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
-1
votes
1 answer

How to name variables and structure code in dynamically typed languages for better readability?

Debugging old code in dynamically typed languages like Python, Ruby, JavaScript, etc. is often a struggle. For example, below Ruby function extracts only the key:val pairs from the result (hash) if a key is present in filters (array). def…
Dante
  • 537
  • 2
  • 4
  • 18
-1
votes
2 answers

Is it best practice to separate data calculations from data formatting in Kotlin app?

I have a codebase where all my data calculations and data formatting occur within a single function. I have heard that it is best practice to have one task per function but I wonder if calculations, formatting, and display can fit into one function…
Dylon Jaynes
  • 166
  • 11
-1
votes
4 answers

Enum or define in returned C function

Which is better for code readability and further documentation of the code? Define return values and return function like this? #define RETURN_OK 0 #define RETURN_NOT_OK -1 int do_it(void) { /*...*/ return RETURN_OK; } or create…
user3742046
  • 171
  • 12
-1
votes
1 answer

moving back and forth between inherited class and derived class with predicate

I have several objects that inherit from a TreeTagModel. The inheriting objects are meant to be placed in a tree structure and retrieved with limited need to understand what "it" is until the object is consumed. By this I mean, it can get passed…
Siberian
  • 27
  • 5
-1
votes
1 answer

error - [-Werror,-Wunused-value] - don't know what it means

#include #include #include #include int letters = 0; int words = 0; int sentences = 0; int main(void) { string text = get_string("Text: "); printf("\n"); for(int j = 0; j < strlen(text);…
-1
votes
1 answer

How can I improve my code readability? Spaghetti Code (I'm a beginner)

I was need of help and besides helping me, people told me my code was, although working, a complete mess and under the "Spaghetti Code" category. Can someone please assist me on how to refactor my code for efficiency and readability purposes? Any…
-1
votes
1 answer

R: Applying quanteda's textstat_readability function producing "Error in set"

I am encountering an issue with applying the textstat_readability function to a DF column. Following several lines of cleaning tweet text (~ 53K observations), I apply the text_readability function to create a new column called $Flesch from the…
-1
votes
1 answer

Extremely long statements in Python?

I'm taking an online Python course. One of the exercises contains: [print(x, 'has type', type(eval(x))) for x in ['np_vals', 'np_vals_log10', 'df', 'df_log10']] To me, this long statement is less readable than a standard loop, e.g., for x in…
user36800
  • 2,019
  • 2
  • 19
  • 34
-1
votes
1 answer

Refactoring If Statements For Better Readability

I'm currently working on a project that will diminish a class that being used by other several classes. if(condition_A) { doSomething(); } else if(condition_B) { classToBeRemoved(); } else { doAnother(); } The first solution that…
Rnine
  • 13
  • 3
-1
votes
1 answer

Which code is more readable?

This isn't a difficult question. I simply want to know which of these two C++ code snippets you think is better (readability vs. length vs. boiler-platery): Option #1 Entity* square = Entity::Builder().positionX(0.0).positionY(0.0). …
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
-1
votes
3 answers

Is there a using/Dispose syntax that will be more eager to dispose but just as safe as chaining?

If I'm doing the following: using (var foo = bar.GetFoo()) using (var blat = new Blat(foo)) using (var bonk = Bonk.FromBlat(blat)) using (var bork = Bob.FromBip(bonk)) { var target = bork.ToArray(); // I GOT THE TARGET } It's very safe and…
KRA2008
  • 121
  • 1
  • 11
-1
votes
2 answers

C# - Prettier way to compare one value against multiple values in a single line of code

I have this piece of code: if (filter != RECENT && filter != TODAY && filter != WEEK && filter != MONTH && filter != ALLTIME) { filter = RECENT; } Note that filter is a string and it's compared against const string types. Is…
bezbos.
  • 1,551
  • 2
  • 18
  • 33
-1
votes
2 answers

Python3: How do I make this equation readable?

So for this internship I am doing, I need to use the integral of (x^(9/2))/((1-x)^2) as part of an equation I am graphing. However, the variable that I am graphing along the x axis appears in both limits of integration. Since I am a complete and…
-1
votes
1 answer

How to make an INSERT sql statement into more readable form?

Often times, I ran into constraint violation while using insert statements. For ex. INSERT INTO table_1 (col1, col2, ..., col100) VALUES (val1, val2, ..., val100); Now, is there a fast way of navigating to the 34th column's value by making this…
Chaipau
  • 199
  • 1
  • 5
  • 14
-1
votes
2 answers

In Java, ask if a variable STILL equals null after a possible change in value

In Java, this works: String foo = a(); if(foo == null){ foo = b(); } if(foo != null){ list1.add(foo); } However, its ugly to look at because it looks like it should be handled as an if/else, even though it cannot be. Is there a neat way to…