Click here to Skip to main content
16,010,876 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
JokeRe: To me this is a coding horror, and to you? Pin
leonej_dt25-Sep-08 9:12
leonej_dt25-Sep-08 9:12 
GeneralRe: To me this is a coding horror, and to you? Pin
cpkilekofp25-Sep-08 9:37
cpkilekofp25-Sep-08 9:37 
GeneralRe: To me this is a coding horror, and to you? Pin
leonej_dt25-Sep-08 9:41
leonej_dt25-Sep-08 9:41 
GeneralRe: To me this is a coding horror, and to you? Pin
cpkilekofp25-Sep-08 10:16
cpkilekofp25-Sep-08 10:16 
JokeRe: To me this is a coding horror, and to you? Pin
leonej_dt25-Sep-08 10:19
leonej_dt25-Sep-08 10:19 
GeneralRe: To me this is a coding horror, and to you? Pin
cpkilekofp25-Sep-08 10:25
cpkilekofp25-Sep-08 10:25 
GeneralRe: To me this is a coding horror, and to you? Pin
leonej_dt25-Sep-08 10:56
leonej_dt25-Sep-08 10:56 
GeneralRe: To me this is a coding horror, and to you? Pin
cpkilekofp29-Sep-08 4:03
cpkilekofp29-Sep-08 4:03 
leonej_dt wrote:
When I program (I don't know about other people), my priorities are, in decreasing order:

1. the program has to be as fast as possible
2. the compiled executable has to be as small as possible
3. the source code has to be as small as possible


Nice, as long as no one will ever have to change your code again. Naturally, you forgot the fourth rule, which distinguishes the professional from the cowboy:

4. The code must be readable by someone with no more than six months of experience.
5. The code must be modifiable and extendable without a major rewrite.

You see, there's no guarantee that the next person to maintain your code is as sharp on all the nuances of code as you are; in fact, in any group setting, first cuts are often written by senior programmers, while modifications are often written by juniors. And, in fact, your own observation qualities fall short: this is a C# example, not a C example.

I was an expert in C programming for the first half of my career, to the point that I had the names of the standard headers and most of their standard declarations memorized. I used this trick and many others unique to C-like languages. It is, however, a cowboy trick, and if I found it in a review of your C# code, you'd be fixing it the next day. Tricks like this were often necessary in C because C didn't support booleans, but it's unnecessary in C#.

leonej_dt wrote:
Any sufficiently good C programmer knows what the double negation does. But, if you can't quite get it, you can define a macro

#define IS_NOT_ZERO(a) !!(a)


Again, this is a C# example, and C# does not have macro capabilities, any more than it has pointers.

Now, in some environments the skill level required is so high, and will remain so high, that you can write everything in obscure C with no indentation and the next programmer will be able to read it at a glance. Making your employer depend on this level of skill when they don't have to is a disservice to your employer.
GeneralRe: To me this is a coding horror, and to you? Pin
leonej_dt29-Sep-08 17:49
leonej_dt29-Sep-08 17:49 
GeneralRe: To me this is a coding horror, and to you? Pin
cpkilekofp30-Sep-08 7:00
cpkilekofp30-Sep-08 7:00 
GeneralRe: To me this is a coding horror, and to you? Pin
leonej_dt1-Oct-08 15:18
leonej_dt1-Oct-08 15:18 
GeneralRe: To me this is a coding horror, and to you? Pin
cpkilekofp2-Oct-08 5:49
cpkilekofp2-Oct-08 5:49 
GeneralRe: To me this is a coding horror, and to you? Pin
cpkilekofp2-Oct-08 7:03
cpkilekofp2-Oct-08 7:03 
GeneralRe: To me this is a coding horror, and to you? Pin
geoffs2-Oct-08 10:34
geoffs2-Oct-08 10:34 
GeneralRe: To me this is a coding horror, and to you? Pin
David St. Hilaire24-Sep-08 14:01
David St. Hilaire24-Sep-08 14:01 
GeneralRe: To me this is a coding horror, and to you? Pin
cpkilekofp25-Sep-08 3:49
cpkilekofp25-Sep-08 3:49 
GeneralSomeone please help me .... PinPopular
Monty211-Sep-08 18:27
Monty211-Sep-08 18:27 
GeneralRe: Someone please help me .... Pin
StM0n11-Sep-08 23:45
StM0n11-Sep-08 23:45 
JokeRe: Someone please help me .... Pin
BadKarma11-Sep-08 23:58
BadKarma11-Sep-08 23:58 
GeneralRe: Someone please help me .... Pin
dojohansen16-Sep-08 2:22
dojohansen16-Sep-08 2:22 
GeneralRe: Someone please help me .... Pin
cpkilekofp25-Sep-08 3:58
cpkilekofp25-Sep-08 3:58 
GeneralRe: Someone please help me .... Pin
Nagy Vilmos12-Sep-08 2:26
professionalNagy Vilmos12-Sep-08 2:26 
JokeRe: Someone please help me .... Pin
Chris Meech12-Sep-08 2:39
Chris Meech12-Sep-08 2:39 
JokeRe: Someone please help me .... Pin
CPallini12-Sep-08 3:35
mveCPallini12-Sep-08 3:35 
GeneralRe: Someone please help me .... Pin
dojohansen16-Sep-08 2:24
dojohansen16-Sep-08 2:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.