readability

Using explicitly numbered repetition instead of question mark, star and plus

I've seen regex patterns that use explicitly numbered repetition instead of ?, * and +, i.e.: Explicit Shorthand (something){0,1} (something)? (something){1} (something) (something){0,} (something)* (something){1,} (something)+ The questions are: Are these two forms identical? What if you add possessive/re...

Usage of ‘if’ versus ‘unless’ for Perl conditionals

What are some guidelines for the best use of if versus unless in Perl code? Are there strong reasons to prefer one or the other in some situations? ...

Using true and false as the expressions in a conditional operation

I'm maintaining some code and have found the following pattern a lot: var isMale = (row["Gender"].ToString() == "M") ? true : false; instead of this: var isMale = (row["Gender"].ToString() == "M"); Is there any reason why anyone would do this? Does anyone think the former is more readable or clearer? Is there some sort of old C "go...

Using break statement even though previous line results in exit

Hi! I was reading through some code (C, if it makes a difference to anyone) today and got curious about a switch-block. switch (c_type) { case -1: some_function(some_var); break; [...] default: abort(); } Now, this is a perfectly simple switch-block. It's the some_function(some_var)-call I'm curious about: If you, the pro...

Database normalization design - single or multiple tables

Should this be represented in the database as 1 table or 3 tables? I and my friend have different opinions about this so I'd like to see the general views on this. (Maybe it should be a vote for either solution?) Create Table Order // Basic fields of the table - ID (Primary key) - CustomerID (integer, with a FK) - Quantity - Prod...

Proper commenting for functional programming

I've been learning scheme, and I just realized that I don't really know how to properly comment my functional scheme code. I know how to add a comment of course - you add a ; and put your comment after it. My question is what should I put in my comments, and where should I comment for maximum readability and comprehensability for other p...

How to calculate easy to read color for a random backcolor?

Hi there, in my current tool there is a colored box with some numbers in it. The backcolor of the box is defined by some sort of list but can also be altered by the user. The forecolor (== fontcolor of the numbers) cannot, and i want to make sure that the user can always read the numbers, so i´d like to adjust the forecolor of the numbe...

Is for keyword obsolete like goto in modern object-oriented languages?

Hi, Is for keyword obsolete or may become obsolete just as goto in languages like C# or Java? In a few years, will it be strange and suspicious to see an object-oriented code which uses for, like today, it's very suspicious to see gotos? In other words, is there any reason to know and use for in programs? I notice that there are a b...

Improve readability of a short snippet while keeping StyleCop happy.

The code below looked ok to me when I wrote it, but when I came back to it again, it was pretty hard to grasp what is going on. There used to be parenthesis around value == ..., but I had to remove them after StyleCop became mandatory (I cannot really control this). So, how can I improve this section of code? I was thinking: x = value ==...

Is wrapping STL idioms for readability a good idea?

Hi, I'm currently working on a C++ project that needs to have as few external dependencies as possible, and thus I'm pretty much sticking to STL and Boost. Until now, I've been almost exclusively living in Qt-land when it comes to C++. In general I tend to use C# and Python when I can. Today I wanted to check whether a std::vector cont...

Writing unittests for a function that returns a hierarchy of objects

I have a function that performs a hierarchical clustering on a list of input vectors. The return value is the root element of an object hierarchy, where each object represents a cluster. I want to test the following things: Does each cluster contain the correct elements (and maybe other properties as well)? Does each cluster point to t...

How to return a flag plus an optional message in Java?

I want to write a method in Java that verifies that some conditions hold on some data, and acknowledges that the data is valid or produces an appropriate error message otherwise. The problem is that we cannot return more than one thing from a method, so I'm wondering what the best solution is (in terms of readability and maintainability...

Immutability and Readability

So I've been reading Effective Java by Joshua Bloch and noticed two points which I actually have encountered in my work. Point 1: Making setter methods to make code more readable. In his example, we have a class with a ridiculously huge constructor. When people instantiate the class, it's hard to tell what's going on with all the para...

Why C# doesn't accept the boolean operators as words ("and", "or", "not" ,..etc) with the current operators ?

My if stetement: if (!string.IsNullOrEmpty(Person.Name)) // some code I think the "!" operator is less readable when writing imperative code, Are you agree with me the following code is more readable? if (not string.IsNullOrEmpty(Person.Name)) // some code I'm not talking about replace the current operators, bu...

How do you encourage fellow programmers to care about code readability?

I've noticed some programmers do not seem to have much desire to write clean, organized, and readable code. What are some good ways to encourage consistent indentation, good naming of variables and functions, organized file structures, among other things? ...

Splitting C++ Strings Onto Multiple Lines (Code Syntax, Not Parsing)

Not to be confused with how to split a string parsing wise, e.g.: http://stackoverflow.com/questions/236129/how-to-split-a-string I am a bit confused as to how to split a string onto multiple lines in c++. This sounds like a simple question, but take the following example: #include <iostream> #include <string> main() { //Gives error...

Making a readable xml file for NSXMLParser

Hi, I'm new to xml parsing and am trying to make a file for NSXMLParser to parse. I'd be editing it by hand and have several nested groups, so was looking for advice on how best to approach this. I found that I couldn't just use newlines to cleanly separate my groupings because the newline would find its way into the parsed data. So, ...

Formatting of dynamically generated HTML - does no one care?

Possible Duplicate: Formatting of dynamically generated HTML - does no one care? I have very little experience in web development, so this may be a very basic question. It's just, from the limited experience I do have (a little PHP, and a little Ruby on Rails), it seems that the way dynamically generated HTML is formatted jus...

Formatting of dynamically generated HTML - does no one care?

I have very little experience in web development, so this may be a very basic question. It's just, from the limited experience I do have (a little PHP, and a little Ruby on Rails), it seems that the way dynamically generated HTML is formatted just "doesn't matter"; it ends up ugly, with weird indentation, and nobody cares because that i...

Is K&R teaching bad readability?

Hello. It has been a while since I looked at C (still learning) and I just got back into the K&R book. I just had a go to Exercise 5-3 (p107). Write a pointer version of the function strcat that we showed in Chapter 2: strcat(s,t) copies the string t to the end of s. I came up with this... void strcat(char *s, char *t); void st...