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

Looping over array values in Lua

I have a variable as follows local armies = { [1] = "ARMY_1", [2] = "ARMY_3", [3] = "ARMY_6", [4] = "ARMY_7", } Now I want to do an action for each value. What is the best way to loop over the values? The typical thing I'm finding…
Jeroen De Dauw
  • 10,321
  • 15
  • 56
  • 79
28
votes
19 answers

Design of an Alternative (Fluent?) Interface for Regular Expressions

I've just seen a huge regex for Java that made me think a little about maintainability of regular expressions in general. I believe that most people - except some badass perl mongers - would agree that regular expressions are hardly maintainable. I…
sfussenegger
  • 35,575
  • 15
  • 95
  • 119
26
votes
7 answers

Is it possible in C++ to do std::map<> "for element : container" iteration with named variables (eg, key and value) instead of .first and .second?

I wasn't sure what to search for. I found Renaming first and second of a map iterator but it's not quite what I want to do. Here's what I'd like to do [see below for nonsense C++ code]. Is something close to this possible? Otherwise will just have…
JamEnergy
  • 720
  • 8
  • 21
26
votes
3 answers

Is there an IDE/utility to refactor Python * imports to use standard module.member syntax?

I was recently tasked with maintaining a bunch of code that uses from module import * fairly heavily. This codebase has gotten big enough that import conflicts/naming ambiguity/"where the heck did this function come from, there are like eight…
Zac B
  • 3,796
  • 3
  • 35
  • 52
25
votes
10 answers

Improving Code Readability

When it comes to code documentation, it is usually accepted that code should explain itself, and inline code documentation (excluding public API documentation) should only explain meta-code issues such as workarounds, explanations on why specific…
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
25
votes
6 answers

How to specify large integer literals in a readable way?

I want to specify a sequence of large integers (with many zeros) like: a = [1e13, 1e14, 1e19, ...] My intuition is to use scientific notation. But in python, it's a float instead of integer. Is there a easy way in python to write these integer…
Gary
  • 1,828
  • 1
  • 20
  • 27
24
votes
13 answers

Optimal tab size for code readability

Personal preferences aside, is there an optimal tab size (2 spaces? 3 spaces? 8 spaces?) for code readability? In the different projects I've worked on, people seem to have vastly different standards. I can't seem to read 2 space indents, but…
sotangochips
  • 2,700
  • 6
  • 28
  • 38
23
votes
14 answers

Is there a concise opposite of "empty"?

Interfaces to string classes typically have of method named IsEmpty (VCL) or empty (STL). That's absolutely reasonable because it's a special case, but the code that uses these methods often has to negate this predicate, which leads to a "optical…
Wolf
  • 9,679
  • 7
  • 62
  • 108
22
votes
5 answers

How to avoid nested chains of "if let"?

I'm wading through a codebase full of code like this: if let Some(i) = func1() { if let Some(j) = func2(i) { if let Some(k) = func3(j) { if let Some(result) = func4(k) { // Do something with result …
GMA
  • 5,816
  • 6
  • 51
  • 80
22
votes
1 answer

How to cleanly keep below 80-char width with long strings?

I'm attempting to keep my code to 80 chars or less nowadays as I think it looks more aesthetically pleasing, for the most part. Sometimes, though, the code ends up looking worse if I have to put line breaks in weird places. One thing I haven't…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
22
votes
2 answers

Implicit return values in Ruby

I am somewhat new to Ruby and although I find it to be a very intuitive language I am having some difficulty understanding how implicit return values behave. I am working on a small program to grep Tomcat logs and generate pipe-delimited CSV files…
csamuel
  • 820
  • 2
  • 8
  • 11
21
votes
5 answers

How to make SQL query more readable in PHP?

When you have a long fields in SQL query, how do you make it more readable? For example: public function findSomethingByFieldNameId($Id) { $sql = "SELECT field1, field2, field3 as Field3_Something, field4, field5, field6, field7, field8,…
I'll-Be-Back
  • 10,530
  • 37
  • 110
  • 213
21
votes
11 answers

What is the best color combination for readability, easy of use, and reduced eye strain?

I am trying to pick out the optimal set of colors for a new website project. I want to do a traditional black on white look and feel for the main content. However my partner on the project wants to do a color combination that more looks like the…
Nick Berardi
  • 54,393
  • 15
  • 113
  • 135
21
votes
6 answers

Tuples readability : [0,0] vs (0,0)

I'm using Python since some times and I am discovering the "pythonic" way to code. I am using a lot of tuples in my code, most of them are polar or Cartesian positions. I found myself writing this : window.set_pos([18,8]) instead of this…
Zoé Martin
  • 1,887
  • 1
  • 16
  • 28
20
votes
6 answers

Reference equality performance difference? ((object)obj1 == (object)obj2) vs. object.ReferenceEquals( obj1, obj2 )

Is there extra overhead in using the object.ReferenceEquals method verses using ((object)obj1 == (object)obj2)? In the first case, there would be a static method call involved, and in both cases some form of casting to an object would be…
Triynko
  • 18,766
  • 21
  • 107
  • 173
1 2
3
48 49