Skip to main content
324 votes

Am I too 'clever' to be readable by Jr. devs? Too much functional programming in my JS?

In your code, you have made multiple changes: destructuring assignment to access fields in the pages is a good change. extracting the parseFoo() functions etc. is a possibly good change. introducing ...
amon's user avatar
  • 135k
237 votes
Accepted

Should we eliminate local variables if we can?

Code is read much more often than it is written, so you should take pity on the poor soul who will have to read the code six months from now (it may be you) and strive for the clearest, easiest to ...
Tony BenBrahim's user avatar
227 votes

Am I too 'clever' to be readable by Jr. devs? Too much functional programming in my JS?

If you are in doubt, it probably is too clever! The second example introduces accidental complexity with expressions like foo ? parseFoo(foo) : x => x, and overall the code is more complex which ...
JacquesB's user avatar
  • 59.8k
205 votes
Accepted

Developer insists if statements shouldn't have negated conditions, and should always have an else block

Explicit else block The first rule just pollutes the code and makes it neither more readable, nor less error-prone. The goal of your colleague — I would suppose — is to be explicit, by showing that ...
Arseni Mourzenko's user avatar
185 votes
Accepted

Is readability a valid reason to not use const in (reference) parameters?

Readability is a valid reason to learn to use whitespace: void MyClass::myFunction( const MyObject& obj, const string& s1, const string& s2, const string&...
candied_orange's user avatar
181 votes

How can I defend reducing the strength of code reviews?

How can I justify and defend the thesis that: The merge button should be enabled by default The code review should be a recommendation , but not mandatory The code author should have the right to ...
Philip Kendall's user avatar
164 votes
Accepted

At what point is brevity no longer a virtue?

To answer your question about extant research But has anything been written or researched on recognizing the point where striving for code brevity stops being useful and becomes a barrier to ...
John Wu's user avatar
  • 26.6k
164 votes

Programming cleanly when writing scientific code

This is a pretty common problem for scientists. I've seen it a lot, and it always stems by the fact that programming is something you pick on the side as a tool to do your job. So your scripts are a ...
BgrWorker's user avatar
  • 1,694
156 votes
Accepted

Is a comment aligned with the element being commented a good practice?

No, such aligned comments are not a good practice. It is not clear that the comments relate to specific positions on the line. It just looks like very wildly formatted code. The comment's indents will ...
amon's user avatar
  • 135k
153 votes

Inside a for-loop, should I move the break condition into the condition field if possible?

Those two examples you gave are not functionally equivalent. In the original, the condition test is done after the "some other code" section, whereas in the modified version, it is done first, at the ...
Pete's user avatar
  • 3,221
144 votes

Programming cleanly when writing scientific code

Physicist here. Been there. I would argue that your problem is not about the choice of tools or programming paradigms (unit testing, OOP, whatever). It's about the attitude, the mindset. The fact the ...
Edgar Bonet's user avatar
  • 1,319
133 votes

Has / can anyone challenge Uncle Bob on his love of removing "useless braces"?

You can find several published promotions or rejections of no-brace styles at here or here or wherever bike sheds are painted. Stepping away from the bike sheds, remember the great OS X/iOS SSL bug ...
Paul Draper's user avatar
  • 6,022
133 votes

Why are "if elif else" statements virtually never in table format?

It's more readable. A few reasons why: Nearly every language uses this syntax (not all, most - your example appears to be Python, though) isanae pointed out in a comment that most debuggers are line ...
enderland's user avatar
  • 12.1k
132 votes
Accepted

Would it be a bad idea to periodically run code formatters on a repository?

Sounds nice, but I would prefer to have people responsible for committing code changes, not bots. Besides, you want to make absolutely sure that those changes do not break anything. For example, we ...
Marcel's user avatar
  • 3,122
129 votes
Accepted

Readability versus maintainability, special case of writing nested function calls

If you felt compelled to expand a one liner like a = F(G1(H1(b1), H2(b2)), G2(c1)); I wouldn't blame you. That's not only hard to read, it's hard to debug. Why? It's dense Some debuggers will ...
candied_orange's user avatar
122 votes
Accepted

In what cases is less code not better?

A thin person isn't necessarily healthier than an overweight person. A 980 lines children story is easier to read than a 450 lines physics thesis. There are many attributes that determine the ...
M.A. Hanin's user avatar
120 votes
Accepted

Is "avoid the yo-yo problem" a valid reason to allow the "primitive obsession"?

The assumption is that you don't need to yo-yo to the ZipCode class to understand the Address class. If ZipCode is well-designed it should be obvious what it does just by reading the Address class. ...
JacquesB's user avatar
  • 59.8k
119 votes
Accepted

Functions that simply call another function, bad design choice?

Never forget the Law of Demeter: The Law of Demeter (LoD) or principle of least knowledge is a design guideline for developing software, particularly object-oriented programs. In its general form, ...
Flater's user avatar
  • 52.7k
117 votes
Accepted

Does comparing equality of float numbers mislead junior developers even if no rounding error occurs in my case?

I would always avoid successive floating-point operations unless the model I'm computing requires them. Floating-point arithmetic is unintuitive to most and a major source of errors. And telling the ...
Kilian Foth's user avatar
105 votes

Managing and organizing the massively increased number of classes after switching to SOLID?

Now, to build a simple file saving application you have a class to check if the file already exists, a class to write the metadata, a class to abstract away DateTime.Now so you can inject times for ...
David Arno's user avatar
  • 39.4k
101 votes
Accepted

Should I follow a bad coding style just to follow the established conventions at my workplace?

This is really between you and your team mates. Nobody else can tell you the right answer. However, if I may dare read between the lines, the fact that you call this style "bad" gives some information ...
Cort Ammon's user avatar
  • 11.6k
101 votes
Accepted

Is this use of a symbolic constant overkill?

IMHO your friend is right in using a symbolic name, though I think the name should definitely be more descriptive (like BOARD_WIDTH instead of CHESS_CONST). Even when the number will never change ...
Doc Brown's user avatar
  • 210k
98 votes

Should we eliminate local variables if we can?

Some highly upvoted comments stated this, but none of the answers I saw did, so I will add it as an answer. Your main factor in deciding this issue is: Debuggability Often, developers spend far more ...
DVK's user avatar
  • 3,586
94 votes
Accepted

Is it wrong to use a boolean parameter to determine values?

API design should focus on what is most useable for a client of the API, from the calling side. For example, if this new API requires the caller to write regularly code like this if(flag) foo....
Doc Brown's user avatar
  • 210k
93 votes
Accepted

Why are "if elif else" statements virtually never in table format?

One reason may be that you're not using languages where it's popular. A few counter-examples: Haskell with guards and with patterns: sign x | x > 0 = 1 | x == 0 = 0 ...
viraptor's user avatar
  • 814
89 votes
Accepted

How do you normalize coding style among multiple isolated developers?

Have a coding standard. If the shop you're going to work for already has one in use, that's the one you follow. Avoid coding standards that are dozens of pages long; it's not that complicated. ...
Robert Harvey's user avatar
87 votes

Python file naming convention?

Here is a link for different types of Python name conventions. The style guide for Python is based on Guido’s naming convention recommendations.
Vlad Bezden's user avatar
83 votes

Should I follow a bad coding style just to follow the established conventions at my workplace?

Honestly, do you believe having functions which are difficult to use, with 300 lines, is just a matter of style? So following the bad example could keep the overall program in a better state because ...
Doc Brown's user avatar
  • 210k
83 votes

Programming cleanly when writing scientific code

Version control is probably going to give you the most bang for your buck. It isn't only for long-term storage, it's great for tracking your short-term experimentation and going back to the last ...
Karl Bielefeldt's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible