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
7 answers

Is it worth the effort to have a function that returns the inverse of another function?

I have recently added a HasValue function to our internal javascript library: function HasValue(item) { return (item !== undefined && item !== null); } A during a convorsation with a coworker, we came up with the idea of also adding another …
chills42
  • 14,201
  • 3
  • 42
  • 77
5
votes
2 answers

Line Continuation Mid String In Powershell

I'm trying to write an FFmpeg command on system that has two identical capture cards, so I have to use their "alternate names" or FFmpeg doesn't understand which one I'm calling. The only problem is the alternate names are extremely long,…
ninbura
  • 450
  • 6
  • 14
5
votes
3 answers

Tips on writing concise and elegant Java

Please share your tricks for making your Java code concise, still readable. Coming from Python I'm suffering from "oh, this looks so verbose", it's sometimes hard to fit even in 100-character long lines. I understand Java is a bit more verbose and…
Pēteris Caune
  • 43,578
  • 6
  • 59
  • 81
5
votes
3 answers

Is it possible to combine a GroupBy and Select to get a proper named Key?

I really love the GroupBy LINQ method in C#. One thing that I don't like though is that the Key is always called Key. When I loop through the groups, Key doesn't say me anything. So I have to look at the rest of the context to understand what Key…
Dirk Boer
  • 8,522
  • 13
  • 63
  • 111
5
votes
6 answers

Can a Visual Basic (.NET / 2010) file be split up for readability?

I'm writing a program in Visual Basic 2010. It's a HMI (Human-Machine Interface) and therefore has a whole whack of buttons that just send commands to other devices. As a result, there are a huge pile of event handlers for clicking buttons that…
evilspoons
  • 405
  • 2
  • 6
  • 16
5
votes
13 answers

How do you write code that is easily read by other people who have had no hand in writing any part of it?

How do you write code that is easily read by other people and who have had no hand in writing any part of it?
Codeslayer
  • 3,383
  • 7
  • 35
  • 42
5
votes
4 answers

Is a single loop with several statements and conditions better than several simple loops?

I was creating a very simple program that determines how many coins you need to return the change to a client, using a greedy algorithm. The algorithm is really obvious, you just need to determine which is the bigger coin you can use, subtract its…
mauroSabella
  • 71
  • 1
  • 5
5
votes
4 answers

JavaScript - Are loops faster than discretely writing line-by-line?

Ignoring all code cleanliness and readability, which script will finish quicker? This: for(var i = 0; i < 10; i++){ --do that thing-- } Or this: --do that thing-- --do that thing-- --do that thing-- --do that thing-- --do that thing-- --do that…
user3163495
  • 2,425
  • 2
  • 26
  • 43
5
votes
2 answers

How to avoid multiple streaming when using collect

I have a combination of querying a database with jooq and post processing the result with the streams. However I feel that my code is not very readable and not concise enough. How can I improve my code in ways of better expressing my intent. sql …
Angelo.Hannes
  • 1,729
  • 1
  • 18
  • 46
5
votes
2 answers

Suppress F# Compiler Warning: Possible incorrect indentation: this token is offside of context

I have some xunit tests I would like to layout as follows for readability: [] let ``Has Hash Code 2``() = target.GetHashCode().ShouldBe 2 [] let ``ToString yields two``() = target.ToString().ShouldBe "two" [] let…
Craig
  • 55
  • 7
5
votes
4 answers

How to avoid nested functions when using AJAX?

Sequential Asynchronous calls are gross. Is there a more readable solution? The problem is this is hard to follow: ajaxOne(function() { // do something ajaxTwo(function() { // do something ajaxThree() }); }); where the anonymous…
Fletcher Moore
  • 13,558
  • 11
  • 40
  • 58
5
votes
3 answers

How do you make long SQL invoked from other code readable?

This is a very open question, but I think it can be very beneficial for SQL readability. So you have a Java program, and you are trying to call a monster SQL statement from it, with many subqueries and joins. The starting point for my question is a…
Artem
  • 6,420
  • 6
  • 26
  • 26
5
votes
8 answers

Formatting an if statement for readability

What's the best way to format this for readability? if (strpos($file, '.jpg',1) && file_exists("$thumbsdir/$file") == false || strpos($file, '.gif',1) && file_exists("$thumbsdir/$file") == false || strpos($file, '.png',1) &&…
PHLAK
  • 22,023
  • 18
  • 49
  • 52
5
votes
6 answers

Obfuscated C# Code - What is the balance between concision and clarity?

Years ago there used to be a contest to see who could produce the most obfuscated C code, and some of the results were dramatically unreadable. C was like that. You could really screw things up with the preprocessor in particular. However, many of…
Fred Thomas
  • 51
  • 1
  • 2
5
votes
3 answers

What is the industry and community best practice for coding proper maintainable readable jQuery for a large codebase?

Coming from a Ruby background, I'm used to writing all my code using classes with methods and such. I do know javascript quite well, but I'm new to jQuery and its best practices. Obviously there are a million ways to simulate classes in javascript.…
Thomas Aylott
  • 899
  • 1
  • 6
  • 11