I don’t know much about programming… but do the “cringeworthy” examples you gave work? Is it just a matter of sloppy spaces and tabs that you don’t like?
…the fuck? This is cringeworthy? You must be the most sheltered programmer on the face of this planet if you think any of these even rates noticing, let alone a cringe.
Do yourself a favor and go read the archives at The Daily WTF until you understand what a programming abomination really is.
I have never seen anyone write like that second example you give.
It really bothers me to see people do this:
if(condition){
flag = true;
}else{
something=5;
}
Why not just line the braces up so everyone knows where things end by simply looking without having to create your own “brain stack” to see where the braces begin and end? Obviously this was as simple example but when you start throwing a bunch of functions, conditionals, switch statements, etc things get confusing.
My high school programming teacher must have been some sort of saint - the things I did in that class would make an ordinary person’s head explode. You see, I’d decided in my junior year that it was terribly clever to use the most verbose variable names, and comments, that I possibly could. So, I’d have variable names like “pleased-to-meet-you-hope-you-guessed-that-i-am-storing-the-user-input-from-the-main-menu” , and comments like “this increments the variable I’m using to control this loop, so that the user doesn’t stay trapped in it forever and ever. Without this line, the user would have no choice but to stay in front of the computer, forgoing his chance at marriage, children, an education beyond high school - all in the hopes of a program termination that will never, ever come. but is this really such a bad thing?..” And so on in that vein.
This is why I’m not a programmer, folks. Well, one of many reasons.
Variable names that are permutations of other variable names are even worse in assembly code. I actually had to work on some such software that was used in a life critical medical device. It was not pretty.
Heh. I do this. Why waste a whole line on one bracket? That example gets done in five lines what the “good” style takes eight lines to do. It’s easy to tell where the condition begins and ends - that’s what the indentation is for.
My personal pet peeve? Misspelled variable names. I still cringe at the memory of the “moreThenAYearFromToday” variable that cropped up everywhere in my first job - all other horrors I have managed to mostly block out of my mind. Yeah, I know it works just as well, but it’s just Wrong Wrong Wrong
By far the most irritating one for me is the horrible misuse of indentation of curly braces, not least because it is so damn widespread. I see so many people who insist on writing code like this:
I just don’t understand why anyone would want to do things the stupid way; placing the opening and closing braces of a block at the same level of indentation ensures that it’s possible to take in the block structure of a screenfull of code at a glance. At the cost of just a little extra vertical whitespace, entire programs are rendered more readable.
In particular, the practice of writing a closing brace, an “else” and an opening brace on the same line is called “cuddling” the else, and should be a sexual offense.
Anyway, I agree that tabulating lists of variable initializations is gratuitous. Also, trying to assign 6 to a vector<int> isn’t going to go over very well!
Anyone who argues K&R style vs. Allman style is an idiot. It is not hard to read either style once you’ve gotten used to both. I used to argue for Allman before I was forced to use K&R at a couple jobs and I realized that it just didn’t fucking matter.
GNU brace style, on the other hand? Pure trash.
On to my rant:
Fuck Dennis Ritchie for pissing all over 20 years of established research into formal languages and specifying an inherently ambiguous language. Efficiently parsing C requires some of the most egregious hacks I’ve ever seen and a 10-page long grammar. I mean, come on! Knuth’s paper on LR(k) grammars was published in 1965! All other programming languages since(save one, about more anon) then have managed to be unambiguous, why the hell couldn’t you manage that feat?
Oh, and fuck Bjarne Stroustrup for the utter monstrosity that is C++. You can just forget about trying to parse C++ with a grammar. Fuck, you can forget about trying to parse C++ period. C++ 98 is nearly 10 years and still nobody’s managed to come into full compliance with the standard. And fuck his attitude that (and I’m paraphrasing here) faced with a choice of making life harder on the programmer or on the compiler writer, he chose to make life harder on the compiler writer. Do you know what makes life hard for a programmer? Programming in a language whose feature support is spotty because the language is so damn complicated even the compiler writers can’t manage to actual support all of your features!
All this pain because these two idiots didn’t know the first thing about formal languages when they set out to design their languages. So much pain could have been avoided had they just done a modicum of research.
int dbi_debug = 0;
float neat_maxlen = 400;
string db2 = "bla";
int dbi = 89;
float dbm = 3.45;
int df = 938;
long long f = 1;
string file = "foo";
int ib = -22;
double ing = 2.3;
double ix = 1234.4;
int jdbc = 7;
long msql = 99;
or this:
int dbi_debug = 0;
float neat_maxlen = 400;
string db2 = "bla";
int dbi = 89;
float dbm = 3.45;
int df = 938;
long long f = 1;
string file = "foo";
int ib = -22;
double ing = 2.3;
double ix = 1234.4;
int jdbc = 7;
long msql = 99;
Annoys me no end. Because if tomorrow somebody needs to tweak the code and add another side effect, especially to the “else” clause," (doing this to the “if” clause will thankfully fail in compilation. Unless there is no “else” clause…) it will almost certainly become
if( condition) x=0;
else x=1;
y=1;
Notice anything wrong here…?
Please, for the love of Og, protect your if/else blocks with braces even if they contain a single statement!:
I’ve heard it said that C++ is like an octopus made by nailing extra legs onto a dog. It’s an absolute truth, but even still I have to admit that I have a soft spot in my heart for this kludgy, misbegotten language.
I just got through a course on compiler design in which the course project was to build a Java compiler (or more properly, a compiler for a reasonably demonstrative subset of the Java language), and although I don’t like Java very much either, I was impressed with how comparatively straightforward it was to develop a grammar for parsing it.