Questions tagged [code-readability]

Code-Readability is how easy it is to understand a piece of code. Whether it be reading someones code, or writing your own.

Code-Readability is how easy it is to understand a piece of code. Whether it be reading someones code, or writing your own. This includes Coding Conventions, positioning of white space, declaration of variables and among other coding practices.

337 questions
3
votes
2 answers

Iterating through a vector of tuples c+17 style don't work?

I am currently looking neat ways in which i can iterate this vector of tuples.. This is what I am currently doing? #include #include #include #include…
Lamda
  • 914
  • 3
  • 13
  • 39
3
votes
2 answers

Splitting out blocks of code in F# pattern matching for readability

// Standard pattern matching. let Foo x = match x with | 1 -> // ... lots of code, only evaluated if x == 1 | 2 -> // ... lots of code, only evaluated if x == 2 // Standard pattern matching separated out, causing exception. let…
3
votes
3 answers

What's the most readable way to write nested functions in javascript?

Example this code I wrote doesn't seem as readable as it could be: function getShortMessages(messages) { return messages.filter((messages) => { return messages.message.length < 50 }).map((object) => { return object.message …
Dany M
  • 113
  • 2
  • 2
  • 9
3
votes
2 answers

Correct extent of the exception handling block

Lets say we have the following code: print("...") might_throw_type_error() print("...") might_throw_index_error() If we want to handle the exceptions that those functions might arise what is the preferred way: Full split of "business" code and…
Mario Corchero
  • 5,257
  • 5
  • 33
  • 59
3
votes
2 answers

Should `using std::cin` and `using std::cout` be avoided or encouraged?

I searched this site and people says you should avoid using using namespace std. I totally agree. However, what about using std::cin and using std::string? Should this be avoided or encouraged? I know always type std::cin is the safest choice, but…
an offer can't refuse
  • 4,245
  • 5
  • 30
  • 50
3
votes
1 answer

Lua Spaghetti Modules

I am currently developing my own programming language. The codebase (in Lua) is composed of several modules, as follows: The first, error.lua, has no dependancies; lexer.lua depends only on error.lua; prototypes.lua also has no…
user6245072
  • 2,051
  • 21
  • 34
3
votes
3 answers

Parsing big XML file with SAX parser, the class is becoming bloated and unreadable - How to fix this?

This is purely a code readability related question, the performance of the class is not an issue. Here is how I am building this XMLHandler : For each element that is relevant to the application, I have a boolean in'ElementName' which I set to true…
SAKIROGLU Koray
  • 208
  • 1
  • 9
3
votes
7 answers

Java best practice - doing large math calculations on a single line?

I'm wondering about whether it is good to declare multiple unneeded variables to make my code more readable. Which of the following snippets is better coding? it calculates the force between two masses. // 1 double dx = xPos - b.xPos; …
pyjamas
  • 4,608
  • 5
  • 38
  • 70
3
votes
1 answer

How can I decouple this C# worker thread code from the main thread for shared data variables?

How could I modify the below code such that I could, for better readability in code: a) move the "workThreadMethod()" into it's own class b) not have any code in this worker thread class reference static variables from the main "Program" class c)…
Greg
  • 34,042
  • 79
  • 253
  • 454
3
votes
3 answers

Readability in nested conditional statements

I'm currently writing a program in Python to model projective geometry, and the congruence function for a projective point is looking rather nasty. (for anyone interested, two projective points are congruent if they both lie on a single line passing…
Patrick
  • 455
  • 4
  • 11
3
votes
2 answers

Is there a character I can use to improve large number legibility in PHP code?

In Perl code, you can put underscores in large numbers to improve legibility. For example, the number 123456789 is equivalent to 123_456_789, which helps the coder understand what number it represents. Is there a character in PHP that I can use for…
Ben
  • 315
  • 1
  • 3
  • 14
3
votes
3 answers

String constant vs variable in a Java method

Unchangeable, constant values should be stored in constants rather than variables for both safer and cleaner code. The latter doesn't apply to all cases of unchangeable values though: There's the following method that is only called once, on…
msp
  • 3,272
  • 7
  • 37
  • 49
3
votes
0 answers

Is there a way to print all function calls made during the lifetime of a script?

Is there a way to print every function call that's made during the lifetime of a script in NodeJS? The current debugging tools seem to be focused on inspecting the state of the program at an exact point in time. What I'm really looking for is a…
hondaman
  • 263
  • 2
  • 5
3
votes
1 answer

Why java has no not function/ alternatives for same

Ok so if you want to check if a list is not empty we would need to do something like if(! mylist.isEmpty()) this affects code readability, so how can we write the same thing in a readable way, calling out negation of condition check. One of…
Ankur
  • 788
  • 6
  • 13
3
votes
1 answer

Add (read and write) a property to the jQuery object

I'd like to add a property to the jQuery object and hence attach it to the DOM without polluting the DOM. In casu, the property i'd like to add is called 'hue'. (But let's not think of this property as a color ) Ofcourse, there's the possibility to…
Ideogram
  • 1,265
  • 12
  • 21