Readability measures how easy code is to read and understand.

learn more… | top users | synonyms

-4
votes
0answers
38 views

Custom code folding in Eclipse

For those who use Eclipse and are working primarily in Java, there is a custom folding plugin coffee script. It is old but still works. However, C/C++ users are left without code folding ...
0
votes
0answers
61 views

Naming self or this something else, a good idea?

I'm finding that my code becomes more readable when I make a local reference to this/self, and/or call it something that makes sense in the context. "self" or "this" doesn't really indicate what kind ...
2
votes
2answers
198 views

At what point should you collapse many parameters into (e.g.) struct to improve readability in function headers?

While making a struct creates some overhead at run-time, packaging a bunch of frequently-used-together variables can dramatically increase code readability. How do you balance the two? I was just ...
0
votes
1answer
20 views

Accessing struct attribute: casting vs field name

I was just going over some kernel code, I noticed that rb->__rb_parent_color = (unsigned long)p | color; is kinda wired. The first field of a struct is accessed by casting the pointer and not by ...
17
votes
7answers
2k views

What can one do to improve readability of math-oriented code in C#, Java, and similar? [closed]

As both a C programmer and a C# programmer, one of the things I don't like about C# is how verbose math functions are. Every time you would have to use a Sin, cosine, or power function for example, ...
0
votes
0answers
57 views

API for accessing CTS and DSR signals of serial port

I'm trying to improve another abstraction of the serial port. The project involved often needs to check one of the single control signals CTS and DSR. This is currently done by a call to ...
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 ...
3
votes
1answer
198 views

How reduce the usage of Magic Strings?

In the application database there is a configuration table with this schema: Table: ReleaseProperty ReleasePropertyID ReleaseID Name Value Currently to retrieve a specific property I pass to the ...
1
vote
3answers
179 views

Redundant function to clarify purpose? [duplicate]

Since what matters is not how the code does it but what it does, would you consider wrapping a function with a different name just to clarify it's behavior in certain situations a good practice? ...
4
votes
1answer
542 views

In Java, why use bit hacks when non-bitwise technique it is more readable?

Is there any legitimate use for bit manipulation hacks in higher-level languages such as Java? I can see them being useful in speed-sensitive low-level and computation-intensive programs, e.g. ...
7
votes
1answer
134 views

Restructuring a large Chrome Extension/WebApp

I have a very complex Chrome Extension that has gotten too large to maintain in its current format. I'd like to restructure it, but I'm 15 and this is the first webapp or extension of it's type I've ...
1
vote
4answers
198 views

Is there a good way to communicate the intent that a class only contains referentially transparent methods?

My workplace mostly uses C# for writing code. I'm trying to figure out a good way to indicate that a class with referentially transparent methods is intended to be referentially transparent (i.e., ...
17
votes
4answers
613 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 ...
3
votes
1answer
108 views

Exceptions catching clutter code and make it hard to read

When I read well written code that checks to make sure all the input is of the correct format and type, and also catches all the things that possibly could go wrong, I find it difficult to understand ...
0
votes
1answer
112 views

Switch / select case etc. compared to If … ElseIf … Else [duplicate]

I don't understand why the switch or equivalent is so popular in languages. To me, it seems like it had a place back in the days when the alternative was lots of nested if statements in the else part ...
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 ...
1
vote
2answers
120 views

Is input validation necessary?

This is a very naive question about input validation in general. I'm a MATLAB user (1.5 years old) and I learned about input validation techniques such as "parse" and "validatestring". In fact, ...
1
vote
1answer
370 views

Get subset of associative array. Which of these is more readable? Is there another reason to use one over the other (or a different method)

If I have an array that has more info than I need and I want to pull out a subset of its name value pairs I have come up with 2 methods. Both rely on this: ...
13
votes
4answers
978 views

Which way to terminate reading loop is the preferred approach?

When you have to iterate a reader where the number of items to read is unknown, and the only way to do is it to keep reading until you hit the end. This is often the place you need an endless loop. ...
9
votes
5answers
623 views

Can a pure-functional solution to this problem be as clean as the imperative?

I have an exercise in Python as follows: a polynomial is given as a tuple of coefficients such that the powers are determined by the indexes, e.g.: (9,7,5) means 9 + 7*x + 5*x^2 write a function to ...
1
vote
4answers
268 views

What's the most readable way of echoing from PHP?

Should I use <?php if(!$user->is_logged_in()){ echo '<p id="login">Click <a href="login">here</a> to log in</p>'; } ?> or <?php ...
1
vote
1answer
378 views

Readability vs benefits of polymorphism

We are dealing with a lot of CRUD operations in our application. Each database table has one or more corresponding SQLContainer instances to perform various types of operations. All of these ...
1
vote
4answers
947 views

Usage of magic strings/numbers [closed]

This is somewhat controversial topic, and I guess there is as many opinions as there are programmers. But for the sake of it, I want to know what are the common practices in business (or in your work ...
6
votes
6answers
628 views

Why do many languages not support named parameters? [closed]

I was just thinking how much easier it would be to read code if, when calling a function, you could write: doFunction(param1=something, param2=somethingElse); I can't think of any drawbacks and it ...
11
votes
5answers
506 views

Code repetition vs multi responsible method

I try to follow the Single Responsibility Principle (SRP) and also to omit Code Repetitions. However there are often places where there are code repetitions that are nothing more than code blocks of ...
1
vote
3answers
723 views

Storing a value vs calling reference for repeated use in Java

I have an old habit of avoiding calling references multiple times, both for easier to read/maintain code, and for possible efficiency. But I'm wondering which is more efficient (memory, performance, ...
0
votes
2answers
486 views

Good or bad code? Or “a secret reason”?

I think this code: if(file_exists("amodule.inc.php")) require_once("amodule.inc.php"); is misleading because of the use of the require_once. I think that - to keep the logic and "wording" ...
3
votes
2answers
391 views

Extracting lambda expressions from linq queries and readability

Every now and then when I have a complex lambda, I do something like this: Func<SomeObject, bool> equals = o => o.ID == someID && o.Name == someName && IsAdd || ... var ...
1
vote
2answers
309 views

How much functional programming expertise can programmers be expected to have? [closed]

I'm coding in a non-functional language with functional mechanisms (C# to be specific, but you could substitute, say C++ and use function pointers, or what have you) on a small team. It's my habit to ...
0
votes
1answer
78 views

Good practice to use namespace or prefix to indicate what file function is from? [duplicate]

For example, I have the function generate_salt() in encryption.file but the person may not know where generate_salt() is from. Using a namespace like encryption::generate_salt(), or ...
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; ...
4
votes
6answers
3k 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 ...
5
votes
5answers
575 views

Is it best to use “get” as a prefix for getters?

if I had a boolean (property) shouldAutoLogin is it better to name the getter getShouldAutoLogin or just shouldAutoLogin so that it reads more like English? ex : if(shouldAutoLogin){ ... } or ...
2
votes
2answers
413 views

XML/HTML: Do we need the element name in closing tags?

Compared to other serialization languages, one of the main criticisms directed at XML is its verbosity; JSON's more terse and readable for most cases, but not all. But it seems to me that we could ...
12
votes
4answers
943 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 ...
0
votes
5answers
182 views

Question regarding Readability vs Processing Time

I am creating a flowchart for a program with multiple sequential steps. Every step should be performed if the previous step is succesful. I use a c-based programming language so the lay-out would be ...
8
votes
5answers
208 views

Gathering all data in single iteration vs using functions for readable code

Say I have an array of runners with which I need to find the tallest runner, the fastest runner, and the lightest runner. It seems like the most readable solution would be: runners = getRunners(); ...
2
votes
3answers
186 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 ...
15
votes
4answers
10k 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 ...
15
votes
7answers
1k 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 ...
8
votes
1answer
1k 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 ...
12
votes
1answer
547 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 ...
11
votes
4answers
9k views

What's the dominant naming convention for variables in PHP: camelcase or underscores? [closed]

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, ...
3
votes
2answers
498 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 ...
112
votes
13answers
24k 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
2answers
168 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 ...
6
votes
3answers
993 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
221 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 ...
5
votes
4answers
351 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
317 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. ...