- 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
...avoided!
Admin
If you are among those who believe that the future is XML and XSLT, then you are going to have to deal with variables that can't be changed after they're defined. Makes me wonder why the inventor(s) of XSLT called them variables in the first place.
Admin
This is a translation table. But without all the constraints of using a table; or all the constraints of translating the input to usable output.
Admin
Admin
Guy must have worked with MISRA before...
MISRAble.
Admin
public static boolean IRISH_GIRL = "Too gorgeous to be measured on the 1/0 scale";
caecus - where the Demoplicans elect their candidates?
Admin
Yes, organic things that float are not quite pie.
Admin
Ah, but if you use FOUR you can redefine it later to be 5 so you don't need to subsequently change it everywhere in the code.
Useful when you move into the world of 5 byte integers, 5 seasons, 5 legged animals, etc.
And that automatically redefines that constant of 17 above to 26.
Admin
Because 'variables' don't vary, in a given scope. Get that elementary school "explanation" out of your mind as quickly as possible. They are merely names for (possibly) unknown things.
Admin
Well, in ruby you can, you just need to handle the execption ;)
Admin
Oh, the stupid! It burns!
Admin
200th!
Admin
I did this once as an April's Fools joke. We had a woman on the team who was doing code reviews, and we knew she was easy to get worked up about this.
And she fell for it like a stone. It was very funny.
Admin
My head literally exploded at the end.
Admin
I had a professor in college who allowed absolutely no "magic numbers". So if we were implementing a formula that required dividing by 2, and it wasn't some arbitrary thing that could change in the future, we would still have to name it something like DIVISION_FACTOR. I thought that was incredibly stupid and made code much harder to read.
Admin
"Ninth!"
Admin
Butthurt much?
Ironically, my post was in reference to someone bitching at how unfunny the firsts were. So where was your response the post I was responding to?
And your spontaneous chucking just proves that you are an idiot.
"Durr.. Look, someone hit CTRL-V again, and changed a word!"
Admin
It's very similar to how 3 year olds like to watch the same DVD 100 times a week.
Admin
const int FIRST = 208;
FIRST!
Admin
I was just being a pedant, and picking up on the difference between NULL and nul. I can't think of any situation where you might want to do something like that.
Admin
This is an excellent idea for backward compatibility.
public static final int I = 1; public static final int II = 2; public static final int III = 3; public static final int IV = 4; public static final int V = 5;
...and so forth. You could back port thousands of years old software with this. Brilliant.
Admin
I used to work as a Software Engineer. I've seen stuff like that used in OS systems that live around for decades. When it comes time to upgrade, the compilers sometimes change the definition of what an Integers is, for example, 8 bits vs 16 bits. By defining these up front, they can redefine them quickly.
Admin
So the author believes that using the number four in a program is a problem. Yeah, your sarc detector is working just fine.
Admin
Hendrix. Dig it!
Admin
WTF?
"That is brillant"
Brilliant, my dear, brilliant.
Admin
Read this: http://thedailywtf.com/Articles/The_Brillant_Paula_Bean.aspx
Admin
All the very intelligent folks stare at this and miss the most obvious WTF! - Data typing. Compilers have been smart enough to know the data context for years - and give a data type mismatch error, but other than a few exceptions (like PERL) the developer community holds on tightly to their fixed, pre-defined data types.
Admin
Once I worked with a developer who did this. She's been promoted. Twice. Admittedly she had a pleasing personality, and a couple of other great assets, but now she's in charge of evaluating actual programmers.
Admin
You use a magic number (17) and then a magic formula that uses magic numbers to explain it. Dude, define the constant and be done with it!
Admin
Admin
A magic comment with 3 magic numbers :)
Admin
Oh HELL no.
malloc(17) when sizeof(int) != 4? My sizeof(int) != sizeof(long) and I'm not sure what sizeof(short) is.
The correct code here:
malloc(4*sizeof(int) + 1); // 4 (int) + '\0'
And even then, that's nonsensible: if you're allocating an array of integers bounded by a magic value like 0, myarry[n] will read 4 bytes.
Admin
dang. I think they should've kept Allen's colleague locked in the COBOL cave!
Yeah, it's good to have a constant defined almost everywhere except perhaps when that number is part of a mathematical formula and is not many digits long. For example, if I had the C=2 Pi r formula in some code somewhere, I'd probably code it with a literal 2 because I'm really never going to change that unless I'm changing the whole formula anyway. Now, while I'd feel perfectly justified inserting the literal Pi approximation 3.14159264 there, but I'd probably just use a constant named Pi. Not because it's gonna change next Tuesday, but simply because 3.141592654 is kinda long.
But the thing they missed here with the Constants thing is that the symbolic names are supposed to be meaningful.
Furry cows moo and decompress.
Admin
public static final int CHASSIT = 19
Admin
A colleague of mine adds a prefix to his magic Constants, for better readability:
In VB.net:
private constTwentyone as Int32 = 21
He thinks his program runs faster by adding const as prefix. I told him few times that const is a keyword and needs to be separated before his literal, but he just don't get it...
Admin
final static int INFINITY = 3;
Admin
"BRILLANT"?
Admin
I once had to maintain a FORTRAN program that took exactly the opposite approach: In calculating perspective views for the CalComp plotter (gives you an idea of the age of the application) there were a lot of trigonometric expressions on the order of X = cos(A) + sin(B) or something like that. In certain parts of the code the expressions were like X = cos(0.0) + sin(180.0). This preserved a nice symmetry with the rest of the code and gave the reader an idea of what was going on, but seemed wasteful to me at a time when cycles were expensive. Presumably this might be a good place to define constants like Cos0.
And that reminds me of a calculator that was once being peddled by one of those Sharper-Image boutique companies when mathematical calculators were hot stuff. The ad explained that this was a complicated and expensive calculator, but contained a microprogramming flaw in which arctan(0) was returned as some false value, so the manufacturer had recalled the whole batch. The merchandiser was offering these units at a very attractive price, along with a paper sticker that said "arctan(0) is 0."
Admin
Unfortunately I have seen this on my previous project. The code was checked and the "magic number" was high. So management assigned a programmer (who appearantly did not think of his own) to fix this.
Other pieces of code in that class:
public static final String empty = ""; public static final String EMPTY_STRING = ""; public static final String SPACE = ""; // <== no typo
So imagine the rest of the code...
Admin
I've never met a developer that agreed to that. Maybe I just don't work with stupid people, or maybe this is a stupid strawman.
Admin
You're an idiot. I hope no one pays you to code.
Admin
It wasn't humor and it wasn't funny, moron.
Admin
Unlike you, intelligent people grasp which parts of this are funny and which parts are stupid.
Admin
That's because you're an ignoramus.
Admin
No, moron, it's not the only possible name ... BASE is the correct name.
Admin
It's called an equation, imbecile.
Admin
What a stupid dick. Do you have any idea just how not new Early FORTRAN is? And the fact that this was a seminal version of the joke went flying over your tiny head.
Admin
That quoted statement is clearly not sarcastic. You were called on your over-generalization, but couldn't admit to anything because you're an intellectually dishonest jackass.