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

two-way list comparison in C# unit test

In my C# unit tests, I often query for a list of rows based on a list of IDs. I then want to ensure that 1) for all the IDs, there was at least one row found that has that ID and 2) for all the returned rows, each row has an ID that is in the list…
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
5
votes
3 answers

Can Python code be compressed like Javascript?

I am wondering if Python code can be compressed/non-human readable like Javascript can. I know indentions are important in Python, and it's core philosophy is readability, but is there, by any chance, a method that allows compressed Python code?…
Jace Cotton
  • 2,004
  • 1
  • 21
  • 38
5
votes
4 answers

How can this 6 line method be refactored to be more readable?

I'm trying to clean up this ridonkulously ugly method here, that's crying out for refactoring, but I'm not sure what kind of structure would do this best (i.e. a case statement, or simply a carefully formatted if then statements) At first glance, it…
Chris Adams
  • 2,721
  • 5
  • 33
  • 45
5
votes
4 answers

Should multiple if statements like "if (condition) if (condition) ..." be avoided in Java?

My IDE (IntelliJ IDEA) is telling me that I have the option to remove the braces on this if statement: if (objectIsOfTypeFoo) { if (objectOfTypeFooIsShared) { // do something with Object of type Foo knowing that it's shared... } else…
Liam
  • 1,041
  • 2
  • 17
  • 31
5
votes
10 answers

Populating a PHP array: check for index first?

If I'm deep in a nest of loops I'm wondering which of these is more efficient: if (!isset($array[$key])) $array[$key] = $val; or $array[$key] = $val; The second form is much more desirable as far as readable code goes. In reality the names are…
Ben Dunlap
  • 1,838
  • 1
  • 16
  • 17
5
votes
19 answers

What makes a language readable or not readable?

I heard people say they can understand their python code a year later but not their XYZ code. Why? I dont know what is good about python syntax or what is bad about another. I like C# but i have a feeling VB.NET code is easier to read. I am doing…
user34537
4
votes
7 answers

What is the most readable regex to extract a second word with no trailing spaces from comma-separated string?

I have an array of strings of the form: @source = ( "something,something2,third" ,"something,something3 ,third" ,"something,something4" ,"something,something 5" # Note the space in the middle of the word ); I need a regex which…
DVK
  • 126,886
  • 32
  • 213
  • 327
4
votes
9 answers

Is there a better way to comment the parameters' direction in code?

I want to improve the readability of the code. So I commented the parameter's direction in the code like this: #define IN #define OUT void Add(IN int Para1, IN int Para2, OUT int& Result); But I think the compiler will replace every instance of IN…
William.Zhou
  • 158
  • 3
  • 7
4
votes
2 answers

increasing expressiveness in array elements test

I like Python for it's expressiveness. I can't express everything as compact as I'd like to, though. For example this one I write quite often: def is_everything_okay(some_array): for s in some_array: if not is_okay(s): return…
erikbstack
  • 12,878
  • 21
  • 81
  • 115
4
votes
2 answers

Using delegates instead of interfaces for decoupling. Good idea?

When writing GUI apps I use a top level class that "controls" or "coordinates" the application. The top level class would be responsible for coordinating things like initialising network connections, handling application wide UI actions, loading…
sipsorcery
  • 30,273
  • 24
  • 104
  • 155
4
votes
1 answer

How to properly set Python class attributes from init arguments

As a Python programmer, I frequently declare classes similar to class Foo: def __init__(self, attr1, attr2, attr3, attr4, attr5, attr6, attr7, attr8, attr9): self.attr1 = attr1 self.attr2 = attr2 ... self.attr9 = attr9 # init…
4
votes
1 answer

Web API for pulling text from article url?

I like the products provided by Read it Later, Instapaper, Readability, etc. where they strip out the core of an article and display it back to you formatted nicely: just text and images from the article. I am looking for a good API to do this. I…
awetawef
  • 41
  • 1
4
votes
4 answers

Is it bad style to reassign long variables as a local abbreviation?

I prefer to use long identifiers to keep my code semantically clear, but in the case of repeated references to the same identifier, I'd like for it to "get out of the way" in the current scope. Take this example in Python: def…
gregsabo
  • 430
  • 2
  • 9
4
votes
2 answers

update one column twice in a data.table efficient in R

I have a data table that looks like this: DT <- data.table(Zeit = c(0.024, 0.4, 0.05), Gier = c(1, 2, 3), GierVZ = c(1, 0, 1), Quer = c(2, 4, 6)) Now I want to update and add some columns to this…
Bolle
  • 322
  • 2
  • 11
4
votes
5 answers

C# Code readability issue

int scalar = creature is SpecialCreature ? (creature.IsAwesome ? 700 : 500) : (creature is NotSoNormalCreature ? (creature.IsAwesome ? (creature is IGreatCreature ? 450 : 280) : 240) : (creature.IsAwesome ?…
bevacqua
  • 47,502
  • 56
  • 171
  • 285