# Programming style abominations

**URL:** <https://boards.straightdope.com/t/programming-style-abominations/429810>\
**Category:** The BBQ Pit\
**Created:** [December 13, 2007, 3:24am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810 "2007-12-13T03:24:00Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [December 13, 2007, 2:48pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/41 "2007-12-13T14:48:47Z")

</div>

[QUOTE=Usram]  
The religious wars over braces make me glad I use Python. No braces or line terminators at all (well, except for a few colons, which I understand were included simply because it felt right). Since we all (should) use indentation, why not make it significant?

[/QUOTE]

Yeah, you Python doodz have done the world a great service by replacing the holy war over brace style with a holy war over spaces vs. tabs. 🙂

Ultimately, indenting style is irrelevant. It can easily be “corrected” to whatever style you prefer by your local ‘indent’ program or a source control filter. If you’re complaining about indenting and braces, you haven’t seen bad programming. (I also recommend reading The Daily WTF. A lot.)

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [December 13, 2007, 2:52pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/42 "2007-12-13T14:52:36Z")

</div>

[QUOTE=Derleth]  
[ul]  
[li] **Fuck Javascript for having no self esteem** : _It isn’t Java! It is nothing like Java! It is a good language!_ But you’d never know it the way it gets fucked around with by browsers and stupid, stupid hacks crapping out webpages that make the cursor grow a tail and butt-fuck Steve Reeves. It has a wonderful style of OO that solves the fragile base class problem, it dispenses with the stupider syntax, and it generally acts enough like Lisp to make it a wonderful prototyping language. First, though, you need to get it away from its abusive relationship with the Web and cure its identity crisis.[/li][/ul]  
[/QUOTE]

It’s nice to see another person in defense of the noble Javascript. It’s a great high-level language. Lots of people could learn a lot from simple prototype-based OO.

But I must disagree with you about C#. If you need to do some object-oriented systems programming, which would you rather use? Bjarne’s abomination, or a clean super-set of C with bounds checking and garbage collection?

Personally, though, I really like Objective-C.

---

<div class="post-metadata">

**Author:** ![shiftless](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@shiftless](https://boards.straightdope.com/u/shiftless)\
**Post date:** [December 13, 2007, 2:59pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/43 "2007-12-13T14:59:39Z")

</div>

Ah … the religious wars, as we call them in my office. The users of this style:

```auto

if (cond) {
   <statements>
}

```

give many reasons for their behavior:

This is probably due to some early childhood trama or poor potty training. They just need understanding and re-education. 😉

We don’t even discuss when to use IF blocks vs. CASE statements anymore.

---

<div class="post-metadata">

**Author:** ![Blaster\_Master](https://avatars.discourse-cdn.com/v4/letter/b/cab0a1/32.png) [@Blaster\_Master](https://boards.straightdope.com/u/Blaster_Master)\
**Post date:** [December 13, 2007, 3:27pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/44 "2007-12-13T15:27:57Z")

</div>

[QUOTE=Polerius]  
Which one is easier to parse, visually, this:  
…

```auto

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;     

```

[/QUOTE]

I don’t understand this at all. The spacing is irrelevant if you’re using an IDE made any time in the last 15 years or so. Granted, I’ve done a non-insignificant amount of my coding without a modern IDE, and that’s where the real objection to the style comes in… who the hell blocks together that many variable declarations without any sort of organization? If I need to declare that many variables in a block, which is not often, I will organize them in a meaningful way and comment if necessary.

And speaking of variables, give them f’n meaningful names, will you? I know someone mentioned seeing someone name a variable after himself, but it’s just as horrible when all of the variables have only slightly more than meaningless names. I’m okay with using things like i, j, k for loops and such because it’s established style, but using a bunch of variables like int1, int2, int3, etc. is impossible to read. I’m fine with abbreviating things, but make sure the abbreviations make sense.

I’m constantly reading code written by other people, mostly Microsoft developers, and invariably (NPI) making improvements or fixing bugs, and their style is impossible to read. I suppose, at least it’s consistent.  
And to comment on the

```auto

if (cond) {
   <statements>
}

vs.

if (cond)
{
   <statements>
}

```

The first is unconscionable to me, perhaps because I learned to program in PASCAL where it would look completely horrendous.

```auto

if (cond) then begin
   <statements>
end

```

The only time I’d ever put the {}'s on the same line as code is for the do-while loops because the only way to remove the visual ambiguity of the end of a do-while loop and the beginning of a while loop is with

```auto

do{
   <statements>
}while (cond)

```

Consequently, I avoided the do-while loop like the plague.

---

<div class="post-metadata">

**Author:** ![3acresandatruck](https://avatars.discourse-cdn.com/v4/letter/3/e79b87/32.png) [@3acresandatruck](https://boards.straightdope.com/u/3acresandatruck)\
**Post date:** [December 13, 2007, 4:11pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/45 "2007-12-13T16:11:20Z")

</div>

[QUOTE=DeadlyAccurate]  
Was it easier to just rewrite it from scratch? I’ve never even seen a GOTO statement in COBOL. I can’t comprehend variable names like that, either. Who names variables something so incomprehensible?

Oh, and Dark Ages? I was doing COBOL on the mainframe a year and a half ago.  
[/QUOTE]

I couldn’t rewrite it until I deconstructed it. Nobody knew what the program did, except that you fed it these two files and the personnel database, “then a miracle occurs”, and a report and a paycheck file fit for printing came out. The existing program, such as it was, was the ONLY documentation on how the paychecks were calculated. I tried contacting the accounting department, but they had no idea what the requirements were. Even the people I contacted at the state revenue department couldn’t tell me what the rules were for payroll taxes. Seemed insane to me, but that’s the way it was.

I’d conjecture it was the first COBOL program the original coder had ever written. There were no ELSEs to go with IF-THENs (and no DO blocks of any kind)…just branch here via a GOTO, branch back, branch hither and yon. In fact, the GOTO targets were labels like GOTO-TARGET-001, GOTO-TARGET-002, etc. (So yeah, you’d see a statement that said GOTO GOTO-TARGET-001.) Loops were ‘manually’ controlled by explicitly coded counters and GOTO statements and IFs for the loop exit control… (Evidently the guy wasn’t aware that you could achieve a DO loop in COBOL using a PERFORM-VARYING combo.) Heck, the guy never even indented a single statement.

The variable names were done as though there was an 8-character limit. Besides, it was hard to write, it should be hard to understand, no? I love the fact that COBOL is still around; I swear it’ll outlive humanity.

And since I forgot this on my previous post… Hey you kids! Get out of my field!!

---

<div class="post-metadata">

**Author:** ![Polerius](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@Polerius](https://boards.straightdope.com/u/Polerius)\
**Post date:** [December 13, 2007, 5:02pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/46 "2007-12-13T17:02:22Z")

</div>

[QUOTE=Blaster Master]  
I don’t understand this at all. The spacing is irrelevant if you’re using an IDE made any time in the last 15 years or so.  
[/QUOTE]

Why is that? What do modern IDE’s do with statements such as the one you quoted?

> [@](#):
>
> who the hell blocks together that many variable declarations without any sort of organization? If I need to declare that many variables in a block, which is not often, I will organize them in a meaningful way and comment if necessary.

Agreed. What I gave was an artificial example with too many variables being initialized in the same spot, just to show that aligning them improves readability (in a basic text editor, like vi or emacs)

[QUOTE=ultrafilter]  
…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.  
[/QUOTE]

If you notice, the title of the thread is “programming _style_ abominations”, not  
“programming abominations”.

Of the latter, I’ve seen too many to count here, but this was more about coding style (or rather space-brace-and-indentation style).

BTW, the OP was a bit tongue-in-cheek, because it is obviously an exaggeration to call a badly-placed brace an “abomination”.

[QUOTE=Blaster Master]

in PASCAL …

```auto

if (cond) then begin
   <statements>
end

```

[/QUOTE]

This reminds me one of my huge pet peeves about programming languages.

Why does every goddamn language have to invent its own way of saying if-then-else?

Each language should just concentrate on adding its own unique features (e.g. OOP) and leave the damn if statement alone (BTW that goes for ‘for’ loops too, and don’t get me started on the comment character)

Let’s see, we have  
C

```auto

if(bla)
{
   foo;
}
else if (test)
{
   bar;
}

```

Perl

```auto

if(bla)
{
   foo;
}
elsif (test)
{
   bar;
}

```

Csh

```auto

if(bla) then
   foo;
else if (test)
   bar;
endif

```

Matlab

```auto

if(bla)
   foo;
elseif (test)
   bar;
end

```

and, now, based on **Blaster Master** ’s example, I can add PASCAL, which I guess would look like

```auto

if (bla) then 
   begin
     <statements>
  end
else if (test) then
  begin
       <statements>
  end
end

```

and the list goes on and on.

Hey, jackass language developers, you are not adding anything to the programming paradigm by inventing your own little way of doing a simple if statement, or for that matter, a comment, or a for loop, and with all the different ways of saying ‘break’ and ‘continue’ in all the languages.

---

<div class="post-metadata">

**Author:** ![wolfman](https://avatars.discourse-cdn.com/v4/letter/w/a8b319/32.png) [@wolfman](https://boards.straightdope.com/u/wolfman)\
**Post date:** [December 13, 2007, 5:41pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/47 "2007-12-13T17:41:35Z")

</div>

[QUOTE=Enderw24]  
Uh…

I remember when my friend couldn’t get the little turtle to move.

That’s about all I can contribute.  
[/QUOTE]

Ah yes Apple LOGO, my first language. Many cycles ago.  
When I was a TA I constantly had a fight with my prof of Variable names, he would teach them “be as descriptive as possible in variable names, point will be taken off for nondescriptive names” with no further instruction, then I had to grade then damn things.

```auto

int[] arrayToStoreTheTemperatureIn;
int variableToStoreTheXAxisOfTheArray =0;
int variableToStoreTheYAxisOfTheArray =0;
int variableToStoreTheXAxisOfTheArray =0;

.....

for(int variableToControltheXAxisOfTheArray =0; variableToControltheXAxisOfTheArray ;
 variableToControltheXAxisOfTheArray ++){
      for (int variableToControltheYAxisOfTheArray =0; variableToControltheYAxisOfTheArray ;
 variableToControltheYAxisOfTheArray ++){

        for (int variableToControltheZAxisOfTheArray =0; variableToControltheZAxisOfTheArray ;
 variableToControltheZAxisOfTheArray ++){

            if (arrayToStoreTheTemperatureIn[variableToControltheXAxisOfTheArray] == variableToStoretheXAxisOfTheArray)
          {
          killProfessorWithDullImplement(myFoot, hisSpleen);}
            }
        }
 }

```

---

<div class="post-metadata">

**Author:** ![Robot\_Arm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/robot_arm/32/18280_2.png) [@Robot\_Arm](https://boards.straightdope.com/u/Robot_Arm)\
**Post date:** [December 13, 2007, 6:40pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/48 "2007-12-13T18:40:19Z")

</div>

One word: INTERCAL

I think **3acres** knows what I’m talking about.

---

<div class="post-metadata">

**Author:** ![Taber](https://avatars.discourse-cdn.com/v4/letter/t/ac91a4/32.png) [@Taber](https://boards.straightdope.com/u/Taber)\
**Post date:** [December 13, 2007, 7:11pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/49 "2007-12-13T19:11:03Z")

</div>

[QUOTE=3acresandatruck]  
I couldn’t rewrite it until I deconstructed it. Nobody knew what the program did, except that you fed it these two files and the personnel database, “then a miracle occurs”, and a report and a paycheck file fit for printing came out. The existing program, such as it was, was the ONLY documentation on how the paychecks were calculated. I tried contacting the accounting department, but they had no idea what the requirements were. Even the people I contacted at the state revenue department couldn’t tell me what the rules were for payroll taxes. Seemed insane to me, but that’s the way it was.

[/QUOTE]

So when you coded it to give programmers three times their current pay, no one would know that it wasn’t supposed to?

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [December 13, 2007, 7:18pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/50 "2007-12-13T19:18:10Z")

</div>

Here’s a little abomination for all of you C++ folks:

```auto

const int c = 3;
int* x = &c;

*x = 5;

if ((&c == x) && (*x != c))
{
    printf("Everything you know is wrong!");
}

```

Visual Studio 6.0 and 7.0 will actually print that out. I’ve not had the chance to try it in other compilers.

---

<div class="post-metadata">

**Author:** ![Polerius](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@Polerius](https://boards.straightdope.com/u/Polerius)\
**Post date:** [December 13, 2007, 7:32pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/51 "2007-12-13T19:32:13Z")

</div>

[QUOTE=ultrafilter]  
Here’s a little abomination for all of you C++ folks:

```auto

const int c = 3;
int* x = &c;

*x = 5;

if ((&c == x) && (*x != c))
{
    printf("Everything you know is wrong!");
}

```

Visual Studio 6.0 and 7.0 will actually print that out. I’ve not had the chance to try it in other compilers.  
[/QUOTE]

```auto

-> g++ -o tst tst.cc
tst.cc: In function `int main()':
tst.cc:8: error: invalid conversion from `const int*' to `int*'

```

---

<div class="post-metadata">

**Author:** ![Blaster\_Master](https://avatars.discourse-cdn.com/v4/letter/b/cab0a1/32.png) [@Blaster\_Master](https://boards.straightdope.com/u/Blaster_Master)\
**Post date:** [December 13, 2007, 8:21pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/52 "2007-12-13T20:21:20Z")

</div>

[QUOTE=Polerius]  
Why is that? What do modern IDE’s do with statements such as the one you quoted?  
[/quote]

In my experience with Visual Studio, Eclipse, Borland, and who knows what else, reserved words are generally colored, bolded, or otherwise differentiated from identifiers so the type would be easily visually distinguishable from the variable name. For instance, it might look something like this (a simple Visual Studio-esque example):

```auto

int i = 1
string s = "foo"
double x = 3.14

```

> [@](#):
>
> Agreed. What I gave was an artificial example with too many variables being initialized in the same spot, just to show that aligning them improves readability (in a basic text editor, like vi or emacs)

Understood, of course, I’d consider that bad style too. 😛

> [@](#):
>
> and, now, based on **Blaster Master** ’s example, I can add PASCAL, which I guess would look like
> 
> ```auto
> 
> if (bla) then 
> begin
> <statements>
> end
> else if (test) then
> begin
> <statements>
> end
> end
> 
> ```
> 
> and the list goes on and on.

Nitpicks: the last end would cause an error. In that sense, it is like C, such that if only a single statement follows the if, you don’t need the {}'s. Also, IIRC, there is no “else-if” equivalent, so you would’ve had to do nested ifs instead. And it’s a nitpick because…who uses PASCAL anymore?

> [@](#):
>
> Hey, jackass language developers, you are not adding anything to the programming paradigm by inventing your own little way of doing a simple if statement, or for that matter, a comment, or a for loop, and with all the different ways of saying ‘break’ and ‘continue’ in all the languages.

Mostly agreed here. It’s annoying when I’m constantly switching between languages, especially during certain semesters in Grad school when I had one class in C++ and Java, one in Matlab, one in Lisp, and another with random tools like Yakk, Prolog, etc. But at the same time, a certain syntax just may not make sense in another context (Lisp being an excellent example). And, of course, we’re stuck with the whims of the designers’ preferences… should the “begin” be explicit or implicit, etc.

---

<div class="post-metadata">

**Author:** ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)\
**Post date:** [December 13, 2007, 8:55pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/53 "2007-12-13T20:55:08Z")

</div>

[QUOTE=Polerius]

```auto

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;     

```

[/QUOTE]  
Is that a list of globals, or are they locally declared? If the latter, then I would recommend splitting the function up - it’s too long. 😃

My personal pet peeve is when I see something like this:

```auto

bool someFlag = false;

...

if(checkBoxIsChecked)
{
    someFlag = true;
}
else
{
    someFlag = false;
}

```

For cryin’ out loud - if you love your unnecessary conditional so much, why don’t you marry it?

LilShieste

---

<div class="post-metadata">

**Author:** ![Dead\_Badger](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@Dead\_Badger](https://boards.straightdope.com/u/Dead_Badger)\
**Post date:** [December 13, 2007, 9:08pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/54 "2007-12-13T21:08:59Z")

</div>

[QUOTE=Polerius]

```auto

-> g++ -o tst tst.cc
tst.cc: In function `int main()':
tst.cc:8: error: invalid conversion from `const int*' to `int*'

```

[/QUOTE]  
If you explicitly cast it however (int\* x = (int\*) &c;), it does exactly as **ultrafilter** describes. That is a weird one, all right.

---

<div class="post-metadata">

**Author:** ![squeegee](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/squeegee/32/14537_2.png) [@squeegee](https://boards.straightdope.com/u/squeegee)\
**Post date:** [December 13, 2007, 9:18pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/55 "2007-12-13T21:18:21Z")

</div>

A K&R brace style war? You’re kidding me. Can we debate the Brady Bunch next?

In any case, that if/else clause should be pounded down to:

```auto

foo = (blah) ? bar1 : bar2

```

Happy? Yeah, well I don’t care, either. Twatwaffles.

---

<div class="post-metadata">

**Author:** ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)\
**Post date:** [December 13, 2007, 9:26pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/56 "2007-12-13T21:26:06Z")

</div>

[QUOTE=wolfman]  
When I was a TA I constantly had a fight with my prof of Variable names, he would teach them “be as descriptive as possible in variable names, point will be taken off for nondescriptive names” with no further instruction, then I had to grade then damn things.

```auto

int[] arrayToStoreTheTemperatureIn;
int variableToStoreTheXAxisOfTheArray =0;
int variableToStoreTheYAxisOfTheArray =0;
int variableToStoreTheXAxisOfTheArray =0;

.....

```

[/QUOTE]

Wow, that’s pretty obnoxious. Also, Hungarian Notation sucks. 😛

LilShieste

---

<div class="post-metadata">

**Author:** ![Ludovic](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@Ludovic](https://boards.straightdope.com/u/Ludovic)\
**Post date:** [December 13, 2007, 9:54pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/57 "2007-12-13T21:54:28Z")

</div>

I use reverse hungarian notation. Especially useful when writing a bathroom application and you have a hand dryer subobject with an activation control called PushBut.

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [December 13, 2007, 10:01pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/58 "2007-12-13T22:01:02Z")

</div>

[QUOTE=squeegee]  
A K&R brace style war? You’re kidding me. Can we debate the Brady Bunch next?

In any case, that if/else clause should be pounded down to:

```auto

foo = (blah) ? bar1 : bar2

```

Happy? Yeah, well I don’t care, either. Twatwaffles.  
[/QUOTE]  
I’m guilty of using the ? operator even though I would probably forbid its use by anyone else.

I like to do this:

```auto

public void setJohnsonLength(Long value){
  _johnsonLength = (value == null) ? DEFAULT_JOHNSON_LENGTH : value;
}

```

It’s a short-and-sweet way to insulate from nulls (especially important in this example).

And about those braces… Go ahead and put them wherever you want. The automated build will slam them into shape with a sledgehammer and there’s nothing you can do about it :D.

---

<div class="post-metadata">

**Author:** ![squeegee](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/squeegee/32/14537_2.png) [@squeegee](https://boards.straightdope.com/u/squeegee)\
**Post date:** [December 13, 2007, 10:29pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/59 "2007-12-13T22:29:09Z")

</div>

[QUOTE=minor7flat5]  
I’m guilty of using the ? operator even though I would probably forbid its use by anyone else.  
[/quote]  
The ? operator is fine, as long as the three elements are variables or very brief. If “blah” is some long-ass function with multiple params, then a ? operator would be horrid.

Another concise way might be:

```auto

foo = bar1;
if(blah)
{
 foo = bar2
}

```

so you avoid the ‘else’ altogether.

---

<div class="post-metadata">

**Author:** ![Absolute](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Absolute](https://boards.straightdope.com/u/Absolute)\
**Post date:** [December 13, 2007, 10:50pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/60 "2007-12-13T22:50:19Z")

</div>

I am firmly in the

```auto

if (foo) {
   doSomething();
} else if (blah) {
   doOther();
} else {
   doNothing();
}

doMore();

```

camp. The braces just clutter up the code, so I don’t waste any space on them. I can tell what block something belongs to through indentation.

It drives me nuts when people put braces on a separate line - why are you wasting so much space?

[Previous page](https://boards.straightdope.com/t/programming-style-abominations/429810.md?page=2)

[Next page](https://boards.straightdope.com/t/programming-style-abominations/429810.md?page=4)
