- 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
I believe all Oracle functions are PL/SQL. Not many people do it, but it's possible to compile Oracle functions through C: http://www.lc.leidenuniv.nl/awcourse/oracle/appdev.920/a96624/12_tune.htm#48419 So, I suspect that the SUBSTR() function was written in C, and runs the same as a PL/SQL or SQL function.
The above link also explains that it is slow to move from the PL/SQL engine to the SQL engine. The SELECT in the function call causes a switch to SQL; this is the WTF.
Admin
Yes, C can have a boolean type. I don't think the C++ bool type is any different; it's just required by the ISO standard to exist.
typedef unsigned int bool; #define TRUE 1 #define FALSE 0
bool done = FALSE;
while (! done) { ... }
Admin
Incidentally, I am pretty sure the code snippet we see is just fallout from some form of TRUE, FALSE, MAYBE enum.
Admin
That actually makes some sense. Store procedures can be called by application programs and return a cursor.
An embedded C program can run it, and just know to fetch the rows. It may need to know the rows' record structure, by not the SQL that made it. EXEC SQL CALL STORED_SET(:CUR); ... EXEC SQL FETCH INTO :ROW FROM :CUR; ... EXEC CLOSE :CUR; A DBA can write and tune the SQL in the STORED_SET() procedure independently. The best person writes the C or SQL parts, respectively.
Admin
Here is why I sometimes use if (x == true)...
Much of our legacy code was written by unix weenies who were raised on scripts. For scripts, success is indicated by zero, failure by a non-zero error code.
So, a test for success as written by these guys, looks like if (foo()) { failure handler } else { success handler } ... which is the opposite of the way c, c++, etc work.
Now... you can argue (as I do) that this is WTF code; nevertheless, it is still all over the place in our code base, so when I write logical code which goes if (foo()) { success handler } else { failure handler } it confuses all the unix weenies.
So I often write if (foo() == true) specifically not to confuse the unix weenies.
More generally, that means I am less likely to rely on a stateful test of a boolean for any reason, preferring the more obvious test against a constant/literal -- again, just to make clear what is going on.
Admin
Wow, that IS general -- it even properly handles fuzzy logic and expert systems! (FALSE=0, TRUE=255, act if truthiness is greater than or less than a given threshold...)
Admin
Admin
Apparently he meant procedural programming. Of course, QBaseic is not the best environment to learn the functional one.
Admin
At least in C++ (and I think also in ISO C99) bool is not the same as unsigned int. Older implementations often use such constructs, yes. For example Visual C defines in some older headers
(*shudder*). However, while a boolean in C++ and C99 is always implicitly convertible to an integer value, they are not the same. Furthermore, the lowercase versions of "bool", "true" and "false" have to be reserved keywords, not #define'd.So, in strict ANSI C++ (and until proven otherwise, I assert the same to be true in C99), the following is indeed correct and the if clause has to be evaluated.
In a broken implementation however, where bool is typedef'd to int and 'true' is just defined to be 1, the comparison (apparently) fails. This is not a problem of the standard, but of the implementation, but sometimes it just cannot be helped. Just don't use such 'sensitive' (and reduntant) comparisons in C/C++. Sometimes verbosity helps and adds clarity, in this case, it can actually hurt.Admin
The second function modifies a boolean variable in-place. Sure, it could be rewritten as a one-liner, but that doesn't mean the function itself is useless at all.
Examples:
Admin
Fix the obvious omission in the last line.
Many of the posts here are amusing, but Alex seems to consistently overrate his own own rather narrow experiences. These IT people hack out a few websites, and then suddenly they're wizened sages about all forms of programming.
Admin
if ( x != y ) { whoops }
In C++, C99, and other languages with true boolean types, the only values that a boolean can have are 'false' and 'true'.
Admin
There is something no-one has yet mentioned of the SUBString-function...
First some background: Oracle still has some this that are possible on the SQL-engine, but not on PL/SQL-engine. For example, getting the next value of a sequence used to be such a thing up until 9iR2 (at least, I think they've changed it in 10g so that you can just assign "my_seq_nextval := my_sequence.nextval" instead of doing it the hard way "select my_sequence.nextval into my_seq_nextval from dual". This is where I would/am/will be writing a function "get_my_seq_nextval" to do the stupid thing so I didn't have to do it again and again.
I'm just throwing guesses here, but ain't it just a possibility that on some century old system running Oracle 6 (read: something "old as time itself") there was no possibility to directly call SUBSTR from PL/SQL - and the code just stayed in the codebase as a relic from the past.
Admin
Ok. Who did it? Who stole "ng" from my "things".
Captcha: burned
Admin
I'm a Unix script weenie, too. :^) The reason Unix programs have an exit() value of 0 on success and nonzero on failure is that usually there's only one way for a program to succeed and many ways it can fail. (There are documented exceptions, like cmp(1).) But this success/failure mechanism is also used for truth: true(1) always "succeeds," and false(1) always "fails."
Admin
To paraphrase Terry Pratchett in one of the Discworld novels: "all statements are true for some value of true".
Admin
Admin
it's something like this: Task: convert lower character to upper character
Seems that some programmers are paid per code-lines ;-)))
Admin
Isn't that what DEFINT A-Z was for? And then use "var!" if you really did want a float?
Admin
OK, I'll take TRUE to be the maximum value of an integer on the platform and FALSE to be one less than that.
Admin
And some of the IT people here post moronic comments about people whose background they know nothing about, probably trying to inflate their own experience levels. Unfortunately, they tend to expose themselves by the stupidity levels of their comments, as you have done. At least you made it very clear very quickly, so as not to waste anyone's time trying to figure out the levels of your idiocy. Thank you for that, at least.
Admin
So that's why I always got everything backwards!
Captcha: pointer
Admin
The ! operator is not used, because it is a software patent:
http://profesores.matcom.uh.cu/~kyrie/documents/appft1.uspto.gov/isnot.html
Admin
A few well-placed EXCEPTION WHEN OTHERS THEN NULL; blocks sprinkled through your code will take care of that.
Admin
Me too... Not in QBasic though ...
Spectrum had a great Basic and an editor where you had only to press G and GOTO was already there ...
Admin
You hit the nail in the head with that comment, one common (and potential) problem is that the "developer" will never realize those limitations and continue to focus on the "language", eventually creating monstrosities such as the one shown in this article.
Admin
probably some rogue substring function ...
Admin
Admin
The real WTF it that they used stored procedures. Stored procedures are EVIL. PL/SQL is a very limited language in comparison with modern OO languages. It always ends up with having some part of business logic in Java/.NET application and some part in stored procedures which is a BAD THING. Performance of SP also often sucks if compared to dynamic SQL queries. Use SP only when really needed.
Admin
VERY private
Admin
Actually, in C99, bool, true, false are not keywords. In <stdbool.h> there are lines:
But _Bool is a true boolean type. As for BOOL, it's a Platform SDK type, and is still there.
Admin
Actually, in C99, bool, true, false are not keywords. In <stdbool.h> there are lines:
But _Bool is a true boolean type. As for BOOL, it's a Platform SDK type, and is still there.
Admin
Admin
Yea... Don't let the door hit you on your way out, Piotr.
Guy
Admin
Ok, so ANSI C++ and ISO C99 do differ in this regard, but not signifantly (whew). In C++, true/false are specified explicitly as the boolean literals, whereas 'bool' is the corresponding type specifier. Again something new learned, thanks ;)
However, even it being a typedef to _Bool in C99 fortunately does not invalidate the main point: it is still a specific boolean data type, and not the same as int, therefore '(bool) x' has to be identical to 'true' for any non-zero value of x. Unfortunately, the second point also remains very true: do not bet on it that your specific implementation behaves correctly in this regard :(
Ah, the wonderful world of (programming) language evolution...
Admin
I really don't see what's wrong with the toggle function. It would be useful as a function pointer. I would also consider using it for the sake of clarity, heck even boost has a next() and prior() functions implemented as ++argument and --argument.
Sure the implementation could be done in one line, but would that really change anything? It works, has no side effects and readable to people that dont use C/C++ like languages on a daily basis(afaik the ! operator doesn't exist in say vb or delphi).
Admin
Never mind the (bool)x. We're the Sex Pistols!
e.
Admin
Bwahahahahahaahaahhhahh!!!
Admin
So, has PL/SQL had substr since the beginning? I recall having done lots of similar'ish hacks to get around missing features and sometimes old habits die hard. (still wtf, no-one uses forms 3 anymore, right?)
Admin
I started on Logo, then moved to Basic on an old Amstrad after finding out that I could list the code for any of the games I had. When my Dad upgraded to a 386 I moved onto QBasic. Eventually, with his 486 (which could run Windows 95 when it was released, it was GEM on the 386 and 3.1 on the 486 until then, CP\M on the Amstrad) I got into C++ via Deitel Deitel which I got from the local library. It gave me a thoroughly fine explanation of O-O coding, and was very good at explaining nuances of the language. I moved to C++ to find out about OpenGL, and, of course, a lot of the basic parts of graphics programming (such as double-buffering) I already knew from QBasic. I did a great little sniping game in it which included optional swaying grass (affected by wind velocity). Unfortunately, with the full complement of grass at about 500 blades, randomly swaying every frame, my Dad's PC ground to a halt. But it was pretty. Now I enjoy C#, although most of my work is still done in C++ and Win32.
Admin
You mean like most people?-)
Admin
Aww, come on! This is the most ridiculous sattement-that-can-be-considered-as-VB-bashing I heard ever.
Admin
The comment refers to C-like languages with operator!() producing code intelligible to users of languages such as VB/Delphi/presumably Cobol that prefer the (slightly) more verbose "[Nn]ot." Perl, being perl, gives you the choice of line-noise or English. I rather wish that ole Larry had also offered multi-lingual support, eg
Boy, programming in floating-point (or "point flottant") arithmetic would be a breeze.Jeez, if your skin was any thinner, you'd be standing in ten pints of your own blood by now ...
Admin
Reminiscent of the endless debates about whether language x "really is objected oriented" ie, whether language x really is smalltalk. BASIC is not by common definition a functional language, but it is a language in which one can write functional (or object oriented) programms, or (perhaps it comes to the same thing) a language in which one can write a functional language.
Admin
#define TRUE 1 #define FALSE 0 int flag; ... flag=TRUE; ... flag=1-flag; /* toggle */
I really like the TRUE+FALSE-inVal solution earlier though, who doesn't like arbitrary values for TRUE and FALSE!
Admin
Note that I am not using a "language x is not smalltalk" argument here. I am not holding up LISP or Haskell or anything as the "one true FP language" that every other language must imitate precisely. I am treating FP as a very broad and generic concept, and indeed one that can certainly be used to some extent in languages like C that are not traditionally considered FP languages. However, it cannot be used in BASIC.
This is not the same thing at all. You cannot write FP in BASIC. If you write a functional language in BASIC and then use that, then you are no longer using BASIC.To claim that you are still using BASIC, when you are using a functional programming language written in BASIC, is like claiming that C# programmers are all writing machine code, because C# is implemented in C++ which is compiled down to machine code.
The IF/THEN statement was implemented in all BASICs, right from the very first version in 1963. Not sure about the history of proper functions and procedures, but they were certainly available in the first BASIC I ever used, which was in about 1984; I don't think I ever used a single GOSUB in all the years I programmed in BASIC.Admin
The real WTF is that the substr function takes the following arguments:
string, startpos, length
as opposed to
string, startpos, endpos
and that nobody noticed or mentioned this in the comments.
Admin
You must be smoking something. The real problem is java/.NET code trying to do what the database does, only "better" which is neither desired or achievable.
Admin
No. The .NET/Java application server is for PROCESSING, the database is for STORING data. Procedural languages for stored procedures are so limited, that programmers must write stupid SUBString functions as workarounds. Besides letting DBAs touch your business logic code is a VERY BAD IDEA.
Admin
Here's the long version...
Early BASIC: GOTOs
QuickBASIC: multi-line conditionals