views:

1543

answers:

27
+25  Q: 

Weird constants

I've seen these in real code:

#define SCREEN_DIMENSIONS 2
#define THREE_THOUSAND_FIVE_HUNDRED_TWENTY_TWO 3522

What is the weirdest constant you've ever seen?

P.S. And of course my favorite in JScript:

bool b;
switch (b.ToString().length) {
case 4: // true
  ...
  break;
case 5:  // false
  ...
  break;
)
+20  A: 
#define private public
Johannes Weiß
In some C++ unit tests maybe?
Anonymous
+1 as i've seen this one before myself (and it was not in unit tests but in a "fix" for production code)
andyp
This is my trick to access private members/methods. Some class designers just underdesign.
Vardhan Varma
+19  A: 
#define TEN 9
David Morton
is that from someone with a problem with zero-index arrays?
annakata
I could make a case for this...but I only have 229 characters to do so.
gbarry
oh god, this one is awesome
Eric
there was a constant before this line. can anyone guess what it was?!
Matt Joslin
+11  A: 
#define TRUE 0
#define FALSE 1
Matthew Crumley
I've seen that one before too - what are these people thinking
MrTelly
Obligatory: #define FILE_NOT_FOUND 2
Outlaw Programmer
This actually makes sense in C, as there was no boolean data type prior to C99. Most C functions return 0 if everything worked or non-zero if there was an error.
Randolpho
@Outlaw Programmer: WTF? :p
Randolpho
@Randolpho: http://thedailywtf.com/Articles/What_Is_Truth_0x3f_.aspx
Adam Rosenfield
yeah this often called // happy debuggin mother****s!
Sergii
Randolpho, C conditions treat 0 as false and everything else as true. This is a recipe for problems, such as if somebody writes "while(TRUE)".
David Thornley
@Outlaw Programmer... I'm so proud!
Mark Harrison
This might have been someone working with POSIX-style return codes... but even then, there's no single `false` value.
Porges
I think in most of C world, when functions return 0, it's considered a success. You have always return -1, and set errno, but think of the code which will actually set errno .. (hint: the drivers of OS ).
Vardhan Varma
+9  A: 

Not the same, but I worked on a code base where the variables and labels where named after streets and pubs in Glasgow. So you could write code like

Goto :TheBowserBar

The code layout only made sense if you knew the city really well - strange.

MrTelly
+19  A: 
char *myGodItsFullOfStars = "********************************************************************************";
Dour High Arch
Dave... Dave.... What are you doing Dave? Dave?Priceless.
David Morton
My mind is going. I can feel it.
Randolpho
Daaaaaiiiissyyyyyy...
gnovice
+33  A: 

The Android's accelerometer API has gravitational constants for different planets.

http://code.google.com/android/reference/android/hardware/SensorManager.html

eduffy
I like GRAVITY_DEATH_STAR_I :D
Rob Prouse
I seem to remember this thread on Reddit... wasn't there a Roasanne Barr joke in there, somewhere?
Randolpho
They need GRAVITY_ISS = 0 (or maybe GRAVITY_ORBIT) for the space station.
Matthew Crumley
YAGNI is (in)action.
paxdiablo
My personal favorite is GRAVITY_THE_ISLAND. Although, nobody ever heard from the people who went there to test it out.
MiffTheFox
the link is 404
Eric
Nitpick: those values are g (ie. acceleration due to gravity), not G (the Gravitational constant). Plus some of the values look wrong.
Mark Bannister
+6  A: 

From The Daily WTF:

private String paula = "Brillant";
Adam Rosenfield
Not really a constant...
Ed Swangren
Not really "Brillant" either.
Joel Coehoorn
Very funny, that was the first TDWTF article that I ever read.
Ed Swangren
It's not declared constant, but it's a private member of a class which is never modified, so it's semantically a constant.
Adam Rosenfield
strings are constant
1800 INFORMATION
+11  A: 

To comply with Indiana H.B. 246:

#ifdef INDIANA
const float PI = 3.2;
#endif
eleven81
Didn't this bill fail? In 1897?
David Morton
No, no....PI = 4; :)
igor
+2  A: 
/** SUBVERSION REVISION OF THE FILE */
private String SVN_REVISION = 34234;

I still haven't figured it out. It was littered in a few dozen files, and never used.

Rontologist
You don't suppose something was writing it into the source file?
gbarry
Let's say you forgot the quotes; this is clearly something added by a script. CVS/RCS had something like that, you can see it sometimes, when you put $Version$ in a file, it gets replaced with the version number on commit.It's not used by the code, but it's written to the class files and might be used by exception or debugging code to generate stack trace with version info.
niXar
+1  A: 

Never seen it, but really want:

#define MAGIC "more magic"

We have a bunch of magic #defines here that we use as the kernal of license keys...

Brian Postow
Gotta include the link: http://catb.org/jargon/html/magic-story.html
Joe White
+21  A: 
#define NUMBER_OF_CONSTANTS_NOT_INCLUDING_THIS_ONE  4
#define NUMBER_OF_CONSTANTS_INCLUDING_THE_LAST_ONE_BUT_NOT_THIS_ONE  5
JohnFx
+NUMBER_OF_CONSTANTS_NEEDED_TO_INDICATE_UPVOTE
David Zaslavsky
I... I don't want to believe that this actually exists. Please tell me you made this up.
JSBangs
Kurt Godel made this up
1800 INFORMATION
Sure about Goedel? I'd have picked Bertrand Russell, myself.
David Thornley
I don't understand why those two macros should have different values.
Jeffrey L Whitledge
What, nobody has complained about the syntax errors?
Thomas Padron-McCarthy
I need proof this exists
annakata
Unless there is one more constant between them, this is not only absurd but also wrong.Also, the syntax errors.
Javier Badia
A: 
#define ADMIN "Admin"
Oscar Cabrero
+11  A: 
//Thank you Crash Macro!!!
#define CRASH (*((void*) 0))++

I actually used that one in a project where i was doing some programming with a simulator that had no debugger. It went something like this:

if(v == SOMETHING_WRONG)
    CRASH;

Then I got to spend a few hours looking at memory dumps in a hex editor to find out what happened. (also the comment was obligatory).

luke
+5  A: 

From the early days of C:

#define PI 3.14159 /* should the value of PI ever change */

Yes, I know they meant the constant, but I wonder what sort of extreme universe-altering behavior would have to occur for the actual value of PI to change.

paxdiablo
Maybe if new calculators are invented that show our calculations were wrong :P
Hosam Aly
The #define makes sense, the comment is obviously a joke. Among the sort of people who do this, thought-provoking jokes are often considered the best.
David Thornley
Perhaps at Apple? (see: Reality Distortion Field)
gbarry
#define PI 3in the simpsons world
Jonathan
+7  A: 

We complained to another programmer about him having too many "magic numbers" in his code and that he should turn them into constants. We should have more specific...

Private Const MAGIC_NUMBER as Integer = 7;

Jacob Adams
A: 

function signature that look like:

void FAR PASCAL function()...

where:

#define FAR far
#define PASCAL __stdcall
Calyth
A: 

Here is one right from our own community.

#define TRUE 0
#define FALSE 1

http://stackoverflow.com/questions/541705/is-iftrue-a-good-idea-in-c

JohnFx
+2  A: 

This in an application that deals a LOT with ton / lbs conversions:

const ONE_TON_IN_LBS = 1999.6
JosephStyons
+2  A: 

From the DailyWTF

#define whilst while

Personally, in Authorware (which allowed spaces in variables names)

booBoolMoveOnIsOn True := 1
annakata
+4  A: 

I'm not sure if this counts, but

#define COMMA ,

I can't remember the specifics, but this was necessary for nesting template arguments.

Oliver Hallam
Yep .. MY_MACRO(std::map<int, int>) won't parse correctly (the C preprocessor isn't smart enough to treat <> like () or []).
eduffy
A: 
#define WTF "What the... ?"
ScottSEA
+5  A: 

Here's my personal favorite form TDWTF: pascal.h

#define procedure void
#define then
#define is
#define not !=
#define begin {
#define end }
MiffTheFox
+6  A: 

Not a constant, but related to your dimensions=2 remark: When I was at UW, the manpage for the print spooler had something like:

--duplex n   Print on this many sides of the page.  Acceptable values
             (until we obtain more versatile printers) are 1 and 2.
Ken
+2  A: 
public bool bTrue = true;
Kirschstein
+1  A: 

I once worked for a school board as a programmer of COBOL reports. In order to comply with desegregation directives, it was necessary to track enrollment and attendance by race. As a result, many of the reports contained counts of students in the categories White, Black, Latino, Asian, Native American, etc.

For some reason I thought it would be amusing to globally change all the category names to their...shall we say slang equivalents?...and then go ask the boss for some help debugging a counter overflow problem. Discretion prevents me from writing down what the actual names were but you get the drift.

Took him a couple of minutes to notice. His reaction was funny as hell. Damn near got me fired, though.

T.Rob
+3  A: 

Here is a good one I remember from my last job. It included the following comments.

'Hard coded to be more dynamic
Const DYNAMIC_VAL = 1
dretzlaff17
A: 

Took him a couple of minutes to notice.

ugg