| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
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. |
|
If you teach someone BASIC, you cripple their ability to program.
|
|
I'm guilty of the second WTF a lot. In my defense, I was
young and foolish. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 09:27
•
by
Jonatan
(unregistered)
|
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. |
|
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)
|
Re: No Thanks, I Prefer SUBString!
2007-10-10 09:37
•
by
real_aardvark
|
Really? I can see it now: "C# -- A Better QBasic..." |
Re: No Thanks, I Prefer SUBString!
2007-10-10 09:46
•
by
Andy Goth
(unregistered)
|
|
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! |
Re: No Thanks, I Prefer SUBString!
2007-10-10 09:49
•
by
Just Some Guy
(unregistered)
|
|
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.
|
|
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.
|
Re: No Thanks, I Prefer SUBString!
2007-10-10 09:51
•
by
Andy Goth
(unregistered)
|
By the way, I'm serious about the global variable thing. I once saw code that had a global variable called "success". Functions would return "success" if they succeeded or "!success" on failure. The calling functions would compare against "success" to test for success. However, at least one function got it wrong, instead opting to assign 1 or 0 to the global variable "success" to indicate its status. I think you can picture the ramifications of such a function failing. :^) ("If at first you don't succeed, redefine success.") |
Re: No Thanks, I Prefer SUBString!
2007-10-10 09:52
•
by
misha
|
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. |
|
Here's a "not" function that I cooked up back in my very early days:
return CBool(CInt(bFlag) * -1) |
Re: No Thanks, I Prefer SUBString!
2007-10-10 09:56
•
by
misha
|
Surely "(bool)x" would be considerably more readable and do the same thing? |
Re: No Thanks, I Prefer SUBString!
2007-10-10 10:02
•
by
Phill
(unregistered)
|
|
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. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 10:02
•
by
John
(unregistered)
|
|
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. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 10:05
•
by
Bob
(unregistered)
|
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. |
|
I like the fact SUBString does the same as SUBSTR, except for substrings longer then 100 characters where the output is truncated.
|
Re: No Thanks, I Prefer SUBString!
2007-10-10 10:17
•
by
Andy Goth
(unregistered)
|
Yes, if you're using C++ and descendents. However I usually encounter this kind of garbage when using C, which has no bool type. But thanks, I'll keep that in mind the next time I'm using C++. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 10:20
•
by
Dark Shikari
|
Or you can do what the code I'm working on does--#define BOOLIFY(x) !!x :) |
Re: No Thanks, I Prefer SUBString!
2007-10-10 10:30
•
by
HackyKid
(unregistered)
|
is the BOOLIFY(2+2)==3 intended? :-p |
Re: No Thanks, I Prefer SUBString!
2007-10-10 10:34
•
by
Mr. Shiny & New
(unregistered)
|
|
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? |
Re: No Thanks, I Prefer SUBString!
2007-10-10 10:44
•
by
notbloodylikely
(unregistered)
|
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. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 10:44
•
by
bling
(unregistered)
|
This. |
|
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?
|
|
Enough about the booleans - what's that PRIVATE macro all about?
|
Re: No Thanks, I Prefer SUBString!
2007-10-10 11:19
•
by
Stone
(unregistered)
|
If you're using C from the 1980s, sure. C has had a bool type since '99. |
|
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. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 11:37
•
by
Synonymous Awkward
(unregistered)
|
I see quoting Dijkstra still hasn't gone out of style (or paraphrasing, in this case). |
|
The "toggle" function can be quite useful if it is used as a function pointer
|
Re: No Thanks, I Prefer SUBString!
2007-10-10 11:46
•
by
ais523
(unregistered)
|
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.) |
|
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.
|
Re: No Thanks, I Prefer SUBString!
2007-10-10 11:59
•
by
operagost
|
Automobiles: a Better Bicycle Lingerie: a Better Underoos Please! Get off the high horse. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 12:01
•
by
Puckdropper
(unregistered)
|
|
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? |
Re: No Thanks, I Prefer SUBString!
2007-10-10 12:05
•
by
Andy Goth
(unregistered)
|
That's news to me! Thanks. Looks like it's made available by <stdbool.h>, which I had never heard of before. I guess that means I'm not using C99. I'll probably start sneaking bool into new code now. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 12:11
•
by
real_aardvark
|
What high horse? I quite like C#. 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. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 12:13
•
by
I Know PL/SQL
(unregistered)
|
I think that you will find that this condition will raise an ORA-06502: PL/SQL: numeric or value error, not truncate the string |
|
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. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 12:16
•
by
Brady Kelly
(unregistered)
|
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? |
Re: No Thanks, I Prefer SUBString!
2007-10-10 12:24
•
by
Andrew
(unregistered)
|
|
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?
|
Re: No Thanks, I Prefer SUBString!
2007-10-10 12:38
•
by
misha
|
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] |
Re: No Thanks, I Prefer SUBString!
2007-10-10 12:46
•
by
She Ra
(unregistered)
|
I work with code that does this!!! |
Re: No Thanks, I Prefer SUBString!
2007-10-10 13:00
•
by
Jno
(unregistered)
|
Someone trying to make the language work like ICON, perhaps? ICON uses success and failure to achieve goal-directed evaluation. We lovess it. http://www.cs.arizona.edu/icon/ |
Re: No Thanks, I Prefer SUBString!
2007-10-10 13:28
•
by
Ubersoldat
(unregistered)
|
I find Alicia helps more little children on how to code. Alicia + KungFu = Total Destruction (ain't inspired today) |
Re: No Thanks, I Prefer SUBString!
2007-10-10 13:28
•
by
Pecos Bill
|
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. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 13:47
•
by
Guy
(unregistered)
|
|
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 |
Re: No Thanks, I Prefer SUBString!
2007-10-10 13:49
•
by
rumpelstiltskin
(unregistered)
|
|
[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? |
Re: No Thanks, I Prefer SUBString!
2007-10-10 13:55
•
by
GrandmasterB
(unregistered)
|
|
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!) |
Re: No Thanks, I Prefer SUBString!
2007-10-10 13:58
•
by
GrandmasterB
(unregistered)
|
What he said. |
Re: No Thanks, I Prefer SUBString!
2007-10-10 14:11
•
by
Foosball Girl In My Dreams
|
I am going to start using that one immediately! |
|
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... |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |