Readability measures how easy code is to read and understand.
10
votes
4answers
556 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 ...
14
votes
8answers
621 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 ...
5
votes
1answer
280 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 ...
11
votes
1answer
440 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
5answers
262 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, ...
1
vote
2answers
155 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 ...
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 ...
0
votes
0answers
99 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
145 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
210 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
202 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
264 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
311 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.
...
4
votes
2answers
283 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
584 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
320 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
577 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
904 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 ...
5
votes
5answers
329 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
193 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
325 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
539 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 ...
4
votes
1answer
212 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();
...
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 ...
8
votes
3answers
494 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
105 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
679 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
242 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 ...
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
279 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 ...
7
votes
7answers
362 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 ...
9
votes
5answers
757 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 ...
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 ...
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 = ...
7
votes
4answers
647 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 || ...
1
vote
3answers
202 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 ...
14
votes
6answers
913 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;
...
68
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 ...
10
votes
6answers
945 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
369 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
131 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 ...
5
votes
2answers
262 views
S-expressions readability
In a nutshell and for those who didn't know it, Lisp functions/operators/constructs are all uniformly called like this:
(function arg0 arg1 ... argN)
So what in a C-like language you would express ...
23
votes
15answers
2k views
Does simplicity always improve Readability?
Recently, I was developing a set of coding standards for our company. (We're a new team branching out into a new language for the company.)
On my first draft, I set the purpose of our coding ...
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 ...
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.
...
6
votes
6answers
298 views
Formatting 'Complex' Math
Note: by 'complex' math I mean an equation with many steps involved and a wide mix of operators.
A programmer should know the order that operators are evaluated in an equation. However it can be a ...
11
votes
11answers
292 views
Should 'mathematical' functions follow mathematical notation?
I suppose this question is going to be immediately flagged as subjective, but which do you think is better:
double volume(double pressure, double n_moles, double temperature) {
return n_moles * ...



