•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Software Development category of DaniWeb, a massive community of 397,691 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,550 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Software Development advertiser:
Sep 9th, 2006, 7:17 pm
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.
This blog entry was written by Dave Sinkula. It has received 1,499 views, 2 comments, and 6 linkbacks. 1 voter has rated this entry 5 out of 5 stars.
Comments (Newest First)
Ancient Dragon | Most Valuable Poster | 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:
jwenting | duckman | 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.
Post Comment
•
•
•
•
Only community members can start a blog or comment on blog entries. You must register or log in to contribute.
•
•
•
•
•
•
•
•
DaniWeb Software Development Marketplace
Related Blog Entries
- Parlez-vous le Linux? (11 Hours Ago)
- Here's Your Chance to Hack Into openSUSE Linux (3 Days Ago)
- Four letters, 8 points, describes Scrabulous (3 Days Ago)
- How many developers does it take to build Windows 7? (9 Days Ago)
- USB 3.0 Draft Spec Published (15 Days Ago)
- Open Source licenses get copyright law protection (15 Days Ago)
- Court Equates Contract Breach with Copyright Infringement (15 Days Ago)
- Miyuki Suzuki's TeQ Blog - What is SOA really? (17 Days Ago)
- iPhone gets GIPS real-time VoIP for gamers (18 Days Ago)
- LinuxWorld Caters to Developers (22 Days Ago)
Related Forum Threads
- i++ and ++i (C)
- Lisp question (Legacy and Other Languages)
- Bold (HTML and CSS)
- code tags (DaniWeb Community Feedback)
- Your favorite clean joke (Geeks' Lounge)
- Using VB to select a different sheet in Excel (Visual Basic 4 / 5 / 6)
- "object , object" concatination? (Python)
- Randomize number with OpenGL (C++)
- Real number to binary? (C)