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
6
votes
5 answers

Setting a boolean value based on an integer

I found this statement is some old code and it took me a second to figure out... IsTestActive = (TestStateID == 1 ? true : false); Please correct me if I'm wrong but isn't this the same as this one?: IsTestActive = (TestStateID == 1); If it is,…
chills42
  • 14,201
  • 3
  • 42
  • 77
6
votes
5 answers

How does this sort function work?

As part of my job, I'm occasionally called upon to evaluate candidates for programming positions. A code snippet recently passed across my desk and my first thoughts were that I wasn't sure code like this would even compile any more. But compile it…
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
6
votes
4 answers

Immutability and Readability

So I've been reading Effective Java by Joshua Bloch and noticed two points which I actually have encountered in my work. Point 1: Making setter methods to make code more readable. In his example, we have a class with a ridiculously huge…
Noj
  • 63
  • 2
6
votes
3 answers

Pythonic way to filter data with overlapping dates

I have this data structure where each team has list of issues with start/end dates. For each team, I would like to merge issues with same key and overlapping dates, where in result issue the start date will be smaller date and end date will be…
ThePavolC
  • 1,693
  • 1
  • 16
  • 26
6
votes
5 answers

How to avoid "Math." in front of every math function in C#?

I'm writing some C# heavy in mathematics. Many lines in sequence using plenty of abs(), min(), max(), sqrt(), etc. Using C# is the plain normal way, I must preface each function with "Math." For example double x =…
DarenW
  • 16,549
  • 7
  • 63
  • 102
6
votes
5 answers

Readability of heavy function call nesting?

I've often seen it argued that heavily nested function calls should not be used because they are unreadable. However, using temporary variables instead creates a lot of unnecessary verbosity and forces the reader to mentally link each temporary…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
6
votes
5 answers

How to make long parameter lists readable?

I've developed a natural aversion to long parameter lists in functions. While this is to some extent a good thing, sometimes long parameter lists are the lesser of two evils compared to code duplication or ridiculously long functions due to "manual…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
6
votes
21 answers

What is more readable?

I have these two pieces of code, wich one is more readable? foreach decimal technicalPremium = 0; foreach (Risk risk in risks) { technicalPremium = technicalPremium + risk.TechnicalPremium; } return technicalPremium; linq return…
Mariano
  • 2,928
  • 6
  • 25
  • 28
6
votes
10 answers

Should I make my python code less fool-proof to improve readability?

I try to make my code fool-proof, but I've noticed that it takes a lot of time to type things out and it takes more time to read the code. Instead of: class TextServer(object): def __init__(self, text_values): self.text_values =…
user238424
  • 977
  • 1
  • 7
  • 14
6
votes
3 answers

Making large numbers readable in JavaScript

I'm wondering if there is a way to make large numbers readable in JavaScript. I'm sure there is I just can't find it. For example, if I am writing for (var i=0; i < 1000000; i++){ codecodecode}; is there a way to write that 1000000 so that it's…
Kelly Hall
  • 71
  • 1
  • 3
6
votes
2 answers

Is it possible to embed Cockburn style textual UML Use Case content in the code base to improve code readability?

experimenting with Cockburn use cases in code I was writing some complicated UI code. I decided to employ Cockburn use cases with fish,kite,and sea levels (discussed by Martin Fowler in his book 'UML Distilled'). I wrapped Cockburn use cases in…
fooledbyprimes
  • 999
  • 1
  • 11
  • 29
6
votes
1 answer

Can you apply an operation directly to arguments within map/reduce/filter?

map and filter are often interchangeable with list comprehensions, but reduce is not so easily swapped out as map and filter (and besides, in some cases I still prefer the functional syntax anyway). When you need to operate on the arguments…
kojiro
  • 74,557
  • 19
  • 143
  • 201
5
votes
8 answers

Help on a better way to parses digits from a String in Java

I have a string which contains digits and letters. I wish to split the string into contiguous chunks of digits and contiguous chunks of letters. Consider the String "34A312O5M444123A". I would like to output: ["34", "A", "312", "O", "5", "M",…
Ethan Heilman
  • 16,347
  • 11
  • 61
  • 88
5
votes
3 answers

How to write readable Javascript

In JavaScript, the standard rules for code formatting don't seem to cut it. You still end up with messes of });}); all over the place and I don't believe I even know of established rules for the correct indention of anonymous functions declared as…
Joe
  • 7,922
  • 18
  • 54
  • 83
5
votes
6 answers

Independent function or method

I need to deal with a two objects of a class in a way that will return a third object of the same class, and I am trying to determine whether it is better to do this as an independent function that receives two objects and returns the third or as a…
TimothyAWiseman
  • 14,385
  • 12
  • 40
  • 47