- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The earths rate of rotation changes on a regular basis so the joke's on you!
[;)]
Admin
:O Dude. W.T.F.F.
These look like the work of people who never understood the purpose of constants yet still somehow managed to remember their CS101 Prof's admonition that "literals in code are bad, use constants to define literals and use those in code." Thus, instead of meaningful constants such as SIZE_OF_HEADER or BUFFER_SIZE you get INT_512.
Admin
You know, I was just checking about:config in my firefox, and I noticed general.config.obscure_value as well
I found the explanation:
Admin
Yep, that should be a function that varies on time of year, speed of solar winds, the alignment of the planet, and the number of people are walking east versus the number of people walking west.
[:)]
Admin
Constants aren't, variables don't.
Admin
Hey, the good news is that at least the above code examples avoid the Magic Number Anti-pattern!
Admin
One funny thing I just noticed is that Josh Buhler's coworker only seems to master "not" and "larger than" operators:
if(!(val.indexOf(" ")>0) || !(val.length>TWO)) {
instead of:
(val.indexOf(" ") == -1 || val.length < TWO)
And second half of above if-statement in reprise:
if(!(val.length>TWO))
And he probably would have used constants if there where any(It looks very much like Flash ActionScript 2.0).
/Mirandir
Admin
I suppose calling it something like "duration of earth's rotation" would be too sensible...?
Admin
Make that....
(val.indexOf(" ") == -1 || val.length <= TWO)
(I should have fixed the first half of that as well, but we know what JB's Coworker really meant...)
Admin
And this isn't even counting a submission a made a while back that has these defines in a C header file.
#define FIELD_WITH_LENGTH_FORTY_SEVE 47
#define FIELD_WITH_LENGTH_FORTY 40
#define FIELD_WITH_LENGTH_THIRTY 30
#define FIELD_WITH_LENGTH_THIRTY_ONE 31
#define FIELD_WITH_LENGTH_TWENTY_FIVE 25
#define FIELD_WITH_LENGTH_TWENTY 20
#define FIELD_WITH_LENGTH_THIRTEEN 13
#define FIELD_WITH_LENGTH_TWELVE 12
#define FIELD_WITH_LENGTH_TEN 10
#define FIELD_WITH_LENGTH_NINE 9
#define FIELD_WITH_LENGTH_EIGHT 8
#define FIELD_WITH_LENGTH_SEVEN 7
#define FIELD_WITH_LENGTH_SIX 6
#define FIELD_WITH_LENGTH_FIVE 5
#define FIELD_WITH_LENGTH_FOUR 4
#define FIELD_WITH_LENGTH_THREE 3
#define FIELD_WITH_LENGTH_TWO 2
#define SINGLETON_FIELD_LENGTH 1
Admin
Admin
If that code isn't executed every day at midnight, the values will only be right for a certain amount of time, no? But then again, 24 hours or possibly 12 hours is not what I would call long-running for a daemon....
And WTF if this code is executed at 23:59:59'99? TODAY, YESTERDAY, LASTWEEK and LASTMONTH (stupid capslockitis) might all be wrong then.
Admin
I can only imagine that since TODAY is a constant, TODAY says the same thing as it did when the app was started as it does two weeks later. So maybe they are comparing TODAY with TOMMORROW and determining whether to exit.
Admin
It might also to unwanted effects when the year changes, but I don't know in what format today() returns its information, i.e. if the year is included.
Admin
LOL that made my day, I have nothing to say but WTF!
Admin
Rate makes much more sense. Duration implies that it starts and ends.... Would be awfully strange if the earth just upped and stopped rotating after 24 hours. [:D]
Admin
Time would stop! [:D]
Haven't you ever seen Superman?
Admin
Unfortuetly his code never references an IGyroscope so he cannot detect if the earth's rotation rate was changing.
Also, anybody who previously said the Earth's retation is static was incorrect ( http://www.iers.org/iers/earth/rotation/ ), it does change slightly according to the distance of planets & moons in our immediate area. Of course going with an average rotation is pretty reliable, I mean, it's not like his code is going to automate landing a probe from earth and it MUST land within a 6 inch square on Mars and he has no visual cues to go by. Wait I take that back, he might have been a coder on previous Mars lander projects.
Admin
I am reminded of an early FORTRAN system I worked on that would allow you change the values of constants by passing a constant to a function which changed to value of the parameter. So you give the constant value 3 a value of 5 so that wherever else 3 was used it use 5 so the expression 3 + 2 would calculate to 7.
Then that fancy virtual memory came around and people started putting the values of number in protected pages and it took all the fun out of it.
Admin
On the ZX81 home computer, using the built-in BASIC, it was a common coding practice to do something similar; e.g.
Hard to say if this is a WTF without knowing the background; sometimes similar code is the right way to avoid a date switch-over during processing which would cause bad effects. Of course, your program should run into these lines at least once per day ;-)10 LET I=1
because numeric literals required 5 extra bytes of memory for each occurence (for speed reasons, the system stored the float value along with the readable representation) and memory was very limited, 1KB in the basic model. So using this "constants" saved 5 bytes each time; the declaration of both costs est. 24 bytes, so it pays off soon.20 LET O=0
Admin
So true, thanks for the laugh
Admin
I ended up doing this recently. I think I was feeling allergic to new that day.
private static final Integer INT_1 = new Integer(1);
private static final Integer INT_2 = new Integer(2);
public static final Integer MAGIC_COLUMN_A = INT_1;
public static final Integer MAGIC_COLUMN_B = INT_2;
public static final Integer MAGIC_THINGY_X = INT_2;
public static final Integer MAGIC_THINGY_Y = INT_1;
public static final Integer MAGIC_THIUGY_Z = INT_1;
etc.
Admin
Thank god for design patterns, though.
<FONT face="Courier New" size=2>public class MyAwesomeProgram
{
public static void main(String[] args)
{
MagicNumberFactory mnf = MagicNumberFactory.getInstance();
int myMagicNumber = mnf.getMagicNumber(MagicNumberFactory.BIG);
System.out.println("check out my magic number: " + myMagicNumber);
}
}
class MagicNumberFactory
{
private static int count = 0;
public static final int BIG = 1;
public static final int COOL = 2;
public static final int SUPERMAGIC = 3;
public static MagicNumberFactory getInstance()
{
return new MagicNumberFactory();
}
public int getMagicNumber(int type)
{
++count;
int theMagicNumber = 0;
switch(type)
{
case BIG:
theMagicNumber = BIG * 14 * count;
break;
case COOL:
theMagicNumber = COOL * 85 * count;
break;
case SUPERMAGIC:
theMagicNumber = SUPERMAGIC * 132 * count;
break;
default:
theMagicNumber = count;
break;
}
return theMagicNumber;
}
}</FONT>
Admin
ROFLMAO @ rog. If this place allowed karma awards, that'd get one.
Admin
Wa?? @ Rog
Anyways, I've been wondering why people make getIntance() methods. In what situations is this a good idea?
Admin
Looking at:
Wonder if
'...' is more usefull as a FULL NAME or FULL ADDRESS than '.' or 'abc' or any other random 3 character cr*p.
Admin
BTW, on that last one:
"Obscure" is to be thought of as a verb, not an adjective.
Basicaly, this value is subtracted from the ascii value in config files, so that the files are "obscure"
Admin
Haha What the hell was I thinking... ?? [:$] Can I join the "Have-made-a-big-wtf-club" now? [:P]
/Mirandir
Admin
The other common trick was to use
10 LET I=PI / PI
instead of
10 LET I=1
This was because the ZX81 used a tokenised BASIC, with PI only taking one byte. Therefore, PI / PI actually took 3 bytes to declare the numerical value '1' as opposed to 5.
Ahhh, those were the days!
Admin
getInstance (or similar) is generally a symptom of the http://c2.com/cgi/wiki?SingletonPattern
The link provided explains in excruciating detail what the pattern is about, advantages, pitfalls, how it is commonly abused and why, etc etc.
If you've not come across the concepts of singletons before, I would strongly suggest buying the 'gang of four' book and spending some considerable time browsing the c2 wiki. This is liable to reduce the WTF:LOC ratio of your work considerably[1].
Simon
[1] Unless it doesn't, of course
Admin
That's awesome.
Admin
This forum software, however, is not. :/
Admin
Hey Tufty, thanks for that website. They have a number of interesting things there. [:)]
Admin
Somehow this reminds me of $TEXMF/tex/latex/base/latex.ltx[/code:
\def@vpt{5} \def@vipt{6} \def@viipt{7} \def@viiipt{8} \def@ixpt{9} \def@xpt{10} \def@xipt{10.95} \def@xiipt{12} \def@xivpt{14.4} \def@xviipt{17.28} \def@xxpt{20.74} \def@xxvpt{24.88}
Seems like Roman eleven and twenty-four were half a percent smaller than ours, but to make up for this, seventeen was 1.6% larger, fourteen almost three percent and twenty as much as three point seven percent larger.
Admin
The only way this makes any sense whatsoever is if it was mixing postscript and classical print point sizes. Although that still doesn't explain the roman numerals.
I've been guilty of making one-time-use constants and placing then right before the function definition. >.>
Admin
On the Power PC (and maybe on x86 too) constants may have bad data locality and take two instructions to load. Using gConsts.zero rather than 0.0 may end up taking half as many instructions if a bunch of constants are used in a function. This is because it only has to load the address of gConsts once then it can just use offsets to get the other values.
Admin
Might I suggest that if you don't know what a singleton is that you get a book that you can actually read and follow through like "Refactoring to Patterns". The GoF book is really good, but it's a reference book, not a book for learning.
Admin
I believe the original was "Constants aren't. Variables won't."
Admin
Look like artifacts from an original source written in COBOL some decades ago. Often to be found in prgs for accounting and financial calcs.
Found some which made their way from COBOL through dBase to Access aso. I have an idea of beeing a very old sick man in a hospital and there is a holographic avatar serving me ... and it looks like pacman. [*-)]
Admin
Don't laugh... one day it will happen to you! I have seen this in lots of code before. What happens is some idiot writes the initial system, then all of a sudden it stops working because totalGlue is allowed to be 9, and not 8. So what's the easiest change to make? Just bump it up to 16. Of course the dickhead who did this without renaming the constant should be shot. And they should have renamed it to "MAX_GLUE_AMOUNT" or something.
Admin
This goes back a looong way. I beleive the original K&R suggested using the line
#define PI 3.14159
should "the value of PI change in future".
Admin
private const int INT_ZERO = 0;
TODAY = today()
At least he's prepared if 0 would change to 100,01 in the very near feature.
Same with the fact that soon today will be known as 'the day after tomorrow'.
Surely you've thought of that designing your apps ? [^o)]
Admin
Well, the Roman numerals are there because TeX does not allow digits in identifiers, so they're justified. And yes, it is a point size conversion - although it's still strange to define "20 pt" as "20.74" using a macro.
Admin
I'm pretty sure it wasn't K&R but some Xerox FORTRAN manual. It was used it many fortune files with this annotation.
Admin
er..um... It seems you haven't even gotten that far...
!(val.indexOf(" ")>0)
allows spaces in the first position (position 0) while
val.indexOf(" ") == -1
don't! And it is obvious that we should allow spaces in pos 0 ;-)
/Olle
Admin
Is it just me, or did I find PAUSE_BY_6_SECONDS to be completely reasonable? I.e. if I use the literal "6000", is it obvious that is six seconds? Far too easy to accidentally type "600" or "60000" ...
tekra
Admin
It should use a better name that doesn't include what the current literal amount is. Like: PAUSE_DURATION. If there are multiple pause durations(6 seconds, 12 seconds, 18 seconds for example), then you should append meaningful names like SHORT, MEDIUM, LONG.
All IMO.
Admin
It is just you. It should be
PAUSE_FOR_LEGAL_MINIMUM_TIME
That way when congress changes the legal minimun to be 9 you don't have to change the name of the constant. 6 seconds is the value today, but it might not work out for a faster machine in the future.
Admin
He just wanted to check F and 11 on the hacker purity test. Not to mention 8C
http://www.armory.com/tests/hacker.html
That might be enoguh to get his score out of the single digets.
Admin
"Refactoring to Patterns" is indeed a great book!
But I can also stronly suggest "Head First: Design Patterns"
An amazing book!
regards,
Jeroen Vandezande