Questions tagged [readability]

Readability is a subjective parameter used to measure an aspect of code quality. It is based on the assumption that code should be easily comprehensible by humans, both in its form and in its meaning.

Readability is a subjective parameter used to measure an aspect of code quality. It is based on the assumption that code should be easily comprehensible by humans, both in its form and in its meaning.

To improve code readability, the following is usually considered:

  • The code is written such that a person with poorer programming skills will be able to understand what is written.

  • Adding descriptive comments to explain every step of the way.

  • Using proper indentation and white spaces.

  • Choosing object\variable names that describe their purposes.

  • Referencing the algorithm and the responsible authors.

666 questions
171
votes
21 answers

Is "for(;;)" faster than "while (TRUE)"? If not, why do people use it?

for (;;) { //Something to be done repeatedly } I have seen this sort of thing used a lot, but I think it is rather strange... Wouldn't it be much clearer to say while(true), or something along those lines? I'm guessing that (as is the reason…
Chris Cooper
  • 16,224
  • 8
  • 50
  • 70
154
votes
11 answers

How to split a long regular expression into multiple lines in JavaScript?

I have a very long regular expression, which I wish to split into multiple lines in my JavaScript code to keep each line length 80 characters according to JSLint rules. It's just better for reading, I think. Here's pattern sample: var pattern =…
Nik Sumeiko
  • 6,674
  • 8
  • 41
  • 51
134
votes
12 answers

Boolean method naming readability

Simple question, from a readability standpoint, which method name do you prefer for a boolean method: public boolean isUserExist(...) or: public boolean doesUserExist(...) or: public boolean userExists(...)
Yuval Adam
  • 149,388
  • 85
  • 287
  • 384
128
votes
16 answers

Why should I capitalize my SQL keywords?

Possible Duplicate: Is there a good reason to use upper case for T-SQL keywords? Simple question. I personally find a string of lowercase characters to be more readable than a string of uppercase characters. Is some old/popular flavor of SQL…
Samantha Branham
  • 7,112
  • 2
  • 30
  • 44
126
votes
39 answers

Should one use < or <= in a for loop

If you had to iterate through a loop 7 times, would you use: for (int i = 0; i < 7; i++) or: for (int i = 0; i <= 6; i++) There are two considerations: performance readability For performance I'm assuming Java or C#. Does it matter if "less…
Eugene Katz
  • 5,082
  • 7
  • 36
  • 49
100
votes
11 answers

`if key in dict` vs. `try/except` - which is more readable idiom?

I have a question about idioms and readability, and there seems to be a clash of Python philosophies for this particular case: I want to build dictionary A from dictionary B. If a specific key does not exist in B, then do nothing and continue…
LeeMobile
  • 3,495
  • 6
  • 25
  • 31
91
votes
35 answers

Should a developer aim for readability or performance first?

Oftentimes a developer will be faced with a choice between two possible ways to solve a problem -- one that is idiomatic and readable, and another that is less intuitive, but may perform better. For example, in C-based languages, there are two ways…
JohnMcG
  • 8,283
  • 5
  • 36
  • 49
86
votes
9 answers

How to find good looking font color if background color is known?

There seem to be so many color wheel, color picker, and color matcher web apps out there, where you give one color and the they'll find a couple of other colors that will create a harmonic layout when being used in combination. However most of them…
Mecki
  • 106,869
  • 31
  • 201
  • 225
79
votes
3 answers

Splitting C++ Strings Onto Multiple Lines (Code Syntax, Not Parsing)

Not to be confused with how to split a string parsing wise, e.g.: Split a string in C++? I am a bit confused as to how to split a string onto multiple lines in c++. This sounds like a simple question, but take the following example: #include…
Jason R. Mick
  • 4,797
  • 4
  • 36
  • 61
71
votes
6 answers

Why is the code in most STL implementations so convoluted?

The STL is a critical piece of the C++ world, most implementations derive from the initial efforts by Stepanov and Musser. My question is given the criticality of the code, and it being one of the primary sources for people to view examples of well…
Matthieu N.
65
votes
22 answers

Is while (true) with break bad programming practice?

I often use this code pattern: while(true) { //do something if() { break; } } Another programmer told me that this was bad practice and that I should replace it with the more standard: while(!
Edward Tanguay
  • 176,854
  • 291
  • 683
  • 1,015
63
votes
6 answers

Why are "continue" statements bad in JavaScript?

In the book Javascript: The Good Parts by Douglas Crockford, this is all the author has to say about the continue Statement: The continue statement jumps to the top of the loop. I have never seen a piece of code that was not improved by refactoring…
twiz
  • 6,335
  • 5
  • 35
  • 67
60
votes
4 answers

Using explicitly numbered repetition instead of question mark, star and plus

I've seen regex patterns that use explicitly numbered repetition instead of ?, * and +, i.e.: Explicit Shorthand (something){0,1} (something)? (something){1} (something) (something){0,} (something)* (something){1,} …
polygenelubricants
  • 348,637
  • 121
  • 546
  • 611
57
votes
5 answers

Python: if not val, vs if val is None

I've always coded in the style of if not value, however, a few guides have brought to my attention that while this style works, it seems to have 2 potential problems: It's not completely readable; if value is None is surely more…
John Doe
  • 3,184
  • 1
  • 15
  • 21
56
votes
22 answers

How do I make my code easier for the next developer to understand?

I've been at my very first programming job for about 8 months now and I've learned incredible amounts so far. Unfortunately, I'm the sole developer for a small startup company for internal applications. For the first time ever though, I'll be…
cam
  • 8,095
  • 17
  • 54
  • 81
1
2 3
44 45