User Name Password Register
DaniWeb IT Discussion Community
All
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.)
Originally Posted by Rob Pike
There is a famously bad comment style:
i=i+1;        /* Add one to i */
and there are worse ways to do it:
/**********************************
 *                                *
 *          Add one to i          *
 *                                *
 **********************************/

               i=i+1;
Don't laugh now, wait until you see it in real life.
Since that kinda thing is so well known, we don't actually see this kind of stuff in real life, right?
#define ZERO 0
Don't laugh.
enum { ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN };
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?
typedef enum { false, true } bool;
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?
typedef enum { true, false } bool;
I would say less than one in a million programs that rigorously use 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.

Tags: c

AddThis Social Bookmark Button

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:
double add(double a, double b) {
    return a + b;
}

From another production system at another multinational:
#define BEGIN {
#define END }
#define PROCEDURE void
#define FUNCTION

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
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
Related Forum Threads
All times are GMT -4. The time now is 1:07 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC