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

<div class="post-metadata">

**Author:** ![robardin](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@robardin](https://boards.straightdope.com/u/robardin)\
**Post date:** [December 14, 2007, 6:50pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/81 "2007-12-14T18:50:37Z")

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

Huh. I tried it with g++ after casting &c to (int\*) from (const int\*) and yes, it printed out.

BUT, if I “properly” change the declaration of c to “int c = 3;” instead of const int, it doesn’t.

I’m guessing that when you declare a const value of a native type, the compiler (or rather, the linker) must be at liberty to optimize it to the equivalent magic value.

For example, this code does NOT print out:

```auto

#include <stdio.h>

class Int
{
  public:
    Int(int i) : _i(i) {}
    int get_int() const { return _i; }
    void set_int(int i) { _i = i; }

  private:
    int _i;
};
int main()
{
    const Int c(3);
    Int *x = (Int*) &c;

    x->set_int(5);

    if ((&c == x) && (x->get_int() != c.get_int()))
	printf("Everything you know is wrong!
");
}

```

---

<div class="post-metadata">

**Author:** ![robardin](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@robardin](https://boards.straightdope.com/u/robardin)\
**Post date:** [December 14, 2007, 7:04pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/82 "2007-12-14T19:04:19Z")

</div>

Oh, and as an artifact of my training (first C out of K&R, then C++ out of Stroustrup), I use the older notational convention for pointers and the newer one for references. I guess I get my own Pit thread as far as the OP’er goes.

```auto

int i = 0;
int *ptr = &i;
const int& ref = i;

```

Far more annoying than notational vagaries are stupid comments. It’s just not true that having uncommented code is the worst sin as far as maintainability goes. It’s worse to have wrong and outdated comments that _do not apply_ to the code it annotates – either the code changed and the comments didn’t, or whoever wrote the code and comments were different people, or confused or plain evil.

Though completely out of reference comments can be a source of humor. Like the following more-or-less real life examples I have seen:

```auto

[something innocent looking] // no. 

or
#include <somelib/include_file.H> // do not move this line
(which, I will add, lived up to its warning)

or
[blah blah blah] // added today

```

---

<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, 7:55pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/83 "2007-12-14T19:55:27Z")

</div>

[QUOTE=robardin]

```auto

[blah blah blah] // added today

```

[/QUOTE]

That is absolutely beautiful.

---

<div class="post-metadata">

**Author:** ![dropzone](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dropzone/32/7515_2.png) [@dropzone](https://boards.straightdope.com/u/dropzone)\
**Post date:** [December 14, 2007, 8:20pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/84 "2007-12-14T20:20:15Z")

</div>

[QUOTE=Bryan Ekers]  
Buncha pussies, you are. In my day, we wrote:

```auto

10 If x=5 then goto 20
20 if x<5 then goto 10 else goto 30
30 goto 10

```

…and we were fucking _glad_ for the privilege!  
[/QUOTE]  
You had an ELSE statement? And you call OTHER people pussies?

```auto

10 IF X=5 THEN GOTO 40
20 IF X<5 THEN GOTO 50
30 IF X>5 THEN GOTO 60
40 PRINT "X=5"
45 GOTO 70
50 PRINT "X<5"
55 GOTO 70
60 PRINT "X>5"
65 GOTO 70
70 PRINT "The program continues."

```

---

<div class="post-metadata">

**Author:** ![robardin](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@robardin](https://boards.straightdope.com/u/robardin)\
**Post date:** [December 14, 2007, 8:44pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/85 "2007-12-14T20:44:45Z")

</div>

[QUOTE=dropzone]  
You had an ELSE statement? And you call OTHER people pussies?

[/QUOTE]

Your BASIC interpreter automatically showed you the program in order of the line numbers? Whoa, you had it sweet. The one _I_ learned on spat back the lines in the order they were received (even though, of course, the program was executed in line number order), which meant the really nerdy hackers at my school took great pleasure in floating code around like this:

```auto

100 END
999 PRINT "THINK I EVER GET HERE? HAHAHAHA"
001 LET X = 1
075 GOTO END
023 IF X < 100 GOTO 40
...

```

---

<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, 9:02pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/86 "2007-12-14T21:02:38Z")

</div>

[QUOTE=MrSquishy]  
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.

😃  
[/QUOTE]

Nice, I think I’ll add this to my list of interview questions. “What are the three ways a value can be returned from a function?” 🙂

LilShieste

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [December 14, 2007, 9:23pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/87 "2007-12-14T21:23:28Z")

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

You code this way and you’ll find you voted for Pat Buchanan for president, mark my words.

I agree with you about the braces, though.

I hate too short variable names, and the worst culprit I know of in that regard was the original Zurich Pascal compiler. Wirth’s data structure book has code examples with single letter names, and they coded like that. Maybe it was a reaction to too long German names? It took me months to figure out what everything meant when I was in grad school.

---

<div class="post-metadata">

**Author:** ![robardin](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@robardin](https://boards.straightdope.com/u/robardin)\
**Post date:** [December 14, 2007, 10:03pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/88 "2007-12-14T22:03:04Z")

</div>

Oh… Too-short variable names…

I have to deal with code that iterates over a doubly linked list structure. The nodes in this llist are called “instruments”.

One of the core routines iterates this doubly linked list with three pointers: c\_inst, p\_inst and n\_inst. The iteration begins with “c\_inst” being set to the front of the list.

Any sane person, I would venture to guess, would thereby assume that “c\_inst” was the current node, “p\_inst” the previous node, and “n\_inst” the next node in the iteration.

Think again. As it happens, this particular routine doesn’t ever look “backwards” in the iteration, but does need two forward-looking pointers, so “p\_inst” refers to the next node, and “n\_inst” to the one AFTER that.

What I think happened is that the writer of this code cut-and-paste the outer loop from some other, very similar and very core routine that sorts this doubly linked list using three pointers, where the declarations for c\_inst, p\_inst and n\_inst DO mean “current”, “prev” and “next”, and then just… reused them to mean different things.

Aaaaarrrrggh!

---

<div class="post-metadata">

**Author:** ![Superfluous\_Parentheses](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Superfluous\_Parentheses](https://boards.straightdope.com/u/Superfluous_Parentheses)\
**Post date:** [December 14, 2007, 11:12pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/89 "2007-12-14T23:12:45Z")

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

Hear hear! Javascript is a great language, but why it thinks it should look like Java I have no idea. new Constructor(); in a prototype based language? What the fuck where they drinking?

And Microsoft just can’t write a Gui APIs and I’d really like them to stop trying and use someone else’s please.

---

<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 15, 2007, 1:50am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/90 "2007-12-15T01:50:57Z")

</div>

> [@](#):
>
> And Microsoft just can’t write a Gui APIs and I’d really like them to stop trying and use someone else’s please.

Nonsense. I think Windows messages were an inspired design, especially for its time. You could subclass, superclass and generally take advantage of built-in window widgets and change their behavior to suit what you needed. Want an edit box that only takes numeric input? Superclass the edit control, intercept WM\_CHAR and friends, and you got what you want in no time, in a perfectly encapsulated way. Then you just do a CreateWindow(myNumericEditClass, blah,blah) and use it anywhere. So it’s not C++ or objecty enough? Well, use WTL or similar. Jeez, the design is from 1989 fer chrissakes. Oh, And Apple was apparently impressed enough to rip it all off for Carbon Events much later.

If you want to talk about GDI on the other hand, I don’t really think there’s any defense.

And if you want to talk about how the API is organized and documented, well, it sucks.

Twatwaffles. (I love that word)

---

<div class="post-metadata">

**Author:** ![Tim\_T-Bonham.net](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@Tim\_T-Bonham.net](https://boards.straightdope.com/u/Tim_T-Bonham.net)\
**Post date:** [December 15, 2007, 2:55am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/91 "2007-12-15T02:55:08Z")

</div>

[QUOTE=DeadlyAccurate]  
I can’t comprehend variable names like that, either. Who names variables something so incomprehensible?  
[/QUOTE]  
A consulting company, which is trying to get the maintenance contract for that system.

Somewhere back at their office, they have a version of the code with _real, meaningful_ variable names used. I once worked on such a system, developed by a very small consulting company, where the source actually left enough space for the real variable names, but only showed the short ones. For example:

```auto

IF A1 = "MN"

```

when study of the code showed that the real version was

```auto

IF STATE-CODE = "MN"

```

Real obvious what they had done. And a rather sneaky way to try to guarantee that they would get the maintenance contract. But not uncommon.

---

<div class="post-metadata">

**Author:** ![Tim\_T-Bonham.net](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@Tim\_T-Bonham.net](https://boards.straightdope.com/u/Tim_T-Bonham.net)\
**Post date:** [December 15, 2007, 3:02am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/92 "2007-12-15T03:02:42Z")

</div>

[QUOTE=Liberal]  
There was a time when memory and storage was such a precious resource that every possible tweak would be done to expurgate any and all unnecessary tokens. That meant things like two-digit years and brief abstract variable names.  
[/QUOTE]  
No, that’s not very likely.

This was in COBOL. So the variable names were only used by the compiler, not by the actual generated code. A name like WS-PAYROLL-EMPLOYEE-LAST-NAME or one like WS-A produce the same object code. The only place it might make a difference is in the compiler stack, and even back in the days of COBOL E and F there was plenty of room for long names.

---

<div class="post-metadata">

**Author:** ![Orbifold](https://avatars.discourse-cdn.com/v4/letter/o/779978/32.png) [@Orbifold](https://boards.straightdope.com/u/Orbifold)\
**Post date:** [December 15, 2007, 3:33am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/93 "2007-12-15T03:33:11Z")

</div>

I once had to try and understand a Fortran-77 program written by a mathematician who clearly had no training as a programmer. Goto’s everywhere, no indenting at all, never a three-letter variable name when a two-letter one would do, no comments, and oh sweet Og the input format. Do you know how you input a line of text from standard input in Fortran-77? Why, like this:

```auto

 50 READ 60

```

What’s ‘60’, you ask? Why that’s the line where the input format is specified. What’s to stop someone from writing " 50 READ 1008", putting the input format miles away from where it’s actually used, you ask? Not a damned thing.

Oh, and somehow before the program got to me an extra space had been added to the beginning of each line of the program. This, of course, causes Fortran-77 to not compile. I had to go to a dusty corner of the engineering library on the other side of campus to find a book that explained this to me.

And you’re complaining about whether there’s an line return before the brace? Wimps.

---

<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 15, 2007, 9:14am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/94 "2007-12-15T09:14:35Z")

</div>

[QUOTE=t-bonham@scc.net]  
No, that’s not very likely.

This was in COBOL. So the variable names were only used by the compiler, not by the actual generated code. A name like WS-PAYROLL-EMPLOYEE-LAST-NAME or one like WS-A produce the same object code. The only place it might make a difference is in the compiler stack, and even back in the days of COBOL E and F there was plenty of room for long names.  
[/QUOTE]  
It made a difference in being _stored_ for the program text itself. (Thus, my reference to storage space.)

---

<div class="post-metadata">

**Author:** ![Manduck](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/manduck/32/256_2.png) [@Manduck](https://boards.straightdope.com/u/Manduck)\
**Post date:** [December 15, 2007, 10:26am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/95 "2007-12-15T10:26:22Z")

</div>

FORTRAN had a rule that a variable name couldn’t be more than 6 (I think) characters long, and the first character indicated the data type (IIRC, I through N were for integers, the rest were reals. There were no other types). It pretty much forced you to use obscure abbreviated variable names.

---

<div class="post-metadata">

**Author:** ![Tim\_T-Bonham.net](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@Tim\_T-Bonham.net](https://boards.straightdope.com/u/Tim_T-Bonham.net)\
**Post date:** [December 15, 2007, 10:58am UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/96 "2007-12-15T10:58:05Z")

</div>

[QUOTE=Liberal]  
It made a difference in being _stored_ for the program text itself. (Thus, my reference to storage space.)  
[/QUOTE]  
What I remember from that time, the program text wasn’t stored anywhere – except on a deck of punched cards. Online DASD was far too precious to use it for things like program source. It was a few years later, when DASD space was bigger & cheaper, that we got source management packages like Panvalet and Librarian.

Though there were a few programmers around who used very abbreviated data names, because they were poor typers (keypunchers, really). But generally, you wrote your program on coding pads, and turned it in for an expert keypunch girl to punch for you, so data name length didn’t really matter.

---

<div class="post-metadata">

**Author:** ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)\
**Post date:** [December 15, 2007, 12:32pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/97 "2007-12-15T12:32:24Z")

</div>

Oh, here we go:

**fuck try catches**

try catch is a retarded jizz stain of a syntax, spilling itself into every tiny crevasse and generally obscuring your view of what’s important.

```auto

openA();
openB();
openC();
closeC();
closeB();
closeA();

```

becomes

```auto

try
{
	openA();
	try
	{
		openB();
		try
		{
			openC();
			closeC();
		}
		catch(Exception e)
		{
			closeB();
			error();
		}
	}
	catch(Exception e)
	{
		closeA();
		error();
	}
}
catch(Exception e)
{
	error();
}

```

**fuck the “goto considered harmful” chuckleheads**

If you can rewrite this block to not include goto and not make it a horrible monstrosity, be my guest:

```auto

for(int i = 0; i < 100; i++)
{
	for(int j = 0; j < 100; j++)
	{
		for(int k = 0; k < 100; k++)
		{
			if (found(i,j,k))
			{
				doSomethingComplicated(a, b, c, d, e, f, g);
				goto FOUND;
			}
		}
	}
	FOUND:
}

```

Gotos should be avoided whenever possible but it is possible to use them judiciously.

finally, **fuck all language designers for not letting me hide error checking code**

I would say somewhere between 30% and 80% of the code generally gets taken up making sure nothing goes wrong in a good system. When I’m trying to figure something all, all that cruft is just obscuring the the main logic of the code. I want a simple language spec and a simple IDE where I can toggle between the “full” view of the code and one showing only the main path. All the brace conventions in the world isn’t going to amount to a hill of beans if all you can see is a bunch of error code you don’t care about.

---

<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 15, 2007, 2:19pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/98 "2007-12-15T14:19:51Z")

</div>

[QUOTE=t-bonham@scc.net]  
What I remember from that time, the program text wasn’t stored anywhere – except on a deck of punched cards. Online DASD was far too precious to use it for things like program source. It was a few years later, when DASD space was bigger & cheaper, that we got source management packages like Panvalet and Librarian.

Though there were a few programmers around who used very abbreviated data names, because they were poor typers (keypunchers, really). But generally, you wrote your program on coding pads, and turned it in for an expert keypunch girl to punch for you, so data name length didn’t really matter.  
[/QUOTE]  
Ah. You must predate me slightly. We had punched cards, but for initial input only. It was with great pride and wonderment that we retrieved our small ribbon of magnetic tape. In the future, we dared believe, reels would be four feet wide.

---

<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 15, 2007, 2:22pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/99 "2007-12-15T14:22:09Z")

</div>

[QUOTE=Shalmanese]  
If you can rewrite this block to not include goto and not make it a horrible monstrosity, be my guest:

```auto

for(int i = 0; i < 100; i++)
{
	for(int j = 0; j < 100; j++)
	{
		for(int k = 0; k < 100; k++)
		{
			if (found(i,j,k))
			{
				doSomethingComplicated(a, b, c, d, e, f, g);
				goto FOUND;
			}
		}
	}
	FOUND:
}

```

Gotos should be avoided whenever possible but it is possible to use them judiciously.  
[/QUOTE]  
I’m not really a c guy, but can’t you just write a function that returns found?

---

<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 15, 2007, 5:18pm UTC](https://boards.straightdope.com/t/programming-style-abominations/429810/100 "2007-12-15T17:18:35Z")

</div>

> [@](#):
>
> If you can rewrite this block to not include goto and not make it a horrible monstrosity, be my guest:
> 
> ```auto
> 
> for(int i = 0; i < 100; i++)
> {
> for(int j = 0; j < 100; j++)
> {
> for(int k = 0; k < 100; k++)
> {
> if (found(i,j,k))
> {
> doSomethingComplicated(a, b, c, d, e, f, g);
> goto FOUND;
> }
> }
> }
> FOUND:
> }
> 
> ```

```auto

bool foundIt = false;
for(int i = 0; i < 100 && !foundIt; i++)
{
	for(int j = 0; j < 100 && !foundIt; j++)
	{
		for(int k = 0; k < 100 && !foundIt; k++)
		{
			if (found(i,j,k))
			{
				doSomethingComplicated(a, b, c, d, e, f, g);
                                foundIt = true;
			}
		}
	}
}

```

I couldn’t tell if you really wanted the outermost loop to proceed it your test condition was hit. If that’s the case, then it becomes:

```auto

for(int i = 0; i < 100; i++)
{
        bool foundIt = false;
	for(int j = 0; j < 100 && !foundIt; j++)
	{
		for(int k = 0; k < 100 && !foundIt; k++)
		{
			if (found(i,j,k))
			{
				doSomethingComplicated(a, b, c, d, e, f, g);
                                foundIt = true;
			}
		}
	}
}

```

Was that really so difficult?

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

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