Readability measures how easy code is to read and understand.
70
votes
18answers
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 ...
2
votes
3answers
121 views
Equating multiple new variables with an old one
Sometimes I run into a situation where I need to equate two new variables with an old one. Which of the following (if any) is a good practice (w.r.t. code readability or any other factor), under what ...
16
votes
4answers
2k views
Why are nested loops considered bad practice?
My lecturer mentioned today that it was possible to "label" loops in Java so that you could refer to them when dealing with nested loops. So I went home and looked up the feature as I didn't know ...
7
votes
3answers
292 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 ...
15
votes
8answers
694 views
Should I write compact code or code with lots of spaces? [duplicate]
I have two friends that have completely different schools of thought on how to lay out their code.
The first says that code should be well-indented and use lots of spaces and to name variables ...
6
votes
1answer
300 views
How to write readable Clojure Code?
I am new to Clojure. I can understand the code I write but it becomes too difficult to understand it later.
It becomes difficult to match parentheses.
What's the generic conventions to follow ...
2
votes
5answers
302 views
What's the dominant naming convention for variables in PHP: camelcase or underscores?
The consensus seems to be that one should follow the convention of the platform they're developing for. See:
Underscore or camelcase?
Naming conventions: camelCase versus underscore_case?
However, ...
82
votes
13answers
19k views
Is it OK to split long functions and methods into smaller ones even though they won't be called by anything else? [duplicate]
Lately I've been trying to split long methods into several short ones.
For example: I have a process_url() function which splits URLs into components and then assigns them to some objects via their ...
11
votes
1answer
448 views
Are there any statistics on how often code is read?
I have often come across claims that source code is read much more than it is written and just wanted to do a little calculation like:
If you write a line that takes me 5 minutes longer to read ...
2
votes
2answers
184 views
Programming by Intention, Depth-First or Breadth-First?
Say I have the following graph of dependencies between procedures/functions/methods:
o
/ \
v e
/ \ / \
r f l w
That is, function o first calls function v, and then ...
4
votes
2answers
290 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 ...
0
votes
0answers
103 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
146 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 ...
3
votes
3answers
205 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
265 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
312 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 = ...
12
votes
1answer
620 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
328 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 ...
12
votes
4answers
580 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
1k 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
919 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
648 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
873 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
334 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
194 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
334 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
546 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
215 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
501 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
109 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
709 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
285 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
377 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
4k 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 ...
16
votes
9answers
1k views
Hiding away complexity with sub functions
I am having a discussion on code style, and it's starting to sound like a "matter of taste". I strongly believe otherwise, so I'm writing this to get your opinion and learn from your arguments for and ...
11
votes
2answers
281 views
Studies on how well can a programmer understand code in unfamiliar languages?
Are there any serious studies on how well an experienced programmer who knows language X can understand code written by a competent programmer using language Y, for a good range of widely used ...
9
votes
5answers
759 views
Zero as a constant?
I have come across this programming idiom recently:
const float Zero = 0.0;
which is then used in comparisons:
if (x > Zero) {..}
Can anyone explain if this is really any more efficient or ...
7
votes
5answers
1k views
Is C# becoming harder to read?
As C# has progressed, many language features have been added. It has come to the point where it's becoming unreadable for me.
As an example, consider the following code snip from Caliburn.Micro code ...
32
votes
8answers
1k views
When using method chaining, do I reuse the object or create one?
When using method chaining like:
var car = new Car().OfBrand(Brand.Ford).OfModel(12345).PaintedIn(Color.Silver).Create();
there may be two approaches:
Reuse the same object, like this:
public ...
19
votes
14answers
2k views
Why do so many developers believe performance, readability, and maintainability cannot coexist?
While responding to this question, I began to wonder why so many developers believe a good design should not account for performance because doing so would affect readability and/or maintainability.
...
32
votes
15answers
3k views
Is it bad practice to name an unused variable with a single underscore?
Often when the syntax of the language requires me to name a variable that is never used, I'll name it _.
In my mind, this reduces clutter and lets me focus on the meaningful variables in the code. I ...
14
votes
6answers
932 views
while(true) and loop-breaking - anti-pattern?
Consider the following code:
public void doSomething(int input)
{
while(true)
{
TransformInSomeWay(input);
if(ProcessingComplete(input))
break;
...
1
vote
3answers
203 views
Which of these looks cleaner?
I have wrote a small method in a program to do one thing my method looks like this:
public static void removeExpiredAssignments(Module module){
module.removeExpiredAssignments();
}
So the ...
29
votes
20answers
2k views
Should you sacrifice code readability with how efficient code is?
Should you sacrifice code readability with how efficient code is?
e.g. 3 lines of code into 1 line.
I read in Code Craft by Pete Goodliffe that readability is key.
Your thoughts?
10
votes
6answers
959 views
Need to make my code more readable to the other programers in my team
I am working a project in delphi 7 and I am creating a installer for the application,
there are Three main parts.
PostgreSQL installation/uninstallation
myapplication ( setup of myapplication is ...
8
votes
3answers
374 views
Should we rename overloaded methods?
Assume an interface containing these methods :
Car find(long id);
List<Car> find(String model);
Is it better to rename them like this?
Car findById(long id);
List findByModel(String ...
2
votes
2answers
133 views
Trimming script size by using array notation for frequently accessed properties
I noticed some redundancy in a script I ran through Google Closure Compiler.
(function(){function g(a){var k;if(a){if(a.call)a.prototype=j,a.prototype[e]={}}else a=
{};var ...

