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
4
votes
1 answer

Omitting the 'else' in PHP ternary and null coalescing operators

I was reading about and experimenting a bit with ternary and null coalescing operators in PHP. So, instead of writing if (isset($array['array_key'])) { $another_array[0]['another_array_key'] = $array['array_key']; } else { // Do some code…
4
votes
4 answers

Namespace information compromises the readability in C++

I'm new to C++ and had a background in C. The one thing which is quite difficult for me to adopt is to frequently use scope operator e.g. std:: Well, i'd avoid it usage by putting using namespace std at the start of my source code but a lot of…
Nouman Tajik
  • 433
  • 1
  • 5
  • 18
4
votes
1 answer

Indenting/breaking jquery chains for readability

I'm curious as to how other people indent/break long jQuery chains, as I can never decide what is more readable (particularly when using .end() to "close" a block of methods e.g. $(this).not(":has(.pointer)").append(pointerHtml) …
wheresrhys
  • 22,558
  • 19
  • 94
  • 162
4
votes
0 answers

Difference between a primitive construct and a primitive data type?

I'm reading a textbook evaluating a programming language implementation and I'm easily confused by terminology that I don't understand, but know how to use when writing a program. This is in regards to orthogonality of an…
Charley Erd
  • 103
  • 1
  • 1
  • 7
4
votes
1 answer

Using struct field as loop counter?

Some background to the issue if I have a struct like typedef struct { idx_type type; union { char *str; int num; } val } cust_idx; and I have loops like this for (i = 0; i < some_get(x); i++) { some_fun(z, NULL,…
Grzegorz
  • 107
  • 8
4
votes
7 answers

Improving Python readability?

I've been really enjoying Python programming lately. I come from a background of a strong love for C-based coding, where everything is perhaps more complicated than it should be (but puts hair on your chest, at least). So switching from C to Python…
verix
  • 1,703
  • 2
  • 15
  • 12
4
votes
0 answers

Writing R-thonic code in R

What were the design decisions that led to R having often more than one way of doing things, that have subtle difference? See, for a good example, https://www.r-bloggers.com/r-na-vs-null/ More more such issues are here, some which are justified,…
l7ll7
  • 1,309
  • 1
  • 10
  • 20
4
votes
4 answers

Time Function Syntax

Why is the time function usually used like this: time_t currentTime; currentTime = time( NULL ); instead of this: time_t currentTime; time( ¤tTime ); Is the first method used more just because it is arguably more readable? Or is there…
user542687
4
votes
6 answers

How to make reduce more readable in Clojure?

A reduce call has its f argument first. Visually speaking, this is often the biggest part of the form. e.g. (reduce (fn [[longest current] x] (let [tail (last current) next-seq (if (or (not tail) (> x tail)) (conj…
Ken
  • 2,918
  • 1
  • 25
  • 31
4
votes
1 answer

VBA to make Excel formulae more readable

I've had a glance around on the site, but advice on making Excel formulae (formulas?) more readable tends to be directed towards 'use named ranges' or 'use helper columns'. I'm not after techniques to make formulae easier to read, I'd like to create…
Greedo
  • 4,967
  • 2
  • 30
  • 78
4
votes
2 answers

Experience on textstat / readability package Python 3

anyone here that has ever used the readability 0.2 or textstat 0.3.1 package in python? Couldn't find anything on SO dealing with this subject or any good documentation on this. So far my code is: It iterates over a bunch of txt files locally…
Florian Schramm
  • 333
  • 3
  • 15
4
votes
11 answers

How to return a flag plus an optional message in Java?

I want to write a method in Java that verifies that some conditions hold on some data, and acknowledges that the data is valid or produces an appropriate error message otherwise. The problem is that we cannot return more than one thing from a…
espinchi
  • 9,144
  • 6
  • 58
  • 65
4
votes
3 answers

Writing unittests for a function that returns a hierarchy of objects

I have a function that performs a hierarchical clustering on a list of input vectors. The return value is the root element of an object hierarchy, where each object represents a cluster. I want to test the following things: Does each cluster…
Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
4
votes
5 answers

Should i prefer readability over safety in my code?

I am dealing with some code that has consistent pattern of creating Map instances like this: Map valuesMap = new HashMap(); valuesMap.put("UserName", "Value1"); valuesMap.put("FirstName",…
VishalDevgire
  • 4,232
  • 10
  • 33
  • 59
4
votes
0 answers

Use semicolon in coffeescript - good or bad practice?

When I want to write a class in Coffeescript that provides method chaining I often come up with the problem of having a one liner in principle but then having to add a line to actually return the instance for the chaining. So instead of writing a…
Loilo
  • 13,466
  • 8
  • 37
  • 47