Readability measures how easy code is to read and understand.
3
votes
0answers
109 views
What psychological factors account for readability? [migrated]
Readability is often intuitively synthesized. If you see some piece of code, you just know whether it is readable or not. But what are actual psychological, scientific explanations for this?
There ...
0
votes
0answers
94 views
Where can I find scientific papers about code readability? [closed]
I am looking for scientific papers or any kind of empirical data that on the readability of source code. I am not looking for differences between languages and I am very interested in the meaning of ...
-1
votes
2answers
139 views
Boolean-Integer Typecasting to Replace Conditional
When choosing a value based off of 2 boolean values in this format
var foo:int;
if (X){
foo = 50;
} else if (Y){
foo = -50;
} else {
foo = 0;
}
I discovered that I can condense this ...
5
votes
3answers
198 views
Is relying on implicit argument conversion considered dangerous?
C++ has a feature (I cannot figure out the proper name of it), that automatically calls matching constructors of parameter types if the argument types are not the expected ones.
A very basic example ...
3
votes
3answers
199 views
Is it correct to exclude argument names from function prototypes?
I was recently creating a small technical documentation for an application. The document is to be used by newly hired programmers to get acquainted with the application. It is much friendlier than the ...
4
votes
4answers
257 views
In which order should I do comparisons? [duplicate]
I'm a strong proponent of writing if statements like this:
variable == constant
Because to me it just makes sense, it is more readable than the inverted:
constant == variable
Which seems to be ...
2
votes
2answers
306 views
Leaving “Else” comments
Let's say I have a not-so-intuitive if statement in my code, but only if you're new to the codebase:
def set_markets(markets=None):
"""
Will accept 'all' as markets to set all markets on.
...
25
votes
5answers
1k views
Is use of finally clause for doing work after return bad style/dangerous?
As part of writing an Iterator, I found myself writing the following piece of code (stripping error handling)
public T next() {
try {
return next;
} finally {
next = ...
4
votes
2answers
222 views
Java Generics - how to strike a balance between expressiveness and simplicity
I'm developing some code that utilizes generics, and one of my guiding principles was to make it usable for future scenarios, and not just today's. However, several coworkers have expressed that I may ...
12
votes
1answer
522 views
Why Bootstrap 3 changes camelCase to dashes - is it more readable?
I'm wondering what's the reasoning behind Bootstrap's decision to change all camel case names into hyphenated names in v3.0. I searched on Google, and looked in a few books, but I can only find ...
5
votes
3answers
313 views
Is 'using' appropriate in a context where there is nothing to dispose?
In C#, using statement is used to dispose in a deterministic manner the resources without waiting for garbage collector. For example, it may be used to:
Dispose SQL commands or connections,
Close ...
62
votes
17answers
5k views
How would you know if you've written readable and easily maintainable code?
How would one know if the code he created is easily maintainable and readable? Of course in your point of view (the one who written the code) your code is readable and maintainable, but we should be ...
12
votes
4answers
576 views
Emphasize negation
I was just writing an if statement with fairly long property names and came occross this problem.
Let say we have an if statement like this:
...
16
votes
5answers
990 views
Descriptive naming vs. 80 character lines [closed]
I frequently hear these two valuable programming practices: (1) lines of code should be 80 characters or less and (2) use descriptive names for variables, methods, classes, etc. I understand the ...
18
votes
2answers
896 views
Is it a good idea to provide different function signatures that do the same thing?
Here is a C++ class that gets constructed with three values.
class Foo{
//Constructor
Foo(std::string, int, char);
private:
std::string foo;
char bar;
int baz;
};
All of ...
7
votes
4answers
643 views
Readability of || statements
On HTML5 Boilerplate they use this code for jQuery:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || ...
22
votes
9answers
856 views
Intentional misspellings to avoid reserved words
I often see code that include intentional misspellings of common words that for better or worse have become reserved words:
klass or clazz for class: Class clazz = ThisClass.class
kount for count in ...
5
votes
5answers
326 views
Question regarding code readability
I would like to know, is it considered a common practice to use constructions like |=, &&, ||, != altogether in the single line of code?
E.g.
hasErrors |= vi2!=null && ...
6
votes
3answers
191 views
“static” as a semantic clue about statelessness?
this might be a little philosophical but I hope someone can help me find a good way to think about this.
I've recently undertaken a refactoring of a medium sized project in Java to go back and add ...
0
votes
2answers
314 views
Why is there never any controversy regarding the switch statement? [closed]
We all know that the gotostatement should only be used on very rare occasions if at all. It has been discouraged to use the goto statement countless places countless times. But why it there never ...
8
votes
5answers
529 views
Which is more maintainable — boolean assignment via if/else or boolean expression?
Which would be considered more maintainable?
if (a == b) c = true; else c = false;
or
c = (a == b);
I've tried looking in Code Complete, but can't find an answer.
I think the first is more ...
51
votes
18answers
4k views
Are long methods always bad?
So looking around earlier I noticed some comments about long methods being bad practice.
I am not sure I always agree that long methods are bad (and would like opinions from others).
For example I ...
4
votes
1answer
207 views
Distinguishing repetitive code with the same implementation
Given this sample code
import java.util.ArrayList;
import blackjack.model.items.Card;
public class BlackJackPlayer extends Player {
private double bet;
private Hand hand01 = new Hand();
...
8
votes
3answers
481 views
What happens to programmers most oftenly while reading the code of others?
When reading others code do you usually have any troubles understanding it,
Or its more usually that you question the others code about it being wrong/non-efficient/bad-formatted(etc)?
Someone ...
-1
votes
1answer
99 views
Checking timeouts made more readable
I have several situations where I need to control timeouts in a technical application. Either in a loop or as a simple check. Of course – handling this is really easy, but none of these is looking ...
5
votes
6answers
645 views
Functional programming readability
I'm curious about this because I recall before learning any functional languages, I thought them all horribly, awfully, terribly unreadable. Now that I know Haskell and f#, I find it takes a little ...
3
votes
3answers
202 views
What defines code readability? [duplicate]
Possible Duplicate:
How would you know if you've written readable and easily maintainable code?
It is often said that readability is perhaps the most important quality-defining measure ...
7
votes
7answers
353 views
Using empty subclasses to add to the semantics of a class hierarchy?
I was wondering whether using (almost) empty derived classes to give additional semantics to a class hierarchy was a good idea (or practice) ?
Because a (not so short) example is always better than a ...
2
votes
2answers
154 views
Parameter order: size, count or the other way round
I hope this is the right forum for this ... Well, in C, the standard library uses usually (void* buffer, int size) when referring to some data buffer. I wonder if there is a rationale for this order ...
15
votes
7answers
3k views
How far should 'var' and null coalescing operator '??' be entertained without hampering readability?
I know the title of the question is very subjective, but I was confronted with usage of ?? operator by my peers, where at the same time I was not very happy/comfortable with applying var in new ...