- 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
That IF FALSE THEN TRUE ELSE FALSE is a classic that must get trotted out all the time.
Should be covered in basic programming class.
Admin
If you teach someone BASIC, you cripple their ability to program.
Admin
I'm guilty of the second WTF a lot. In my defense, I was young and foolish.
Admin
I can't fully agree on that. Sure it is a limited language but also a good way to start when learning to program. At least in my case when I first started doodling in QBasic was when I was 6 ;). Converting from QBasic to C# was not so hard.
Admin
The SUBString thingy looks a bit like a workaround. The way Oracle works, substr() in a SQL statement is processed by the SQL engine, while substr() in a PL/SQL statement is processed by the PL/SQL engine. Of course both should return exactly the same result for given input parameters; but if a bug in the PL/SQL engine caused incorrect results on some input parameters, transfering the work to the SQL engine as shown in the example might help. (Not that I know of any bug that would make this kind of function necessary)
Admin
I can see it now: "C# -- A Better QBasic..."
Admin
Argh, I hate "x == TRUE" tests, since they don't match the language's definition of truth. If TRUE is #define'd or enum'ed (or global variable'd, heh) to be 1, but x is the product of something other than the logical operators, then this code may very well consider x to be false. (Heh, if the code then tests "x == FALSE", it may decide that x is neither true nor false, so that leaves... FILE_NOT_FOUND?)
Examples include x being a pointer (which is true if not NULL), a number (true if not zero), or the product of bitwise operations (true if at least one bit is set).
For this test to work as intended, the bizarre locution "!!x == TRUE" must be used so that x is "canonicalized". But somebody who knows about that trick also knows not to compare against TRUE.
Lastly, the expression "x == TRUE" is redundant; just say "x" and be done with it!
Admin
I'm wondering if the SUBString predecessor actually replaced a 200-line function that barely worked but was called from 1,000 places with a much simpler migration function. At least, that's what I'm hoping.
Admin
just to make sure I understand this correctly, he re-wrote SUBSTR with SUBString, and used SUBSTR in the equasion? WTF for re-writing it if he's not going to use his version.
Admin
Admin
Agreed. I started out in QBasic too. The advantage is that after a while, you start to realise the limitations of the language yourself, because you try to do stuff and it's harder than it should be. I didn't know I needed pointers 'cos I'd never heard of a pointer, but I knew I wanted to be able to put a reference to one variable in another. And you don't truly understand the importance of structured programming until you've written some truly tangled spaghetti code yourself :)
So you learn lots about how not to do it. And then go buy a book on a real language.
Admin
Here's a "not" function that I cooked up back in my very early days:
Admin
Surely "(bool)x" would be considerably more readable and do the same thing?
Admin
I used BASIC when I was around 7 as well. Writing some horrible 2000 line monsters littered with GOTOs has given me a real appreciation for a well-designed, loosely coupled architecture. Far from destroying my programming ability, it showed me a way of thinking logically.
I frequently come across people who obviously haven't been thought boolean logic. They get freaked out when you write things like while(!isRunning) and have empty if statements with their code in the else cause they don't understand it. As for the Oracle thing, that could have been caused by a funky implementation of SUBSTR written and taken out and a decision made not to change the existing code that pointed to the function.
It's still a WTF though.
Admin
The other possible (valid) reason for the SUBString function is if the application once supported multiple databases. In that case, you sometimes have to wrap SQL functions in one database so you can use a common function name across all the databases.
Still, not what I would have called the function (too much a possibility of a name conflict with another DBMS vendor) nor how I would have coded it.
Admin
Bollocks. BASIC programmers learn to program in a nice linear manner and understand the whole input, process, output concept. It's the best possible way to start learning to program. All of the recruits we've had recently get far too clever with pointers or spaghetti objects or some fucking framework <spits> and end up tripping over themselves due to a lack of basic skills.
Admin
I like the fact SUBString does the same as SUBSTR, except for substrings longer then 100 characters where the output is truncated.
Admin
Admin
:)
Admin
is the BOOLIFY(2+2)==3 intended? :-p
Admin
SUBString looks to me like a platform independence wrapper. If you want your SQL to work "unmodified" on different databases, you might need to wrap certain functions so that your implementation can work the same on all platforms. On your "canonical" platform the wrapper just calls the base implementation but on other platforms you might have to do something different. Not necessarily a WTF.
My fav abuse of stored procs though is a pattern we used to see where I work: a stored proc whose only job is to do a SELECT and return a cursor. Why have the proc at all?
Admin
A few reasons to do this come to mind.
For one, you avoid having SQL code in your application - which in turn prevents application developers from actually writing SQL, which from a DBA's perspective is a "good thing"(TM)
Another reason may be that you've settled on a particular architecture were all database calls are going to made in a unified and consistent manner, and that method is to call a stored procedure - whether you are doing a simple insert, update, or delete; or whether you are doing something more complicated. That way you application framework only has to handle one method for communicating with the database.
Admin
This.
Admin
Being a bit out of touch in the Oracle way, might the SUBString code have to do with getting substr processed in a different character set?
Admin
Enough about the booleans - what's that PRIVATE macro all about?
Admin
Admin
Well I often did (and still does) the following:
protected boolean someComplexNameIndicatingFunctionalCheck { return true; }
because this method is used in a particular implementation (subclass) and a peer class could return false, or a dynamic value.
Admin
Admin
The "toggle" function can be quite useful if it is used as a function pointer
Admin
Worse, I did much of my early programming on a computer with no languages installed but QBasic, and deciding I needed pointers, I actually implemented them using the low-level memory functions it provides. It took me a while, because this was before I understood floating-point numbers were used by default (it's just 'a number', after all) and spent ages trying to read them bytewise before I came to the conclusion of copying a floating-point number I only had a pointer to (strictly speaking, segment and offset for) byte-by-byte to a local floating-point variable using low-level memory routines, and then returning a copy of the local variable. Certainly not the way to program in any language.
(A couple of years later, I discovered Pascal and then C, both of which are much better at pointer manipulation.)
Admin
Nobody seems to have commented, on the Oracle case, on the point that, even if you need a wrapper, the "SELECT ... FROM DUAL" and the context switch that is implied are pointless ... The developer could have directly returned substr(...). Run it in a loop, you'll feel the difference.
Admin
Please! Get off the high horse.
Admin
Qbasic isn't exactly BASIC. It is, but it isn't. Using QB, you can learn a lot about functional programming and things like parameter passing and writing functions (ahem: procedures--functions return a single value).
Now, real BASIC is what Dijkstra was taking about. There are no functions, only gosub. Gotos were the way to get around your code, not subroutine calls. "Information Hiding"? What's that?
Admin
Admin
I just find my mind boggling at the concept of going directly from QBasic to C# ... OOP just isn't that trivial to pick up (to say nothing of the .NET framework).
The parallel is, of course, with "C++: a better C." Not that that's very believable, either.
Admin
I think that you will find that this condition will raise an ORA-06502: PL/SQL: numeric or value error, not truncate the string
Admin
Oracle treats values from tables somewhat differently from the values of local variables. Perhaps this was just to force it to be part of a rowset so that it can be processed in a particular way (in conjunction with something which did not play nice with a local variable.)
I have had lots of fun trying to figure out when to put the colon or no in PL/SQL, as well as making it play nice with local variables. Some things just don't work with local, pass, or bind variables, and need to be table fields.
Admin
Allow me to say, "That's the real WTF!" Somebody actually feeling it necessary to elucidate on the infamous "x == TRUE" redundancy. What do you take us for?
Admin
I'm confused. When would someone who feels the need to use explicit (x==TRUE) (x!=0) (x!=NULL) comparisons be likely to use the x==TRUE test for something that isn't achieved by using logical operators?
Admin
I went straight from QB to C++, I don't think it is really any harder than doing C++ from scratch. If you are by inclination or ability a half-decent programmer, learning any language isn't going to make you a worse programmer, any more than driving a crappy car would make you a worse driver. [disclaimer: I can't drive so I don't know if that last assertion is really true]
Admin
I work with code that does this!!!
Admin
ICON uses success and failure to achieve goal-directed evaluation. We lovess it.
http://www.cs.arizona.edu/icon/
Admin
I find Alicia helps more little children on how to code.
Alicia + KungFu = Total Destruction (ain't inspired today)
Admin
If that's the case, it still suffers from the flaws mentioned elsewhere: a potentially conflicting name, truncates the output, implied case sensitivity where there might not be any, and appears inefficient for Ork where it can be platform specific. I'd do an assignment: result := SUBSTR(inputStr,startPos,endPos);
And, should it support substr(inputStr,-3); ? If not, it might benefit from some bounds checking.
Admin
I would also add that if all access to the database is via stored procedures then you can secure the data using security roles so the application only sees the data that it's required too.
Important if you have both a "web facing" and "internal administration" views to the data.
And - developers can often develop horrendous SQL code and embed it into the application (like the SELECT :var FROM dual; example above). It least it lets the DBA have a chance of optimising the sql.
I am not a robot: DOOM
Admin
[quote user="Puckdropper"]Qbasic isn't exactly BASIC. It is, but it isn't. Using QB, you can learn a lot about functional programming and things like parameter passing and writing functions (ahem: procedures--functions return a single value). quote]
What could you possibly learn about functional programming from QBasic?
Admin
I dont know enough about Oracle's innards to comment on the first one. But the second one isnt necessarily a WTF - it needs more context. For ex, there may be more functionality intended for that function... or there may have been additional code there at one point and they didnt want to rock the boat and go back and change every call to the function.
The "if (x == true/false)" thing is a matter of style - I think its more readable than "if (x)" or "if (!x)" in some cases.
captcha: gygax (whom I've personally met - great guy!)
Admin
Admin
Admin
The most general way of toggling between two values:
BOOL toggle (BOOL inVal) { return TRUE + FALSE - inVal; }
Now you can redefine TRUE and FALSE to whatever you like...