Questions tagged [readability]

Readability measures how easy code is to read and understand.

Readability measures how easy code is to read and understand.

Questions in this tag should be about code organization, style, and structure from the point of view of enhancing readability by others.

Readability is not the same as legibility, which refers to the clarity and recognition of individual characters rather than whole words, sentences, and other linguistic and coding constructs.

197 questions
355
votes
19 answers

How would you know if you've written readable and easily maintainable code?

How would one know if the code one has created is easily readable, understandable, and maintainable? Of course from the author's point of view, the code is readable and maintainable, because the author wrote it and edited it, to begin with. However,…
KyelJmD
  • 971
  • 5
  • 10
  • 20
259
votes
21 answers

Are `break` and `continue` bad programming practices?

My boss keeps mentioning nonchalantly that bad programmers use break and continue in loops. I use them all the time because they make sense; let me show you the inspiration: function verify(object) { if (object->value < 0) return false; if…
179
votes
13 answers

Is it OK to split long functions and methods into smaller ones even though they won't be called by anything else?

Lately I've been trying to split long methods into several short ones. For example: I have a process_url() function which splits URLs into components and then assigns them to some objects via their methods. Instead of implementing all this in one…
Stas Bichenko
  • 3,689
  • 4
  • 24
  • 32
167
votes
10 answers

Is there a specific reason for the poor readability of regular expression syntax design?

Programmers all seem to agree that readability of code is far more important than short-syntaxed one-liners which work, but require a senior developer to interpret with any degree of accuracy - but that seems to be exactly the way regular…
J.Todd
  • 3,833
  • 5
  • 22
  • 27
146
votes
6 answers

Are private methods with a single reference bad style?

Generally I use private methods to encapsulate functionality that is reused in multiple places in the class. But sometimes I have a large public method that could be broken up into smaller steps, each in its own private method. This would make the…
Jordak
  • 921
  • 2
  • 7
  • 10
104
votes
3 answers

When and for what purposes should the const keyword be used in C for variables?

While getting my code reviewed here the issue of using the const keyword came up. I understand that it is used for implementing read-only behaviour on variables. I am confused about what are the various situations when it can be useful. Should it…
Aseem Bansal
  • 2,954
  • 6
  • 20
  • 33
72
votes
10 answers

Clean readable code vs fast hard to read code. When to cross the line?

When I write code I always try to make my code as clean and readable as possible. Every now and then there comes a time when you need to cross the line and go from nice clean code to slightly uglier code to make it faster. When is it OK to cross…
66
votes
4 answers

What's the dominant naming convention for variables in PHP: camelcase or underscores?

The consensus seems to be that one should follow the convention of the platform they're developing for. See: Underscore or camelcase? Naming conventions: camelCase versus underscore_case? However, PHP doesn't seem to strictly follow any convention…
Stas Bichenko
  • 3,689
  • 4
  • 24
  • 32
66
votes
18 answers

Are long methods always bad?

So looking around earlier I noticed some comments about long methods being bad practice. I am not sure I always agree that long methods are bad (and would like opinions from others). For example I have some Django views that do a bit of processing…
wobbily_col
  • 1,861
  • 3
  • 16
  • 25
63
votes
10 answers

Readability versus maintainability, special case of writing nested function calls

My coding style for nested function calls is the following: var result_h1 = H1(b1); var result_h2 = H2(b2); var result_g1 = G1(result_h1, result_h2); var result_g2 = G2(c1); var a = F(result_g1, result_g2); I have recently changed to a department…
Dominique
  • 1,705
  • 2
  • 14
  • 24
63
votes
11 answers

Is a big boolean expression more readable than the same expression broken down into predicate methods?

What is easier to understand, a big boolean statement (quite complex), or the same statement broken down into predicate methods (lots of extra code to read)? Option 1, the big boolean expression: private static bool…
willem
  • 1,053
  • 9
  • 10
53
votes
15 answers

Is it bad practice to name an unused variable with a single underscore?

Often when the syntax of the language requires me to name a variable that is never used, I'll name it _. In my mind, this reduces clutter and lets me focus on the meaningful variables in the code. I find it to be unobtrusive so that it produces an…
Kris Harper
  • 2,237
  • 2
  • 19
  • 21
50
votes
6 answers

Clarification of "avoid if-else" advice

The experts in clean code advise not to use if/else since it's creating an unreadable code. They suggest rather using IF and not to wait till the end of a method without real need. Now, this if/else advice confuses me. Do they say that I should not…
deviDave
  • 2,933
  • 5
  • 26
  • 30
49
votes
12 answers

Intentional misspellings to avoid reserved words

I often see code that include intentional misspellings of common words that for better or worse have become reserved words: klass or clazz for class: Class clazz = ThisClass.class kount for count in SQL: count(*) AS kount Personally I find this…
Nicole
  • 28,111
  • 12
  • 95
  • 143
46
votes
6 answers

Refactoring into lots of methods - is this considered clean or not?

So, I watched as my colleague complained a bit about a project he has inherited from someone who is, shall we say, not very experienced as a programmer (intern left to his own devices on a project). At one point there was duplicate code, about 7-8…
Max
  • 2,039
  • 1
  • 16
  • 22
1
2 3
13 14