- 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
So they were using the code like: StringUtils.string30("frist") ?
Admin
TRWTF is not using "static final" for the number constants
Admin
For once I am honestly speechless!
Admin
This demonstrates what a great metric lines-of-code is. Never mind the quality, feel the length!
Admin
At least they are on the safe side, should the value of any of the numbers between 0 and 50 ever change!
Admin
Nice. One question: We have seen number-constants many times; under what circumstances do they make sense? (I dont mean e.g. E and PI but ONE, TWO, ...) I know the first answer everyone thinks of is "if they ever change the value of 1 and 2". But my question is meant semi-seriously. (for code-generation?)
Admin
Admin
The Highly Paid Whatevers (TM) didn't screw up. They were obfuscating the code.
Admin
Admin
Yes- if your big constant is MAX_PRODUCTION_RUNS=1000000000 But not ONE_BILLION=1000000000 surely?
Admin
I was on a project where TWO of those Highly Paid Consultants couldn't figure out why their "string copy" function, written in C, wasn't working. They were using an assignment statement (the "=" operator) to assign one function parameter to the other. The debugger seemed to be showing them that their destination parameter had the right string value. They just couldn't figure out why it kept "disappearing" when their "string copy" function returned. I gave them some hints, but they were not listening. Eventually, after a few hours, they figured it out. :-/
Admin
Admin
More like: feel the thickness.
Admin
Or they used stackoverflow and posted their code, asked why it doesn't work and someone responded. A few hours of mucking around and then 2 minutes to get a response sounds about right.
Admin
Actually, I am a bit dissapointed. I half expected the leaked MtGox code to be todays wtf...
Admin
This is really unbelievable. I mean i think its fake or exaggerated. How can someone use a TWENTYNINNE instead of the number.
Admin
There's good reasons for simd/vector types as well (especially on consoles where transferring data from float to vector registers is expensive, Xbox 360 for example) - I'm coming from a game dev background.
Vector1(1.0f);
will give you a 1D vector of value 1, but as the compiler may not understand the vector type it'll load it into a float register, then into the vector one which causes some complex stalls.
Vector1::One();
Returns a reference to a static thing that's already a vector. The difference in subtle, but in some loops on some platforms - it does have an effect.
Admin
They are measuring something, they are keeping logs of their metrics, so they feel that they are actually managing something.
Also, adding lines of code looks more productive than, say, deleting lines of code by refactoring. Especially to managers without a software development background.
After all in most of manufactoring the number of units per worker is a good metric for productivity, so why should it be different for programmers?
Admin
SCNR
Admin
I had a peek at some code today and it was littered with the magic number "100000000". Searching for that number revealed at least one occurrence in the code where 1000000000 is used.
Question: typo (one zero to many) or intention?
If HUNDRED_MILLION would have been used instead of 100000000 that question would not arise.
Admin
Admin
This is very bad. They should have created 21 subclasses of a common superclass, each containing an object with common function name but different truncation functionality.
Then they could instantiate a subclass object each time a truncation is needed and abandon it for garbage collection immediately afterwards. Using a factory, of course.
It's not really object oriented if you do it otherwise.
Admin
Could probably be improved with XML and regular expressions, but I'll leave that to someone else.
Admin
Aaargh, you simply don't get it! Magic numbers are evil! Should have been:
Aaah, much safer!
Admin
Even the most naive compiler would be at least as quick doing 1+2 as ONE+TWO - if not it's trivial to identify literals and produce code like ONE=1, TWO=2 and use those instead during parsing.
Worse, in the code above the values are neither static (so copied across instances) nor final (single reference to let the compiler inline the lookup). In this code THREE + FOUR would entail at least two lookups at runtime.
Captcha: consequat - the consequat of using pointless constants is confused code and a spot on TDWTF
Admin
How do I get in to this Highly Paid Consultant racket? I apparently have the qualifications already, as in I can use a keyboard to type in words.
Admin
After all, the methods (string30(...) etc) are also not static, meaning that whoever wants to use them has to instantiate StringUtils.
Admin
Admin
Love this :D
Admin
That's not a constant ... that's a method with intentional additional logic for optimisation that doesn't return an integral value.
CAPTCHA: bene - you've bene on the hooch again haven't you?
Admin
MAX_AIRSPEED_OF_AN_UNLADEN_SWALLOW_IN_MICROMETERS_PER_HALF_HOUR=1000000000
Admin
Admin
I've implemented numerical code where the data objects satisfied the Ring properties.
In that case I would always implement two constants, Foo.ZERO and Foo.ONE which contained static objects that represented the appropriate values for the multiplicative and additive identities, i.e. foo.times(Foo.ONE).equals(foo)
Admin
Admin
Take, for example, string30. If you pass in a String of length 0-29 characters, you get it returned. If you pass a String of length 31 or more characters, you get back the first 29 characters. If you pass a String of exactly 30 characters, you get that String back.
The suggested replacement code is not bug-compatible.
Admin
You need to be the CEO's nephew.
Or to be married to the president's daughter.
Admin
Probably an engineer of the old school, to whom "static" was what caused certain unpleasant noises to emerge from the loudspeaker of his wireless set, and therefore something to be avoided whenever possible.
Admin
Sometimes the reason for using a billion is because the number you want is a billion?
ONE_BILLION=1000000000 uk_gdp_in_billions = uk_gdp / ONE_BILLION
Admin
"I'm not even going to go into what would happen if someone passed in a null pointer."
I'm going to take a wild assed guess that it would throw an NPE.
TRWTF is strongly typed languages that include values you have to check for at runtime.
Admin
The peculiarities of FORTRAN parsing mean that
and
are the same thing...
Admin
Admin
It is all well and good to use every type of construction in the programming language, but I find it easier to just stick to the basics sometimes:
A little easier to read and I think the optimizer can do a little more with this because two lines are actually the same.
Admin
Admin
Admin
About 20 years ago, Bill Gates was quoted comparing the use of lines of code to measure code with using weight to measure aircraft quality.
Admin
And then there's interpreters.
Admin
Admin
Brillant!
Captcha: Validus - this comment must be right.
Admin
Admin
Seriously? If the input length is less than the substring end index, it throws java.lang.StringIndexOutOfBoundsException.
For example:
String s = "adfadsfadsfadfs"; System.out.println(s.substring(0, 55));