←back to thread

1534 points nromiun | 2 comments | | HN request time: 0.662s | source
Show context
defanor ◴[] No.45081057[source]
I think most programmers agree that simpler solutions (generally matching "lower cognitive load") are preferred, but the disagreements start about which ones are simpler: often a lower cognitive load comes with approaches one is more used to, or familiar with; when the mental models one has match those in the code.

For instance, the article itself suggests to use early/premature returns, while they are sometimes compared to "goto", making the control flow less obvious/predictable (as paxcoder mentioned here). Intermediate variables, just as small functions, can easily complicate reading of the code (in the example from the article, one would have to look up what "isSecure" means, while "(condition4 && !condition5)" would have shown it at once, and an "is secure" comment could be used to assist skimming). As for HTTP codes, those are standardized and not dependent on the content, unlike custom JSON codes: most developers working with HTTP would recognize those without additional documentation. And it goes on and on: people view different things as good practices and being simpler, depending (at least in part) on their backgrounds. If one considers simplicity, perhaps it is best to also consider it as subjective, taking into account to whom it is supposed to look simple. I think sometimes we try to view "simple" as something more objective than "easy", but unless it is actually measured with something like Kolmogorov complexity, the objectivity does not seem to be there.

replies(9): >>45081450 #>>45081668 #>>45082133 #>>45082314 #>>45082455 #>>45082707 #>>45082777 #>>45082899 #>>45083671 #
1. PaulStatezny ◴[] No.45083671[source]
> programmers agree that simpler solutions...are preferred, but the disagreements start about which ones are simpler

Low ego wins.

1. Given: The quality of a codebase as a whole is greatly affected by its level of consistency + cohesiveness

2. Therefore: The best codebases are created by groups that either (1) internally have similar taste or (2) are comprised of low ego people willing to bend their will to the established conventions of the codebase.

Obviously, this comes with caveats. (Objectively bad patterns do exist.) But in general:

Low-ego → Following existing conventions → They become familiar → They seem simpler

replies(1): >>45085857 #
2. Sleaker ◴[] No.45085857[source]
I don't think this necessarily is accurate I've come into a lot of projects that no one understands well, but everyone continues to follow the same bad conventions that already exist which just adds to the problems. Ex: deep nesting, no early exit, deep object inheritance.. this happens because a lot of developers don't want to rock the boat, AND because they don't have the skills to unwind the complexity in a manageable amount of time without also causing serious problems.