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

Is there a more efficient/readable/prettier way to write this Conditional?

I'm learning conditionals in C# and I get how they basically work. A ? B : C Where A = Boolean Condition B = outcome when A == True C = Outcome when A == False My issue is more in writing a complex condition. I am trying to write: (A == B || A ==…
0
votes
1 answer

Using PRG pattern with return button

Hey guys, I haven't used the rpg pattern before, and had a quick question. I want to be able to provide a return link to the page that submitted the post, but I don't want it to show up in the end url (because the return link is long, it looks…
Jess
  • 8,628
  • 6
  • 49
  • 67
0
votes
2 answers

How can I make this query more readable?

I have an SQL query that is doing some calculations. Beyond simple formatting changes, I am wondering if it is possible to somehow utilise CTEs to make this query easier to read? I have found a few opportunities where using CTEs can make a big…
0
votes
1 answer

Is it worth making my code less readable for providing exception safety in case of out of memory errors?

I have a game with non-copyable Items as they are supposed to be unique: class Item { Item() noexcept; Item(Item&&) noexcept; Item(Item const&) = delete; // ... }; class Creature is capable of receiving an Item and adding it to their…
0
votes
1 answer

Can't run PyPi readability package from terminal

I want to use the following PyPI Package on macOS Catalina: https://pypi.org/project/readability/ What the Package does: Analyses .txt files you have in a certain directory and then gives you a .csv file containing readability values for all the…
paschy96
  • 1
  • 2
0
votes
0 answers

What is the minimum distance between two colors to be easily distinguishable?

I need to draw a Sierpinski Triangle for some homework. The task includes a random color picker for the triangle. As the background is white this may lead to problems with visibility. My question is what is the minimum distance between two rgb…
0
votes
0 answers

Is it better to test the same condition repeatedly or test once and duplicate code within them?

Which case is generally better to use in terms of readability, efficiency, etc. One: repeat the same conditions multiple times (no code is repeated) instr1 instr2 if condition: instr3a else: instr3b instr4 if condition: instr5a else: …
Sean
  • 117
  • 2
  • 7
0
votes
5 answers

Which Method Do You Find More Readable To Output Dynamic HTML?

I'm imagining that this will come down to personal preference but which way would you go? StringBuilder markup = new StringBuilder(); foreach (SearchResult image in Search.GetImages(componentId)) { markup.Append(String.Format("
Nick Allen
  • 11,970
  • 11
  • 45
  • 58
0
votes
1 answer

Avoiding redundancy when working with multiple similar functions

That question might sounds completely stupid but since I have 0 experience with such problem, then I believe it might be worth trying to ask. The situation that I am facing is that I have multiple functions, and each of them calls one dataframe,…
Marc Schwambach
  • 438
  • 4
  • 20
0
votes
2 answers

Intermediary variables - what's the performance cost?

const scrollPercent = getScrollPercent(); const mainDivHeight = (mainDivRef.current as any).offsetHeight; const imgHeight = (imgRef.current as any).offsetHeight; const offset = ((imgHeight - mainDivHeight) * scrollPercent) / 100; setBgrImgStyle(x…
John Smith
  • 3,863
  • 3
  • 24
  • 42
0
votes
3 answers

Using multiple if statements instead of else if when each statement return something

I had written a piece of code that looks something like this. public boolean check(String i){ if(i.isEmpty()){ doSomething(); return true; } else if(i.equals("something")){ …
Riza
  • 36
  • 1
  • 5
0
votes
1 answer

SaltStack: "require: previous_state" needed?

I have a sls script which was written by a college. The next state always requires the previous state. Example: apache: service.running: - name: apache2 - enable: True ... apache_modules: apache_module.enabled: ... -…
guettli
  • 25,042
  • 81
  • 346
  • 663
0
votes
3 answers

How to store and list out variables in Selenium code?

I have created my selenium tests however I would like to start cleaning them up for readability and reuse. What do you do with your variables? I have thought about setting up some kind of dictionary of buttons that could be looked up but think that…
J33NO
  • 839
  • 1
  • 8
  • 13
0
votes
1 answer

Choosing the right structure for storing many values of similar type with varying parameters/properties

I'm making a video settings screen for an application and I need a way to store each setting before sending it to a UI manager that will create the HTML elements. I was previously storing them as an array like so: let options = [ new…
Tiago Marinho
  • 2,146
  • 17
  • 37
0
votes
3 answers

How to refactor this unreadable PHP for-loops?

I struggle to understand this lines of code in a legacy project. Also phpcs flagged this as Inline control structures are not allowed. I'd love to refactor this to more understandable code. for ($i = 0, $objectid = ''; isset($query{$i}); $query{$i}…
Bob Ortiz
  • 452
  • 1
  • 3
  • 20