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

Best / neatest way to declare RelayCommands

I've been trying to find a nice neat and succinct way to declare RelayCommands in my ViewModels. The best I can come up with is: public class MyViewModel { public ICommand StopCommand { get; private set; } public MyViewModel() { …
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
3
votes
4 answers

How would I simplify this code?

boolean f(boolean A, boolean B, boolean C, boolean D, boolean E) { if (A) { k(); if (B) { m(); if (C) { n(); if (D) { p(); if (E) { q(); …
Shamoon
  • 41,293
  • 91
  • 306
  • 570
3
votes
3 answers

Throw when succeeding vs. do-while-false vs. function array vs. goto statements

Consider a class that is supposed to make parameter suggestion, given some clues, and a specific acceptance test. Example to concretise: Say you are guessing the cubic dimensions of a raw data file, based on the filename. The acceptance test is:…
swalog
  • 4,403
  • 3
  • 32
  • 60
3
votes
3 answers

Maximizing code readability in methods with side effects?

I'm working with a method that causes side effects on a passed reference parameter. One of my primary concerns for the code is readability, and this is a situation that I feel is a potential cause for confusion. Take for example: class Program { …
Chris Trombley
  • 2,232
  • 1
  • 17
  • 24
3
votes
5 answers

In terms of performance, is an array of doubles better or worse than a custom class in java?

I'm writing a simple implementation of the GJK algorithm (collision of convex shapes) in Java, and it involves a lot of simple calculations on 3D vectors. In terms of performance vs readability, would it be better to store the points as double[3]…
Tom
  • 55
  • 1
  • 7
3
votes
3 answers

Is there a concise way to create bit masks in C?

I need to create three bit masks that end up in three 32-bit unsigned ints (let's call them x, y and z). The masks should end up like this: x: 0000 0001 1111 1111 1111 1111 1111 1111 y: 0000 1110 0000 0000 0000 0000 0000 0000 z: 1111 0000 0000 0000…
Lee Netherton
  • 21,347
  • 12
  • 68
  • 102
3
votes
1 answer

Is giving an argument the same name as the kwarg parameter bad practice in Python?

I have written this code in Python 3; dotenv_path = r"./../.env" load_dotenv(dotenv_path=dotenv_path) Notice how I have named the variable containing the path to the .env file the same as the name of the argument load_dotenv() takes. This results…
Malted
  • 108
  • 7
3
votes
2 answers

How do I use an array element as an iterator in julia?

I'm trying to make my Julia code more understandable (to physicists) and thought it would be nice if I could use some sort of vector type iterator. I'm trying to use each element as an iterator. My solution so far is: kcut=2 =…
Finesagan
  • 45
  • 4
3
votes
3 answers

Best Way to Format a Simple When Function in JS

I found this code in Ruby (from here): DX = { E => 1, W => -1, N => 0, S => 0 } and I was thinking about how to best format it in JS, given that it's lacking a "when" function. For reference, N, S, E, and W are "directions", and have aliases like…
Justin
  • 945
  • 12
  • 26
3
votes
3 answers

is there any downside to creating lots of class instances?

I have lots of variables to keep track of in my game, and I'm wondering if there's any downside to creating lots of class instances: event_1 = event(name, chance, [people]) event_2 = event(name, chance, [people]) ... events = [event_1,…
Kia Azad
  • 186
  • 9
3
votes
2 answers

Awaiting multiple levels of Futures?

I have a getter for a singleton instance of a SQFlite Database, like this: static Database _db; static Future get db async { if( _db == null ) _db = await openOrCreateDatabase(); return _db; } Now, I want to perform a…
Magnus
  • 17,157
  • 19
  • 104
  • 189
3
votes
7 answers

How to make the output of server headers more readable?

Given the following php5 code that output a gigantuous amount of difficult to read code: Question: how to make the output more human-readable? e.g. houw to but every "item" on a new line?
Sam
  • 15,254
  • 25
  • 90
  • 145
3
votes
2 answers

How do I refactor my code to reduce the amount of nested loops?

Here is a helper function that converts an array like object into an actual array and then loops through the iterable, supplying each value in the list to the callback function: var each = function(iterable, callback) { iterable =…
Malekai
  • 4,765
  • 5
  • 25
  • 60
3
votes
1 answer

How to include _ in a numeric value in properties file?

How can I have _ (underscore) in my numerical property while injecting it with @Value annotation in Spring? If I include _ in my value, Spring throws TypeMismatchException. .properties file: min-score=20_000 java…
Mahozad
  • 18,032
  • 13
  • 118
  • 133
3
votes
3 answers

function inside the declaration of a loop?

take this example: foreach(explode(' ','word1 word2 word3') as $v) echo $v; From what I know php doens't execute every time the explode function, but it will be executed only the first time. Is this true? And is this true even for user-defined…
anon