# 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:** 4

<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, 11:06pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/61 "2007-12-13T23:06:32Z")

</div>

What, they charge for white space where you come from?

Do you also think parens and semicolons slow down program execution?

---

<div class="post-metadata">

**Author:** ![Ximenean](https://avatars.discourse-cdn.com/v4/letter/x/aca169/32.png) [@Ximenean](https://boards.straightdope.com/u/Ximenean)\
**Post date:** [December 13, 2007, 11:08pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/62 "2007-12-13T23:08:51Z")

</div>

They charge more for bigger screens, yes.

---

<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, 11:24pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/63 "2007-12-13T23:24:55Z")

</div>

[QUOTE=squeegee]  
What, they charge for white space where you come from?

Do you also think parens and semicolons slow down program execution?  
[/QUOTE]

I like being able to see a lot of code on my screen at once. The more useless whitespace there is, the less actually meaningful code I can see. This is especially important on my laptop.

I am all for using whitespace for readability - but I don’t see how separating the method declaration / if condition / whatever from the actual code by one line makes it any more readable. To me, a blank line between two lines means that the two lines are somehow separated in purpose.

Another pet peeve of mine - people who insist on truncating their code to an 80-character line width. We’ve all got widescreen displays these days - use them! 120 characters gives you a lot more freedom, especially if your variable names are as descriptive as they should be.

---

<div class="post-metadata">

**Author:** ![Algorithm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/algorithm/32/12204_2.png) [@Algorithm](https://boards.straightdope.com/u/Algorithm)\
**Post date:** [December 13, 2007, 11:26pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/64 "2007-12-13T23:26:45Z")

</div>

[QUOTE=Absolute]

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

So other people can read the code. You put braces on the next line for the same reason you don’t nest multi-line ?: operators. Just because something works and _you_ can read it doesn’t mean it’s stylisticly superior. It gives me a headache when people code as if whitespace is some scarce resource to be used as sparingly as possible.

It’s the same as reading some jackass’s resume in email styled in 6 point font and no margins at all so that if I happen to print it, it will all fit on one page. I don’t want to read that shit, and I certainly don’t want to edit it.

**minor7flat5** , I introduce you to the .NET [?? operator](http://msdn2.microsoft.com/en-us/library/ms173224.aspx)

---

<div class="post-metadata">

**Author:** ![pulykamell](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/pulykamell/32/3166_2.png) [@pulykamell](https://boards.straightdope.com/u/pulykamell)\
**Post date:** [December 13, 2007, 11:50pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/65 "2007-12-13T23:50:17Z")

</div>

[QUOTE=LilShieste]  
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  
[/QUOTE]

I’m not really a programmer, but what if you check and then uncheck the box? When you check it, someFlag is set to true. When you uncheck it, you’d need the else statement to change it to false, wouldn’t you? Or would you reset the flag elsewhere?

---

<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 14, 2007, 12:09am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/66 "2007-12-14T00:09:01Z")

</div>

[QUOTE=Algorithm]  
for the same reason you don’t nest multi-line ?: operators.  
[/QUOTE]  
Ooh, yeah. I knew a guy who’d do something like this:

```auto

foofunc(abc, def, qrx, tuv) ? 
    (foofunc2(yada, ya, ya, yada) ? 
        someparam : 
        otherparam) : 
    bar;

```

---

<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 14, 2007, 12:09am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/67 "2007-12-14T00:09:39Z")

</div>

[QUOTE=pulykamell]  
I’m not really a programmer, but what if you check and then uncheck the box? When you check it, someFlag is set to true. When you uncheck it, you’d need the else statement to change it to false, wouldn’t you? Or would you reset the flag elsewhere?  
[/QUOTE]

That’s a good question - and the reason why this situation comes up more often than one might expect. The conditional provided in the example could easily be replaced with:

```auto

someFlag = checkBoxIsChecked;

```

When the checkbox is checked, someFlag will contain “true”. When the checkbox is not checked, someFlag will contain “false”.

LilShieste

---

<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 14, 2007, 12:11am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/68 "2007-12-14T00:11:06Z")

</div>

[QUOTE=squeegee]  
Ooh, yeah. I knew a guy who’d do something like this:

```auto

foofunc(abc, def, qrx, tuv) ? 
    (foofunc2(yada, ya, ya, yada) ? 
        someparam : 
        otherparam) : 
    bar;

```

[/QUOTE]

I think my eyes just threw up, a little bit.

LilShieste

---

<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 14, 2007, 12:16am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/69 "2007-12-14T00:16:42Z")

</div>

[QUOTE=LilShieste]  
I think my eyes just threw up, a little bit.  
[/QUOTE]  
Preach it. I’d actually edited for clarity. A real example would have been on one (120 char) line.

---

<div class="post-metadata">

**Author:** ![Indistinguishable](https://avatars.discourse-cdn.com/v4/letter/i/90ced4/32.png) [@Indistinguishable](https://boards.straightdope.com/u/Indistinguishable)\
**Post date:** [December 14, 2007, 12:24am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/70 "2007-12-14T00:24:58Z")

</div>

[QUOTE=Derleth]  
[li] **Fuck Scheme for breaking car and cdr** : I don’t care about the Lisp-1 v. Lisp-2 debate. I like Lisp-2s because I like to define my own names, but Lisp-1s are how non-Lispers think. However, there was no reason for Scheme to make car and cdr fail on the empty list. _None._ It is neither an aesthetic improvement nor a result of something else. Steele knew better. He had to: He implemented Scheme and predecessors in real Lisps.[/li][/QUOTE]

This is a very piddling matter, but let me just say, _I_ find it an aesthetic improvement. car and cdr should be the least defined operators whose product is a right inverse to cons. There’s no clean reason for them to be applied to anything other than a cons cell, and if the type system isn’t strong enough to prevent them from being so applied anyway, then they need to at least man up and produce an error. Silently producing some arbitrary value just for the sake of misguided “convenience” is nothing more than a failcess.

---

<div class="post-metadata">

**Author:** ![DudleyGarrett](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@DudleyGarrett](https://boards.straightdope.com/u/DudleyGarrett)\
**Post date:** [December 14, 2007, 12:39am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/71 "2007-12-14T00:39:57Z")

</div>

All these posts and no one mentioned the extra spaces after and before parentheses?

```auto

if ( condition )
{
        Bool( string ) = true;
}
else
{
       Method( Int32 ) = String( Bool );
       Bool( string ) = false;
}

```

Seeing hundreds of lines of code like this drives me batty.

Also, excessive commenting. I’ve seen code where, for every line of code, there were 5 lines of comments.

---

<div class="post-metadata">

**Author:** ![Indistinguishable](https://avatars.discourse-cdn.com/v4/letter/i/90ced4/32.png) [@Indistinguishable](https://boards.straightdope.com/u/Indistinguishable)\
**Post date:** [December 14, 2007, 12:49am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/72 "2007-12-14T00:49:59Z")

</div>

[QUOTE=Indistinguishable]  
car and cdr should be the least defined operators whose product is a **right inverse** to cons.  
[/QUOTE]

Sorry, I meant “left inverse”, of course.

---

<div class="post-metadata">

**Author:** ![Liberal](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@Liberal](https://boards.straightdope.com/u/Liberal)\
**Post date:** [December 14, 2007, 12:57am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/73 "2007-12-14T00:57:27Z")

</div>

[QUOTE=Indistinguishable]  
Sorry, I meant “left inverse”, of course.  
[/QUOTE]  
Well, then. See that you keep your wits about you in the future. 😉

---

<div class="post-metadata">

**Author:** ![pulykamell](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/pulykamell/32/3166_2.png) [@pulykamell](https://boards.straightdope.com/u/pulykamell)\
**Post date:** [December 14, 2007, 1:06am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/74 "2007-12-14T01:06:47Z")

</div>

[QUOTE=LilShieste]

When the checkbox is checked, someFlag will contain “true”. When the checkbox is not checked, someFlag will contain “false”.

[/QUOTE]

:smack:

That’s pretty obvious now that you point it out.

---

<div class="post-metadata">

**Author:** ![Taran](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@Taran](https://boards.straightdope.com/u/Taran)\
**Post date:** [December 14, 2007, 2:17am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/75 "2007-12-14T02:17:58Z")

</div>

At our C++ shop, I have a boss who hates and fears templates. We put up with it until one day we found this in our repository:

```auto

#define DEFINE_BITVECTOR(type) struct type#_set \
  /* ... implementation of a type-generic bit-vector elided ... */
}

DEFINE_BITVECTOR(uchar);
DEFINE_BITVECTOR(ushort);

```

We all got together and held an intervention after that.

While I’m here, fuck the C++ standards committee with a walrus for inventing the export keyword without any idea of how to implement it. Now we’re boned: Comeau actually supports the damn thing so we can’t get rid of it, but Microsoft and the Gnu people say they _never_ will. The one bright spot is that we’ve got a new version of the standard coming up, so if we’re lucky they’ll find some way to…accept a whole swarm of new, unimplemented language features. _Awesome_.

---

<div class="post-metadata">

**Author:** ![Taran](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@Taran](https://boards.straightdope.com/u/Taran)\
**Post date:** [December 14, 2007, 2:22am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/76 "2007-12-14T02:22:17Z")

</div>

And oh yes, my favorite brace style in brace-y languages is

```auto

if(foo) {
  Bar()
}

```

…after the Ruby style:

```auto

if foo
  Bar()
end

# Although, technically, the idiomatic Ruby for that is:
Bar() if foo

```

Blah blah blah, saves-vertical-space-associates-the-branches-of-the-block-with-the-branching-condition-cakes.

---

<div class="post-metadata">

**Author:** ![Rysto](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@Rysto](https://boards.straightdope.com/u/Rysto)\
**Post date:** [December 14, 2007, 6:02am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/77 "2007-12-14T06:02:46Z")

</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]

gcc will print it out, too, even without optimization enabled. It happens because the C++ standard allows compilers to do constant value propagation on variables declared const.

---

<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 14, 2007, 8:10am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/78 "2007-12-14T08:10:55Z")

</div>

[QUOTE=Rysto]  
gcc will print it out, too, even without optimization enabled. It happens because the C++ standard allows compilers to do constant value propagation on variables declared const.  
[/QUOTE]  
My guru friend tells me the following, which I think agrees with you:

> [@](#):
>
> yep, that [behaviour] is fine. When you cast away constness and attempt to modify the underlying thingamyjig the operation is deemed to be undefined. your error is in the line:
> 
> \*x = 5;
> 
> after doing, int\* x = (int\*) &c;  
> which btw, should really be: int\* x = const\_cast\<int\*\>(&c);

Which makes sense, really; the code attempts to do something self-contradictory (modify a const), and the compiler complains. If you cast away the error message and proceed anyway, the results are going to be confusing in some way, through no fault of the language or compiler. While the exhibited behaviour is certainly weird, it’s hard to see any other behaviour being much more intuitive. You either do what the compiler did, end up discarding data, or have const variables changing. None of the options is ideal.

And yes, “thingamyjig” is a technical term. 😛

---

<div class="post-metadata">

**Author:** ![MrSquishy](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@MrSquishy](https://boards.straightdope.com/u/MrSquishy)\
**Post date:** [December 14, 2007, 5:28pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/79 "2007-12-14T17:28:20Z")

</div>

I assume all of you have already seen [this](http://www.web-hits.org/txt/codingunmaintainable.html)?

Program for job security!

---

<div class="post-metadata">

**Author:** ![MrSquishy](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@MrSquishy](https://boards.straightdope.com/u/MrSquishy)\
**Post date:** [December 14, 2007, 5:45pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/80 "2007-12-14T17:45:29Z")

</div>

I especially like this one:

> [@](#):
>
> When To Use Exceptions  
> : Use exceptions for non-exceptional conditions. Routinely terminate loops with an ArrayIndexOutOfBoundsException. Return standard results from a method in an exception.

😃

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

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