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
25
votes
9 answers

Gracefully avoiding NullPointerException in Java

Consider this line: if (object.getAttribute("someAttr").equals("true")) { // .... Obviously this line is a potential bug, the attribute might be null and we will get a NullPointerException. So we need to refactor it to one of two choices: First…
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
23
votes
7 answers

How can I implement NotOfType in LINQ that has a nice calling syntax?

I'm trying to come up with an implementation for NotOfType, which has a readable call syntax. NotOfType should be the complement to OfType and would consequently yield all elements that are not of type T My goal was to implement a method which…
Christoffer Lette
  • 14,346
  • 7
  • 50
  • 58
22
votes
1 answer

How to cleanly keep below 80-char width with long strings?

I'm attempting to keep my code to 80 chars or less nowadays as I think it looks more aesthetically pleasing, for the most part. Sometimes, though, the code ends up looking worse if I have to put line breaks in weird places. One thing I haven't…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
21
votes
5 answers

How to make SQL query more readable in PHP?

When you have a long fields in SQL query, how do you make it more readable? For example: public function findSomethingByFieldNameId($Id) { $sql = "SELECT field1, field2, field3 as Field3_Something, field4, field5, field6, field7, field8,…
I'll-Be-Back
  • 10,530
  • 37
  • 110
  • 213
18
votes
4 answers

Preserve code readability while optimising

I am writing a scientific program in Python and C with some complex physical simulation algorithms. After implementing algorithm, I found that there are a lot of possible optimizations to improve performance. Common ones are precalculating values,…
18
votes
4 answers

About the order of input parameters

For a function/method contains many input parameters, does it make a difference if passing-in in different orders? If does, in what aspects (readability, efficiency, ...)? I am more curious about how should I do for my own functions/methods? It…
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
17
votes
6 answers

Readability vs Performance

Recently we had a discussion at work about the impact of local variables on the performance vs readability of Java code. Some of my colleagues are of the oppinion that declarations like this new DoSomethingCmd(new SelectionContext(context, keys),…
dribnif
  • 175
  • 1
  • 7
17
votes
4 answers

Unit testing - log and then fail?

I am used to test drive my code. Now that I am new to Go I am trying to get it right as fast as possible. I am using the testing package in the standard library which seem to be good enough. (I also like that it is not yet another external…
froderik
  • 4,642
  • 3
  • 33
  • 43
16
votes
2 answers

Experimental research findings on white space (for language design and style guides)?

What does experimental research say about white space in code? Let me be specific: I'm talking about cognitive studies that compare how quickly and effectively people can read and grasp visual information that comes across in different…
David J.
  • 31,569
  • 22
  • 122
  • 174
16
votes
10 answers

Using { } to segment large blocks of code to improve code-readability - Good practice?

I'm considering the option of using anonymous { } code blocks to logically distinguish "code blocks" inside the same method call, something that (theoretically) should improve readability of the code. I'm wondering which of the following 2 code…
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
13
votes
7 answers

Too many if statements

I have some topic to discuss. I have a fragment of code with 24 ifs/elifs. Operation is my own class that represents functionality similar to Enum. Here is a fragment of code: if operation == Operation.START: strategy =…
13
votes
9 answers

Is there any tool to standardize format of C++ code?

I'm looking for a tool that works on Windows to reformat some C++ code in my codebase. Essentially, I've got some code I wrote a while ago that I'd like to use, but it doesn't match the style I'm using in a more recent project. What's the best way…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
12
votes
3 answers

How to write long arithmetic expressions in several lines in python?

I have a long expression, its' not fitting in my screen, I want to write in several lines. new_matrix[row][element] = old_matrix[top_i][top_j]+old_matrix[index_i][element]+old_matrix[row][index_j]+old_matrix[row][index_j] Python gives me 'indent'…
ERJAN
  • 23,696
  • 23
  • 72
  • 146
11
votes
6 answers

How to Format Code in Research Reports

I am currently writing a formal research report, and I'll be including code with this report. Question: Is there an accepted way of displaying code in research reports? I'm thinking both in terms of font, spacing, et cetera, and whether the code…
GlenCrawford
  • 3,359
  • 3
  • 26
  • 34
11
votes
3 answers

C++11 range-based for and map : readability

The new range-based for loops really improve readability and are really easy to use. However, consider the following : map FooAndAssociatedBars; for (auto& FooAndAssociatedBar : FooAndAssociatedBars) { …
Bérenger
  • 2,678
  • 2
  • 21
  • 42
1
2
3
22 23