Skip to main content
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
52 votes

Readability versus maintainability, special case of writing nested function calls

On the other hand, the more processing you put on a line, the more logic you get on one page, which enhances readability. I utterly disagree with this. Just looking at your two code examples calls ...
David Arno's user avatar
  • 39.4k
41 votes
Accepted

Why don't programming languages or IDEs support attaching descriptive metadata to variables?

Why doesn't it exist? The direct answer here is that this isn't technically impossible, no one has just been sufficiently bothered enough by it to create a field-spanning standard that everyone can ...
Flater's user avatar
  • 55k
39 votes

Why don't programming languages or IDEs support attaching descriptive metadata to variables?

TLDR Decomposition makes names shorter. Do not fight symptoms, solve underlying problem instead. Scope is important Naming is the hardest problem, not because long names are not readable, but because ...
Basilevs's user avatar
  • 2,895
36 votes

Are private methods with a single reference bad style?

It's probably a great idea! I do take issue with splitting up long linear sequences of action into separate functions purely to reduce the average function length in your codebase: function step1()...
openai_sucks's user avatar
  • 1,287
35 votes

Is it an (anti-)pattern for a function to have an argument to decide which other function to call?

Does this pattern have a name, That depends on who you ask. Some folk treat patterns as only applicable to OOP and see them as more like implementation patterns in that, for example the UML used in ...
David Arno's user avatar
  • 39.4k
30 votes

Is it bad practice create "alias" variables to not use globals or arguments with long names in a method?

In general, creating local variables for readability is a good thing. A local variable gives a locally relevant name to something; that same thing might have a different name in a different context. ...
IMSoP's user avatar
  • 5,877
28 votes

Why don't programming languages or IDEs support attaching descriptive metadata to variables?

Java and C# at least have this sort of feature. Javadoc is the system for it in the Java context, Documentation comments in C# context. Indeed, that’s how IDEs provide on-hover info at all. Generally ...
Telastyn's user avatar
  • 110k
25 votes
Accepted

Use `ref` merely for clarification?

No. For anyone who has understood what the ref keyword means, this obfuscates what the method really does. The better alternative is to pick a more descriptive name for such a method like ...
Doc Brown's user avatar
  • 212k
25 votes

Readability versus maintainability, special case of writing nested function calls

Your first example, the single-assignment-form, is unreadable because the chosen names are utterly meaningless. That might be an artifact of trying not to disclose internal information on your part, ...
Deduplicator's user avatar
  • 9,111
22 votes

Readability versus maintainability, special case of writing nested function calls

As always, when it comes to readability, failure is in the extremes. You can take any good programming advice, turn it into a religious rule, and use it to produce utterly unreadable code. (If you don'...
cmaster - reinstate monica's user avatar
20 votes
Accepted

How should I write a test for a pure method which doesn't return anything?

Most test frameworks have an explicit assertion for "Doesn't throw", e.g. Jasmine has expect(() => {}).not.toThrow(); and nUnit and friends also have one.
DeadMG's user avatar
  • 36.9k
19 votes

Is there a programming paradigm that promotes making dependencies extremely obvious to other programmers?

Discoverability Its absence plagues many organizations. Where is that tool that Fred built again? In the Git repository, sure. Where? The software pattern that comes to mind is Model-View-ViewModel....
Robert Harvey's user avatar
19 votes

Are private methods with a single reference bad style?

The answer is it highly depends on the situation. @Snowman covers the positives of breaking up large public function, but its important to remember there can be negative effects too, as you are ...
dlasalle's user avatar
  • 842
19 votes
Accepted

DRY principle often makes my code more complicated and/or more difficult to understand

DRY absolutely does not mean "use minimum number of lines possible", or "do not write code that looks like other code" DRY refers to having code that does the same thing in two different places. But ...
jmoreno's user avatar
  • 11.1k
17 votes

Is it possible to make long code representing a computation easier to read?

You wrote Is such hard-to-read code considered bad code so you definitely agree it is hard-to-read code, and if it is hard to read, it is hard to maintain and evolve - so I guess you consider the ...
Doc Brown's user avatar
  • 212k
15 votes

Is it an (anti-)pattern for a function to have an argument to decide which other function to call?

Multiple Dispatch I believe the pattern you describe is called multiple dispatch. This is a form of polymorphism. You can compare it to subtype polymorphism of the kind offered by OOP languages that ...
edalorzo's user avatar
  • 2,656
15 votes

Is it an (anti-)pattern for a function to have an argument to decide which other function to call?

One potential issue with this pattern is that the knowledge of which implementation should be used appears to be encoded in more than one place. That is, there appears to be a 1:1 mapping between an ...
ErikE's user avatar
  • 1,181
14 votes

Readability versus maintainability, special case of writing nested function calls

@Dominique, I think in your question's analysis, you're making the mistake that "readability" and "maintainability" are two separate things. Is it possible to have code that is maintainable but ...
Steve's user avatar
  • 10.4k
13 votes
Accepted

How to write Readable Comment when we have to deal with IDs?

You should not use integer id's directly in logic. You should define constants (or enums or whatever is appropriate for your language) corresponding to the id's and then use the names. E.g. ...
JacquesB's user avatar
  • 60.1k
12 votes

Why don't programming languages or IDEs support attaching descriptive metadata to variables?

It's a good question, and some IDEs do have the functionality you suggest, but virtually all programming languages and IDEs have the simple ability to add comments like so: // The lowest integer ...
Steve's user avatar
  • 10.4k
11 votes
Accepted

Why are functional-style chained map operations considered hard to read?

Everyone talks about code readability as a positive, but nobody actually agrees about what it means. The problem is readability depends on the person reading. Your code use a particular approach, ...
JacquesB's user avatar
  • 60.1k
11 votes

Is it a bad practice to use conditionals with functions that change program's state?

To me, the main code smell is that a createFile() method returns a boolean indicating success. That reminds me of programming styles from the 1970s. A method named createFile() implies a contract ...
Ralf Kleberhoff's user avatar
11 votes

Is it bad practice create "alias" variables to not use globals or arguments with long names in a method?

Creating aliases for the sole purpose of having a shorter variable name could be seen as a code smell. In general, variable names should not be long enough to require aliases. They should be concise ...
ianmandarini's user avatar
  • 2,818
10 votes

Is there a programming paradigm that promotes making dependencies extremely obvious to other programmers?

The best way to approach these sorts of problems is incrementally. Don't get frustrated and propose wide, sweeping architectural changes. Those will never get approved, and the code will never ...
Karl Bielefeldt's user avatar
10 votes
Accepted

Is it wrong to use flags for "grouping" enums?

This is definitely abusing enums and flags! It might work for you, but anybody else reading the code is going to be mightily confused. If I understand correctly, you have a hierarchical ...
JacquesB's user avatar
  • 60.1k
10 votes

What is the best way to make an if statement condition itself conditional?

add more functions: buttonPress() { if(input) { process(a, b) } else { process(b, a) } } process(a, b) { for(i=0 ... }
Ewan's user avatar
  • 78.6k
9 votes

Why do some APIs simply throw Exception?

There is no good reason to do this. And in fact declaring a method as throws Exception makes it difficult to use. This is covered by this "example" in the Java Language documentation tree over on ...
Stephen C's user avatar
  • 25.2k
9 votes

inheritance and polymorphism decrease readability

Neither inheritance nor polymorphism decreases readability. Using any OOP concept for the wrong reasons does. Avoiding repeated code is not a good reason to use inheritance, you can do that by ...
Martin Maat's user avatar
  • 18.5k

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