in reply to Re^2: why not listed foreach and if?
in thread why not listed foreach and if?

Because for readability and thus understandability and maintainability the important stuff should come first. A trailing if that determines if anything is performed at all makes the code much harder to understand because when you reach the if you have to revise your entire mental model of the statement to that point.

Somewhat like the infamous instructions for disarming a bomb:

  1. ...
  2. Cut the blue wire
  3. But first cut the red wire
  4. ...

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^4: why not listed foreach and if?
by cavac (Prior) on Jun 19, 2024 at 11:49 UTC

    When it comes to my codebase, the main result of unreadable code is that i would refuse to merge a coworkers change into the main branch and send them back to their desks. With a long todo list on what to fix in their code.

    It's important to understand that i don't shout. Looking sad and slightly shaking my head in disappointment seems to be way more effective when it comes to improving code quality, especially when they come back with still unreadable code. This seldomly fails, my coworkers know the next step up is the dreaded re-run of my one-hour "how to write maintainable code" eye-to-eye lecture while they sit at my desk, watching me refactor their code, commenting on every single mistake and showing how its done correctly.

    It sounds harsh, but it isn't. It's never "you are too stupid to do this right". It's always "You need to learn how to do this to my coding standards. We pay you for it, so take the time and do it. And this is how it's done: ..." (And yes, if a coworker has a good argument on why his way of doing something is the better way, i am not above spending a weekend or two to adapt my whole codebase to the new way of doing things).

      It's important to understand that i don't shout. Looking sad and slightly shaking my head in disappointment seems to be way more effective...

      I'm feeling a bit uneasy about what appears to be your dictatorial approach. For background on where I'm coming from, please take a look at:

      • Psychological Safety (a belief that you will not be punished or humiliated for speaking up with ideas, questions, concerns, or mistakes)
      • Working Solo and in a Team (Google gTeams study - tips on how to create harmonious, high performing teams)
      • Five Whys (the purpose of Five Whys isn't to place blame, but to uncover the root cause of a problem)

      I'm curious how you would rate your teammates in each of the five keys to a successful team, identified in the Google gTeams study:

      • Psychological safety: Can we take risks on this team without feeling insecure or embarrassed?
      • Dependability: Can we count on each other to do high quality work on time?
      • Structure & clarity: Are goals, roles, and execution plans on our team clear? Do we have an effective decision-making process?
      • Meaning of work: Are we working on something that is personally important for each of us?
      • Impact of work: Do we fundamentally believe that the work we're doing matters?

      References Added Later

      Updated: Added Five Whys link and descriptions of the three primary bullet points. Minor changes to wording.

      👁️🍾👍🦟
      You are making working with you sound like a nightmare (browbeating, emotional manipulativeness). Perhaps that's not the case.