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
  • 134k
310 votes
Accepted

Python file naming convention?

Quoting https://www.python.org/dev/peps/pep-0008/#package-and-module-names: Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. ...
agold's user avatar
  • 3,216
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
  • 57.8k
204 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.2k
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
155 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
  • 134k
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,191
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
  • 5,992
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,102
127 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
125 votes
Accepted

Is it better to check `c >= '0'` or `c >= 48`?

Both are horrible, but the first is more horrible. Both ignore Java's built-in capability to decide what characters are "numeric" (via methods in Character). But the first one not only ignores the ...
Kilian Foth'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
  • 57.8k
118 votes
Accepted

Why are large amounts of magic numbers acceptable in CSS and SVGs?

Firstly, magic values are avoided in programming by using variables or constants. CSS does not support variables, so even if magic values were frowned on, you don't have much of a choice (except using ...
JacquesB's user avatar
  • 57.8k
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
117 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
  • 47.7k
110 votes
Accepted

What Style is Better (Instance Variable vs. Return Value) in Java

I'm surprised this hasn't mentioned yet... It depends if var1 is actually part of your object's state. You assume that both of these approaches are correct and that it's just a matter of style. You ...
MetaFight's user avatar
  • 11.5k
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.1k
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
  • 10.9k
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
  • 203k
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,576
96 votes
Accepted

When is it appropriate to make a separate function when there will only ever be a single call to said function?

The rationale behind splitting functions is not how many times (or how often) they will be called, it's keeping them small and preventing them from doing several different things. Bob Martin's book ...
Tulains Córdova's user avatar

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