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.

730 questions
54
votes
9 answers

Usage of ‘if’ versus ‘unless’ for Perl conditionals

What are some guidelines for the best use of if versus unless in Perl code? Are there strong reasons to prefer one or the other in some situations?
JSBձոգչ
  • 40,684
  • 18
  • 101
  • 169
49
votes
7 answers

"public static" or "static public"?

A minor point about function declaration keywords in PHP: If you've got a class method that's static, should the static keyword come before or after the visibility keyword (public, protected, private)? Assuming all your methods, static or…
dirtside
  • 8,144
  • 10
  • 42
  • 54
46
votes
4 answers

StringBuilder/StringBuffer vs. "+" Operator

I'm reading "Better, Faster, Lighter Java" (by Bruce Tate and Justin Gehtland) and am familiar with the readability requirements in agile type teams, such as what Robert Martin discusses in his clean coding books. On the team I'm on now, I've been…
avgvstvs
  • 6,196
  • 6
  • 43
  • 74
43
votes
4 answers

New (std::nothrow) vs. New within a try/catch block

I did some research after learning new, unlike malloc() which I am used to, does not return NULL for failed allocations, and found there are two distinct ways of checking whether new had succeeded or not. Those two ways are: try { ptr = new…
Anne Quinn
  • 12,609
  • 8
  • 54
  • 101
43
votes
6 answers

Calling getters on an object vs. storing it as a local variable (memory footprint, performance)

In the following piece of code we make a call listType.getDescription() twice: for (ListType listType: this.listTypeManager.getSelectableListTypes()) { if (listType.getDescription() != null) { children.add(new SelectItem(…
Kawu
  • 13,647
  • 34
  • 123
  • 195
43
votes
3 answers

Why STL implementation is so unreadable? How C++ could have been improved here?

For instance why does most members in STL implementation have _M_ or _ or __ prefix? Why there is so much boilerplate code ? What features C++ is lacking that would allow make vector (for instance) implementation clear and more concise?
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
42
votes
13 answers

How do I write more maintainable regular expressions?

I have started to feel that using regular expressions decreases code maintainability. There is something evil about the terseness and power of regular expressions. Perl compounds this with side effects like default operators. I DO have a habit…
ojblass
  • 21,146
  • 22
  • 83
  • 132
42
votes
7 answers

Should java try blocks be scoped as tightly as possible?

I've been told that there is some overhead in using the Java try-catch mechanism. So, while it is necessary to put methods that throw checked exception within a try block to handle the possible exception, it is good practice performance-wise to…
Iain Samuel McLean Elder
  • 19,791
  • 12
  • 64
  • 80
40
votes
9 answers

What's the cleanest way to write a multiline string in JavaScript?

It doesn't really have to add newlines, just something readable. Anything better than this? str = "line 1" + "line 2" + "line 3";
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
38
votes
4 answers

Eigen: Coding style's effect on performance

From what I've read about Eigen (here), it seems that operator=() acts as a "barrier" of sorts for lazy evaluation -- e.g. it causes Eigen to stop returning expression templates and actually perform the (optimized) computation, storing the result…
jeremytrimble
  • 1,814
  • 1
  • 18
  • 22
33
votes
11 answers

How do I calculate the "median of five" in C#?

The median of five is sometimes used as an exercise in algorithm design and is known to be computable using only 6 comparisons. What is the best way to implement this "median of five using 6 comparisons" in C# ? All of my attempts seem to result in…
Gant
  • 29,661
  • 6
  • 46
  • 65
33
votes
9 answers

Java try/catch performance, is it recommended to keep what is inside the try clause to a minimum?

Considering you have code like this: doSomething() // this method may throw a checked a exception //do some assignements calculations doAnotherThing() //this method may also throw the same type of checked exception //more calls to methods and…
Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
33
votes
6 answers

Generic Exception Handling in Python the "Right Way"

Sometimes I find myself in the situation where I want to execute several sequential commands like such: try: foo(a, b) except Exception, e: baz(e) try: bar(c, d) except Exception, e: baz(e) ... This same pattern occurs when…
Sufian
  • 8,627
  • 4
  • 22
  • 24
32
votes
21 answers

Which code is more readable?

Suppose I have two methods bool Foo() and bool Bar(). Which of the following is more readable? if(Foo()) { SomeProperty = Bar(); } else { SomeProperty = false; } or SomeProperty = Foo() && Bar(); On the one hand, I consider the…
Greg D
  • 43,259
  • 14
  • 84
  • 117
31
votes
1 answer

What color scheme is best for sunlight readability?

With screen types aside (backlit LCD, OLED, matte, glossy, etc...), what color scheme provides the most readability in direct sunlight? I have not been able to find much on this in a day of Googling. The Kindle uses black on grey. I've seen…
miek
  • 743
  • 1
  • 8
  • 15
1
2
3
48 49