Readability measures how easy code is to read and understand.

learn more… | top users | synonyms

120
votes
20answers
11k views

How would you know if you've written readable and easily maintainable code?

How would one know if the code he has created is easily maintainable and readable? Of course in your point of view (the one who actually wrote the code) your code is readable and maintainable, but we ...
108
votes
13answers
23k 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 ...
67
votes
19answers
22k views

Are `break` and `continue` bad programming practices?

My boss keeps mentioning nonchalantly that bad programmers use break and continue in loops. I use them all the time because they make sense; let me show you the inspiration: function verify(object) ...
1
vote
11answers
6k views

Avoid Postfix Increment Operator

I've read that I should avoid the postfix increment operator because of performance reasons (in certain cases). But doesn't this affect code readability? In my opinion: for(int i = 0; i < 42; ...
22
votes
12answers
2k views

How do people manage to write and maintain extremely complex and hard to read code? [closed]

Reading SQLite source code is IMO mission impossible. Yet it is a usable piece of quite complex software (it's a full-blown embedded database after all) that can be downloaded, compiled and used from ...
45
votes
6answers
2k views

Refactoring into lots of methods - is this considered clean or not? [duplicate]

So, I watched as my colleague complained a bit about a project he has inherited from someone who is, shall we say, not very experienced as a programmer (intern left to his own devices on a project). ...
18
votes
7answers
6k 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 ...
4
votes
6answers
2k views

Clarification of “avoid if-else” advice [duplicate]

The experts in clean code advise not to use if/else since it's creating an unreadable code. They suggest rather using IF and not to wait till the end of a method without real need. Now, this if/else ...
50
votes
9answers
6k views

Clean readable code vs fast hard to read code. When to cross the line?

When I write code I always try to make my code as clean and readable as possible. Every now and then there comes a time when you need to cross the line and go from nice clean code to slightly uglier ...
16
votes
4answers
8k 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 ...
19
votes
7answers
2k 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; ...
19
votes
2answers
1k 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
4answers
349 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 ...
29
votes
16answers
3k views

Should you sacrifice code readability with how efficient code is? [closed]

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?
25
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 ...
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 ...
17
votes
4answers
582 views

What should plugins use: hooks, events or something else?

Consider an app that allows plugins to react to its program flow. I know 2 ways to achieve this: hooks and events 1. Hooks Use calls to empty functions inside the main program flow. These functions ...
26
votes
5answers
2k 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 = ...
14
votes
1answer
2k 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 ...
28
votes
8answers
5k views

Is splitting up a function into several inner functions an anti-pattern? [duplicate]

Imagine a long and complicated process, which is started by calling function foo(). There are several consecutive steps in this process, each of them depending on result of the previous step. The ...
31
votes
11answers
1k 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 ...
23
votes
14answers
3k 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. ...
21
votes
7answers
1k views

How do I manage a very large set of rules and magic numbers in my program?

I'm somewhat new to programming (I'm a mechanical engineer by trade), and I'm developing a small program during my downtime that generates a (solidworks) part based on input from various people from ...
17
votes
3answers
1k views

Must source code released under GPL be human-readable?

In a response to another question, a poster suggested that under the GPL: ...you need to provide the human readable [code], not a whitespace stripped version... Readability would seem to me to ...
12
votes
4answers
773 views

When and for what purposes should the const keyword be used in C for variables?

While getting my code reviewed here the issue of using the const keyword came up. I understand that it is used for implementing read-only behaviour on variables. I am confused about what are the ...
10
votes
4answers
709 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 ...
10
votes
12answers
1k views

Maintainability of Boolean logic - Is nesting if statements needed?

Which of these is better for maintainability? if (byteArrayVariable != null) if (byteArrayVariable .Length != 0) //Do something with byteArrayVariable OR if ((byteArrayVariable != ...
3
votes
3answers
2k 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 ...
11
votes
6answers
1k views

Do sigils make source code easier to read?

In most programming languages, variables do not have identifying characters like they do in PHP. In PHP you must prefix a variable with the $ character. Example; var $foo = "something"; echo $foo; ...
17
votes
8answers
985 views

Do you prefer conciseness or readability in your code?

Language shortcuts can often be used to make code more concise. For example, ternary and null coalescing operators can reduce the amount of code, but arguably to the detriment of readability: In C#: ...
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 ...
6
votes
6answers
338 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 ...
3
votes
2answers
451 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 ...