- 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
Admin
Shame the Distributed Applications Group wasn't called the Distributed Operations Group.
Your combined operation would be WAGDOG.
Admin
I've actually written code kinda like this... but it never made it past testing, was just quick ugly testing code while I was debugging something else. I heavily // TODO: flagged it and removed it before getting much further.
Admin
For some people, exceptions are just another form of GOTO
Admin
Divide this comment by zero.
Admin
I maintain code written by someone who also used them as a break statement.
Admin
Ahh, "elite consultants" - where would TDWTF be without them?
Admin
Admin
You sir, are my hero!
I'm not talking to anyone in particular but I thought I'd get it out there since it seems to be expression of the month at the moment and someone's going to say it sooner or later.
Whilst I'm here, "the googles, they do nothing" and "the REAL WTF is <insert non-WTF here>". Oh, and "frist" (not).
Admin
Stuck programming in a language that does not offer Exception Handling? .. Use the good-old "divide by zero" trick.
Next week: generating Bus Errors to implement inter-process communication.
Admin
I worked with an (obfuscated) library in java which used new Exception() along with try/catch blocks in order to exit loops, switches...
Debugging was great.... :(
Admin
Do you guys have any idea how discouraging it is to search for an image on the internet, copy its URL, post a message and add the proper BBCode tag to display the image, and then come back a few minutes later to discover that it has been deleted? You're abusing your readership when you do that.
So, you corrected your misspelled word. What's wrong with annotating my post with "Fixed! - Alex" or something similar? After all, I don't mind clicking on your ads now and again so you can rake in a few coins.
Admin
Admin
Intentionally creating an error isn't a crazy wtf if you use the error handling code to catch it and do the correct thing...That's basically the entire point of a Try->Catch block.
Still, assuming there isn't any great efficiency gain, it's better to do it using standard conditionals.
Admin
Was using Raiserror or a better filter really that cumbersome? It certainly would have provided a better error. I guess I'm missing what claimed savings the consultants seem to think they got by using this silly solution.
Admin
The real WTF is that it's inefficient too.
let's examine this expression more closely:
(Active = 1 OR 1/(Active+@ActDivisor) IS NULL)
so... if Active is 1 then the expression is true, otherwise it's 0 and the expression is "1/(Active + @ActDivisor) IS NULL", so... isn't that just "1/@ActDivisor IS NULL", 'cause Active is 0 ... or... um... what?
Admin
(1/0)th!
Admin
'leet old skool fun with covert channels
Admin
This was just the error reporting. The real question is why this procedure was called all over with both in parameters set to zero.
Admin
2 conditional jumps!
Admin
Only when the code stops making me curl up in the corner and cry.
Admin
Except this is PL/SQL. Those consultants weren't stuck, they were on crack.
Admin
Admin
TRWTF is how the code fails miserably on Active==FILE_NOT_FOUND
Admin
Admin
Admin
Reminds me of a trick I used long ago when I coded in VB6. It was often useful to know if one was in the IDE or running as a real executable, so I had a handy IsDebug() method.
Function IsDebug() On Error GoTo bad: Debug.print( 1 / 0) IsDebug = False Exit Function bad: IsDebug = true End Function (Coded from memory and haven't done VB work in years)
Basically, Debug.print calls aren't compiled into the executable, so an error will only get thrown in the IDE.
I am so glad I moved on to Linux and left all things Microsoft behind years ago...
Admin
Admin
Uhhh, why? How does your function turn into "Microsoft = Bad"? Just because you couldn't search the SDK docs and write the following?
(Note: Not sure if that's the correct code, I don't use VB6. IsDebuggerPresent is the Windows SDK exposed method of determining if someone has attached a debugger, though.)
Still, I like the code. Ingenious, for someone who doesn't know how to use documentation. How would you do this in Linux?
Admin
Read the man page....oh wait
Admin
You're right. PL/SQL doesn't have ISNULL (it has NVL). Just slap me silly and call me Paula.
Admin
Ah, but by using an exception to transfer control rather than a GOTO, you conform to the "no GOTOs" rule, and thus what you have written must be a good structured program!
Next lesson: The experts agree that embedded constants in a program are bad because their purpose can be unclear, like "adjustedAmount=amount*2.942;" may leave the reader wondering where the number "2.942" comes from. This problem is easily solved by replacing all constants with a symbolic name. In this example, "final static float AMOUNT_FACTOR=2.942;" and then use the name rather than the hard-coded constant to eliminate the problem!
For advanced students, we will move on to avoiding the pitfalls of global data accessed from a million unrelated functions by declaring the variable private, then create public get and set functions for it and use THOSE from your million unrelated functions. Your data is private, so it meets the "no public data" rule and what you have written must be a properly encapsulated class!
(Note: This is a joke. Please don't take this advice seriously.)
Admin
The goggles, they divide by nothing!
Admin
Everone missed the real WTF.
Escaping the ' in the comments.
Admin
I'm hoping next month's expression will be "shovel-ready", as in "that code was a real pile of shovel-ready dogsh*t". Why should the politicians have all the fun?
Admin
You sir, are an idiot commenter.
Captcha: ingenium (a genius who continually submits nothing but comments about goggles?)
Admin
Admin
Actually keeping member variables private and using get/set methods is a pretty damn good idea. Imagine you have a very frequently used class and suddenly due to new requirements you need something special to happen when it's value is changed. What do you prefer to do, make one change to the set method or change each one of your million unrelated functions?
Admin
Depends on how far removed the unrelated functions are from the class. If they're in the same executable, and I'm using Microsoft's compiler, I can just replace the data with a __declspec(property). For example,
becomes
That would require no more changes to the surrounding functions. Same deal when working in C#, just with language support instead of compiler specific functionality.
HOWEVER, all bets are off if this is a library that is imported or loaded into another executable.
Also, I don't know if GCC has anything similar.
Admin
That declspec property thing is neat, I like it. Don't think GCC does, a quick look at it's attribute list doesn't reveal anything like it. In my case though my code needs to compile both under GCC and MS' Compiler so I can't use anything that is compiler specific anyway.
The Eclipse IDE does have support for automatically generating getters / setters, though it still needs a bit of tweaking to really become useful. It currently doesn't support enough customization to make what it generates fit the surrounding coding style and it also doesn't give me the option of making getters return a const reference. By the time I hand-edit what it has generated it generally is still easier to write the methods myself.
It's a new feature though so hopefully Version 6 will see improvements there. :)
Admin
Admin
Admin
If you're using C++, just overload the = operator!
Admin
Brillant
Admin
Oracle PL/SQL supports exceptions. It is a derivative of Ada, which has its own try..catch idiom. Ada has a block structured begin..exception..end instead.
Ada will raise an exception, rather than throw it. Python borrows this term, but still uses try..catch.
begin raise Some_Error exception when Some_Error then -- Do something when others then -- Handle any other exception end;
Admin
Its not a microsoft problem, its an idiot problem.
Admin
Better still: #define TWO_POINT_NINE_FOUR_TWO 2.942
Admin
Complaining about it is twice as worserer....in accordance with the Prophecy
Admin
Once you succeed in that, you should probably pop over to the middle east and tell those guys to just get over their differences. And they wouldn't even want a pope's hat.
(Incidentally, my captcha was 'laoreet' but I don't have anything funny to say about it. Sorry.)
Admin