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

Java: What is considered more readable, "this" or no "this"

You don't really need to write the "this" keyword in Java. But is it better to do so anyway? Does it make sense to homogenise your style, i.e. if you use "this" once, you use it every time it's implied? Or is there a place where you would always use…
Soyuz
  • 1,077
  • 1
  • 8
  • 16
9
votes
3 answers

Can you create collapsible #Region like scopes in C++ within VS 2008?

I miss it so much (used it a lot in C#). can you do it in C++?
RoyOsherove
  • 3,269
  • 2
  • 29
  • 26
9
votes
1 answer

Multiple return statements, readability

Possible Duplicate: Should a function have only one return statement? My teacher took points off on some java code I wrote (I'm still getting an A, this is just the first non 100% grade I've gotten in the java course) I'm not going to argue with…
Seth
  • 113
  • 1
  • 5
9
votes
8 answers

Making large constants in C source more readable?

I'm working on some code for a microprocessor. It has a few large, critical constants. #define F_CPU 16000000UL In this case, this is the CPU frequency. In Hertz. As it is, it's rather hard to tell if that's 1,600,000, 160,000,000 or 16,000,000…
Fake Name
  • 5,556
  • 5
  • 44
  • 66
9
votes
8 answers

Managing number of brackets in clojure

I am new to clojure and the main thing I am struggling with is writing readable code. I often end up with functions like the one below. (fn rep ([lst n] (rep (rest lst) n (take n (repeat (first lst))))) ([lst n out] (if …
Jim Jeffries
  • 9,841
  • 15
  • 62
  • 103
8
votes
12 answers

Should We Use Long-Name Or Short-Name in JavaScript Coding?

There is a discussion about JavaScript coding in my work group. Some people argues that we should use long-name for better readability; the others believes that short-name should be favored to same bits-on-wire. Generally, it is about coding…
Morgan Cheng
  • 73,950
  • 66
  • 171
  • 230
8
votes
8 answers

System.out.println() vs \n in Java

Let's say I wanted to print 5 lines. Which is the best method (for performance and readability). System.out.println(); System.out.println(); System.out.println(); System.out.println(); System.out.println(); or System.out.println("\n\n\n\n"); Is…
Will
  • 19,661
  • 7
  • 47
  • 48
8
votes
2 answers

Where to place __all__ in a Python file?

I am wondering, what the standard placement in a Python file for __all__? My assumption is directly below the import statements. However, I could not find this explicitly stated/asked anywhere. So, in general, where should one place __all__? Where…
Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
8
votes
1 answer

Use inline keyword for small, private functions in kotlin?

I would like to know, if it is a good idea to inline small, private functions? These functions, in my case, are only there for readability purposes and I know, that they are only called a few times, so the bigger bytecode size is insignificant. I…
aa-ndrej
  • 83
  • 5
8
votes
2 answers

Python multiple comparisons style?

I am wondering if there is a way to do the following in a more compact style: if (text == "Text1" or text=="Text2" or text=="Text3" or text=="Text4"): do_something() The problem is i have more than just 4 comparisons in the if statement and…
Symon
  • 2,170
  • 4
  • 26
  • 34
8
votes
6 answers

C# is there a nicer way of writing this?

int uploadsID; int pageNumber; int x; int y; int w; int h; bool isValidUploadID = int.TryParse(context.Request.QueryString["uploadID"], out uploadsID); bool isValidPage = int.TryParse(context.Request.QueryString["page"], out pageNumber); bool…
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
8
votes
10 answers

Does this feature exist? Defining my own curly brackets in C#

You'll appreciate the following two syntactic sugars: lock(obj) { //Code } same as: Monitor.Enter(obj) try { //Code } finally { Monitor.Exit(obj) } and using(var adapt = new adapter()){ //Code2 } same as: var adapt= new…
Carlos
  • 5,991
  • 6
  • 43
  • 82
8
votes
1 answer

Using && as a replacement for IF statement

I found the following snippet when digging through some code: "string" != typeof myVar && (myVar = ""); I understand what happens here. If myVar is not a string, that first condition evaluates to true so the second condition is evaluated, causing…
7
votes
5 answers

How to neatly match "x" and "[x]" with a regex without repeating?

I'm writing a Perl regex to match both the strings x bla and [x] bla. One alternative is /(?:x|\[x\]) bla/. This isn't desirable, because in the real world, x is more complicated, so I want to avoid repeating it. The best solution so far is putting…
Tim
  • 13,904
  • 10
  • 69
  • 101
7
votes
22 answers

Does generated code need to be human readable?

I'm working on a tool that will generate the source code for an interface and a couple classes implementing that interface. My output isn't particularly complicated, so it's not going to be hard to make the output conform to our normal code…
Herms
  • 37,540
  • 12
  • 78
  • 101