Dialects and Readability
Last week, I noted that if there were clear rules about what programming constructs programmers should and shouldn't use, those rules effectively created a dialect, different from the language's nominal definition, in which programmers were actually writing their code.
Last month, I gave an example of a usage that, although I think it has clear advantages over how programmers normally write such programs, has the disadvantage of being unfamiliar:
for (string line; getline(cin, line); ) {
// Process a line of the file
}
This example reads each line of the standard input successively into the variable line, and then processes the line. Its advantage over the usual style is that it makes line into a local variable; there is no risk of using line by mistake after the loop has finished. In spite of clear advantages, programmers do not seem to be eager to adopt this technique.
Here are two other examples of programming styles that have not been widely adopted despite what I think are significant advantages.
The first is to put literals on the left side of relations, particularly assignment. In other words, instead of writing
if (n == 42) { /* … */ }
the style advocates writing
if (42 == n) { /* … */ }
The advantage of this style should be easy enough to see: A programmer who writes = instead of == will be greeted by a compiler error message rather than having a program that quietly sets n to 42 and then compares it (implicitly) with zero. People may argue that 0<n is harder to understand than n>0, but the counterargument is at least plausible that the difficulty comes solely from lack of experience.
The second example is putting modifiers such as const after the types they modify rather than before them:
int const n = 42; // rather than const int n = 42
The reason for this style is that when pointers are involved, writing
int const *p;
makes it clearer that p is a pointer to an int const, rather than that p is a const that points to an int. Writing
const int *p;
makes it unclear whether const is intended to apply to int *p or just to int; the alternative form makes it clear that const modifies only int.
Questions for readers: Do you think that the advantages of these dialects outweigh their unfamiliarity? Have you encountered other similar usages?

