| | |
Silly Code
![]() |
If you've never heard of the following inane code, do a search for "Rob Pike rules". (Or just do that anyway, it'll be good for you.)
Since that kinda thing is so well known, we don't actually see this kind of stuff in real life, right?
Don't laugh.
Um, okay. So that's like so someday you can change FIVE to have a value of 7?
What does it actually provide other than a maintenance headache?
Similarly, why would anyone programming in C want to do this?
Sure it makes the code look like C++ and it is a fairly common idiom. But why should it be? Why couldn't programmers back from the time of C's start not have told others simply to use zero or nonzero values and stop there.
Or is the point just to see if your code could withstand the rigors of doing this?
I would say less than one in a million programs that rigorously use
Hindsight is 20/20, but even with that, there's 99% of us programmers that will still get it wrong.
•
•
•
•
Originally Posted by Rob Pike
There is a famously bad comment style:
and there are worse ways to do it:i=i+1; /* Add one to i */
Don't laugh now, wait until you see it in real life./********************************** * * * Add one to i * * * **********************************/ i=i+1;
#define ZERO 0
enum { ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN };What does it actually provide other than a maintenance headache?
Similarly, why would anyone programming in C want to do this?
typedef enum { false, true } bool;Or is the point just to see if your code could withstand the rigors of doing this?
typedef enum { true, false } bool;true and false could actually withstand a reversal. And if that's the case, why waste the time throughout the code being so rigorous?Hindsight is 20/20, but even with that, there's 99% of us programmers that will still get it wrong.
0
#2 Sep 10th, 2006
Seen all that and more...
From a production system at a multinational:
From another production system at another multinational:
But sometimes a typedef can be a good thing.
For example some database engines don't have a concept of a boolean datatype, so you need to use something else to represent it.
In such cases it makes perfect sense to define in your database library something like
yet seen outside its context it would look utterly idiotic.
From a production system at a multinational:
double add(double a, double b) {
return a + b;
}From another production system at another multinational:
#define BEGIN {
#define END }
#define PROCEDURE void
#define FUNCTIONBut sometimes a typedef can be a good thing.
For example some database engines don't have a concept of a boolean datatype, so you need to use something else to represent it.
In such cases it makes perfect sense to define in your database library something like
public class DbBool {
private static final char TRUE = 'T';
private static final char FALSE = 'F';
private char value;
private DbBool(char value) { this.value = value; }
public char get() { return value; }
public static final DbBool true = new DbBool(TRUE);
public static final DbBool false = new DbBool(FALSE);
}yet seen outside its context it would look utterly idiotic.
0
#3 Sep 12th, 2006
i=i+1; /* Add one to i */
I had a boss once that knew nothing about programming but required comments like this on every line in the program so that he could understand the logic of the program! Boy am I glad I don't work for him any longer:cheesy:
![]() |
Similar Threads
- silly doubt (Java)
- Silly, but interesting (C#)
- silly (C)
- silly bug (C)
- Silly Laws (Geeks' Lounge)
Other Threads in the Upcoming News Stories Forum
- Previous Thread: Sending an email… business communication degree not required!
- Next Thread: Petaflop breaking, PS3 powered Roadrunner will be no toy
| Thread Tools | Search this Thread |
age amd analytics api apple avatar blog blogging bluegene bluray broadband browser business cellphones chips command computers console copyright database dell developer development dos economy email encryption energy enterprise facebook firefox games gaming google government gta hardware ibm ibm.news intel intelibm internet iphone ipod laptop leopard linux mac malware medicine memory microsoft mobile news nintendo obama office openoffice opensource os pc politics prompt ps3 recession redhat registry root russia search security semiconductors software sony statistics stockmarket stocks sun supercomputer supercomputing technology technologystocks tiger trends tweaks twitter ubuntu unix verizon virus vista web webmail wii windows wireless working x86 xbox yahoo






