- 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
What are you talking about? Even if you have a problem with "0 < count", how is that related to marketing skill and the anything-can-be-a-boolean feature?
In mathematics you can just write "0 <= index < size". In most programming languages you can't (or, if you can, it doesn't mean what you had in mind). So you have to think of something else. In my opinion, the following code seems perfectly fine:
if ( ( 0 <= index ) && ( index < size ) ) { // do something with array[index] } else { // throw an index-out-of-bounds exception }
Granted, the example was about count, but unless you want to tell the compiler it should treat constructs involving variable "count" differently from variable "index", based on the name alone, what can the language definition do?
Admin
My commute? Minute and a half. Unless I decide to walk, then it's about 4
Admin
This is also wrong.
10:58 a.m. Sally checks for next available WIDGET_ID. Finds WIDGET_ID=6 is available. 10:59 a.m. Sally adds WIDGET_ID=6 to the primary table, sees the time, and runs out for a lunch date (forgets to click "save" button). 11:02 a.m. Tim is running late for a lunch date with Sally, but can't leave until he adds his WIDGET. The application determines WIDGET_ID = 6 is available. 11:03 a.m. Tim tries to add WIDGET_ID = 6 to the primary WIDGET table. The application hangs. For 25 minutes. Tim becomes angry, as he is missing his lunch date with Sally. After 10 minutes, he calls IT, and berates them every 5 minutes as they investigate. 11:30 p.m. Sally gets back from lunch, annoyed at having been stood up.
11:31 p.m. Sally calls Tim and tells him to go !@#$ himself. After hanging up, she sees that she'd forgetten to save her work, and clicks "save". 11:32 p.m. Tim's application finally unfreezes, and he gets an unhandled application error, some voodoo nonsense about a UNIQUE KEY CONSTRAINT VIOLATION. 11:33 p.m. DBA investigator sees there are suddenly no locks, calls Tim and happliy tells him that the performance issue has been resolved, and inquires, "are you still having a problem?". Tim is not in the best of moods for that question, hangs up, and calls company VP to ask how it is that after a $1 million hardware upgrade, it still takes 25 minutes to add a !@#$ing widget.
Admin
This must be the software version of "If at first you don't succeed, try, try again."
Admin
boolean answerA = funcA(); boolean answerB = funcB(); if (answerA = answerB) ...
Admin
If not, I call BS.
Admin
So many WTF's, I almost abandon hope upon entering here. So, with loins girded, to battle:-
The first WTF is that someone allowed code to be written and promoted to production without a code review. The legacy code may have been outsourced to umbo-gumbo-land, but that's no excuse for allowing such tat into production. No competent reviewer would ever allow this to pass.
Why did the compay employing the outsourcers permit this to occur? Sheer incompetence springs to mind, but ah, that is supposition. No matter what, this is manifest incompetence by the developer and his superiors, and his superiors employers.
As for the RDBMS that worked slower with stored procedures, I can assure the gentle reader that it wasn't Oracle. The big O features such unheard of high-tech wizardry as a cache. This breakthrough in computing science will come as a shock to many of our readers. In essence it saves repeated disk access by storing the latest and most used data in memory. A smart arse alogrithm ages the old stuff out of memory without user intervention. I may be shooting from the hip, but I believe that this sort of wizardry has been available since oh, around 1975.
Finally, I call bullshit on the Java boyos and their "I can do it quicker" routine. Lets see some posted code, sample data, and verifiable timing tests. Put up or shut up!
Admin
My commute is 5 min. Maybe 10 if I get caught by all 4 traffic lights and there is heavy traffic for some reason. It's about 2.5 miles in total.
BUT I know people that have a 3 hr one-way commute every day. I tried to tell them they need to move nearer to work, but noooooo...
Admin
Actually, they need to find jobs closer to their homes.
Admin
I made the same arguments as you in 2005; but back then, houses were flying off the shelves and the average unemployment period was much less than 30 weeks.
Thank you Obama.
Admin
In Oracle you would properly implement the referential integrity and then catch the exeception when you attempt to delete the parent.
Captcha: Ingenium. Yes I am.
Admin
All performance computing is based on caching, and yet standard webapp implementation forget that and routinely throw away all the data between requests and load it all from scratch for the next...
As to your assertion that those Stored Procedures couldn't possibly be running on Oracle... well, all I'm going to say is that I'm fascinated to know how you can assert that ;)
Admin
SP's may or may not be silver bullets (or should that be bullshit?) however, your link merely demonstrates that no matter how good the programming language, it can always be royally screwed up by a developer.
However, it also exemplifies my original point. Do you for one minute think that such a "stored procedure" would pass a code review? I shudder to imagine the sheer carnage wrought by your linked example.
Admin
I worked at a place before that did no code reviews and with competent developers produced WTFs on a non-regular basis. I worked at a place that did code reviews, and it was quickly discovered what person you wanted to do your code review. Plus, managers and higher always trump any process set in place.
Now, if you've been working a while, you may have seen the kind of code-sweat shop that produced "the beast." This from the country that brought you <a rel="nofollow" href="http://thisisjuststupid.com/wordpress/wp-content/uploads/image/india%20wiring1.jpg"" target="_blank" title="http://thisisjuststupid.com/wordpress/wp-content/uploads/image/india%20wiring1.jpg"">wiring like this. You may have discovered that while this country may produce competent coders, scientists, professors, engineers, the ones who don't make it stay home and find jobs by under-bidding their competitors and brute-forcing solutions. And they don't do code reviews or unit tests.
Admin
In C#, you can't simply throw using where ever you want to, it can only be used to clean up an object that implements IDisposable. Only objects that consume resources outside the VM typically implement IDisposable. So, you won't end up with a huge clutter of using blocks, they will only end up where they are useful, even if the developer is a moron.
Using is also good for newbies because it forces them to declare-use-destroy in the same procedure. Really atrocious things like global connections become very difficult to create.
Admin
It's not even an if statement then - there's no branch. It's just a statement. They could have done this:
There was no need for the loop at all. The whole function is full of WTFery.
Admin
However.... absolute speed isn't everything. For example, if I move the implementation to a web server, then it's much easier to throw 100 web servers at a problem than it is to divide the data among 100 database servers. Also, for 99% of problems, speed of execution doesn't trump all other concerns. High-performance stored procedures tend to cause code repetition. This is because intermediate abstractions make code slower. However, the removal of intermediate abstractions cause code to be harder to maintain.
Im my opinion, stored procedures should be used as exceptions when performance needs demand them. All uses should be documented, along with the reason. Before anybody accuses me of advocating SQL spread throughout an entire application, I also feel that any data access code found outside the data access layer should be cause for public flogging.
Admin
while (!(success = try()));
Admin
FTFY - Runs much faster
Admin
Any particular reason to not just use
Admin
True, but not in C ;)
Admin
#ifndef try #define try #endif
Admin
you had to do: if(componentIsReady == true) if(varIsInitialized == true) while(finished == false) { or while(finished != true) }
Also, with ors and ands...
if(componentIsReady == true && varIsInitialized == true && finished == false)
Admin
FTFY, because you apparently aren't very good at remembering when the current crisis started. Unless you are suggesting Obama is a time-traveler in addition to being a Nigerian Muslim Marxist.
Admin
Admin
Oh, this is in Mexico City, where 30 minutes would be a short commute. This is partly thanks to NIMBYs in the metro area blocking any significant commuter rail projects.
Admin
What I meant by that is that they took a hacked-up language designed for writing quick and dirty operating systems--back when operating systems were kilobytes in size, not gigabytes--which was designed as basically a smiley face painted over assembly and is completely unsuitable for doing large-scale work, and managed to market it successfully enough that it became rather widespread. Widespread enough that it's spawned an entire family of C-based languages which copied large chunks of C's grammar to make them easier for people familiar with the C family to pick up, and brought lots of C's flaws along with it. (For example, just look at how many of C++'s more horrific misfeatures aren't inherent flaws in what the language was trying to do, but in trying to do it C-style.)
Yeah, if it's part of a double conditional, that's different. But the example in the article was a single conditional, and it's backwards because C trains you to write conditionals backwards "as a best practice," because anything can be a boolean, even assignment, and it has confusing double operators. "if 0 < count" looks a whole lot like "if 0 == count" and was probably inspired by it.
And your example shows another problem with anything being a boolean: the aforementioned confusing double operators.
"if ( ( 0 <= index ) && ( index < size ) )"? What's the deal with that && sign anyway? Why can't you say "if ( ( 0 <= index ) & ( index < size ) )"? Because when numbers can be booleans, the compiler can't tell whether your and, or, xor or [b]not[b] is supposed to be operating on a number or on a boolean value, so you need to have separate, explicit "logical" and "bitwise" versions of each, and heaven help you if you get the two versions conflated.
Even to this day Java and C#, which actually have real boolean types, require you to keep two sets of operators straight, simply because that's the way C did it almost 40 years ago.
(And JFTR there's at least one language where you can say "if 0 < x < size" and have it evaluate exactly as you'd intuitively think it should: Delphi Prism, a .NET dialect of Delphi. I've been pushing for that construct to be included in standard Delphi too, but apparently the compiler team's had other priorities lately.) :(
Admin
Another lovely WTF is the fact this function returns true if it encounters an error. That is terrible. It would have been better to leave error-trapping out of this function (since your returns are limited to TRUE, FALSE, and FILE_NOT_FOUND) and let the caller handle the error. As it stands now, any error from the database tells the caller of the function to go ahead and use the ID.
Admin
Whoops. I mean it returns false on an error. If the caller is attempting to find a free ID because the programmer doesn't know what an identity is, it will force the caller to keep looping through IDs (possibly forever) any time the database has a bad day.
Admin
Admin
You left out a couple of steps. I added them for you. You're welcome.
Admin
Some have actually fixed C's faults while keeping the syntax (like Java), and others have tried to stick weird stuff into C (like Objective-C). Honestly, I'd rather have C as a measuring stick and not abominations like Visual Basic, or even worse, MUMPS.
Admin
Admin
Typical copy-paste cargo cult programming.
This is what happens when managers argue that "programming is easy", and then hire cheap idiots instead of actual programmers. In few other fields do customers have such a complete disregard for the value of competence.
Admin
I smiled when I read the code: VB code using JAVA.
I laughed when I read this. "these days"? "moving toward"?
Dependancy Injection was the difference between MS Access and VB 3 in 1992.
Admin
On a related note, do you know the "multiple assignment": a, b, c := 0, 37, 42? That would make a nice extension too. Swap becomes real easy: a, b := b, a. In general, whenever you revert to something like a_old := a life would've been easier with multi-assigns. For instance, Kaldewaij's O(log N) algorithm for Fibonacci (converted from GCL to Pascal):
Without multi-assign that would become a mess (it's not clear why it works because I didn't bother copying the comments / derivation, but it's clear what the code is doing). Added benefit: even if two or three "normal" assignments could've done the job, this is just one statement. If your coding standard allows it you can save a lot of begin/ends (or, in C, braces) if you want to, which can often make your code much easier to read (even if it's just because more context fits on screen / paper). It can even be compiled easily and efficiently, no problem there either.
Captcha: "nulla", good thing I'm not Slovenian or I might be offended you're calling me that. ;)
Admin
Some of us don't have time to wait for non-deterministic garbage collection to call the finalizer method before the server on the other end of the unmanaged resources destabilizes. I have too many web users to keep their database connections open an extra GC cycle.
Admin
What lights? Mind you the 150km of country train travel each way has got boreing over the past decade. More germainly, I'm with the 'move it to the database' crowd. One SP would have removed the obviousness of this WTF.
Admin
Interesting. Only language I'm familiar with that does multi-assigns like that is Python.
Admin
Oh, I'm well aware that it "makes sense to computers," and when you need a small library that can give you both high performance and (a certain degree of) portability, C's the way to go. My "big rant" is about how C is based on design principles for building small, high-performance libraries, (70s operating systems,) but that involves a lot of design choices that make it unsuitable for most modern, large-scale software, including modern operating systems. (A coworker of mine likes to say that Dennis Ritchie's true legacy in the field of computer science is the buffer overflow.)
Admin
You might say that, in that buffer overflows are a misfeature of C. But that's like saying that Tim Berners-Lee's true contribution to society is the Nigerian scam and phishing attacks.
Admin
"...by hundreds of poorly trained, and probably poorly paid, developers."
AWTF ("Another WTF") is that the above probably allowed some IT-impaired VP to claim great cost savings and earn a huge bonus.
Admin
rs.next() was the loop condition. If it returns false, the original code will not call getInt().
Admin
This is the first TDWTF article that has scared me.
Our company uses a certain application, much unloved by our staff for its quirky behaviour, such as every now and then importing a transaction with no transaction type even though the transaction type is correctly specified in the source file.
The vendor does not support this application any more and encourages customers to upgrade.
And one of the workarounds that we had to implement when we started using it was a daily restart of the application server to clean up the JDBC connections which it leaves open after the day's processing.
Admin
This is far from being the worst code ever seen. Just for using 'for' in an 'if' fashion, repeating endlessly the same few lines of code without seeing a clear HEY-I'M-HERE pattern, and not freeing any resources adquired, it only make it a usual-bunch-of-code-made-without-have-ever-thougt-in-code-at-all...
Worse beasts are out there camping in the wilds...
Admin
Living in Christchurch, my commute is 15 minutes.
Admin
Admin
Admin
Java and C# are more strictly type-safe than C.
In C and C++ the expression will work with a single & if you can guarantee that the compiler will always return the same non-zero value when a boolean expression returns true. I do not think the standard, even now, promises it will, so technically one of them could return 1 and one of them 2, and 1 & 2 is 0 because they have no bits in common.
It would make sense that in a system where booleans are not integers, you could use & on booleans with the same effect as &&.
a < x < b
is left-to-right associative in C++ at least, so you would get (a<x)<b. Assuming that a boolean always returns 0 or 1 then if b>1 the expression will always be true regardless of a and x, and if b<=0 then it will always be false. If b is somewhere between 0 or 1 (or equal to 1) then (a<x)<b will be true when (a<x) is false thus x is less than or equal to a.
Admin
You may be getting confused with the fact that in a conditional all non-zero values are considered true, and in those cases (a & b) may be false, while (a && b) is true. But that's only valid if a and/or b are not boolean.