- 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's not l33t at all :(
It should've been: MsgBox("File not found!")
Admin
if comment_frist = true then doThings() else if comment_frist = false then doOtherThings() else MsgBox("omfg haxor alert") End --terminate program end if
Admin
Someone in 2007 already commented that they found this in their VB program.
Admin
You can run into issues in VB (pre-.NET) if you call into other components (COM or OCX or the like) that don't treat a VB Boolean as an integer that should be -1 or 0. If the component, for instance, stuffs a "1" in there (like a variable Value), then
will be true, but will also be true, because is the bitwise-not of 1, which is -2, which still isn't 0.This has lead to code along the lines of:
Along with of course a long comment about why it was needed.
Admin
Admin
winrar!
Admin
Even scarier, he used the search field in the top right to search for "omfg haxor alert!" >:)
Admin
Admin
Why? a simple
should perfectly suffice.Captcha: ratis - my ratis [sic]
Admin
If only Rena would have been writing PHP, then a similar construction might even come in handy...
Admin
The real WTF here is Visual Basic used together with the term professional programming ...
Admin
And now with nullable booleans...
Admin
I'll just leave this here...
For the lazy, it's a definition of MsoTriStateEnumeration, which is a tri-state Boolean with 5 possible values of which only two are supported. Just let that sink in for a while so you can appreciate the awesome WFTery of it.
Admin
An actual normalizing code would do this instead:
Admin
But today, yeah, WTF. Nonetheless, I know a worldwide company using a VB6 (yes, VB6) application for realtime (i.e. 1kHz+) data collection, because that's what their non-programmer engineers wrote 15 years ago and they won't let go of it.
Admin
Admin
Since True in VB (and VB.NET IIRC) is -1, when I want to convert a boolean to an integer I usually end up multiplying it by True so I get 0 or 1 as an output, like other, more sane languages. Fun.
Although VB.NET could have True as 1 for all I know, but I multiply it by True just in case...
Admin
From that page:
Instead of What-The-F, it's a What-Sa-F job?
Admin
This is simply standard practice in the industry. Consider one of the most central functions in the Windows API, namely GetMessage. The description is available here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644936(v=vs.85).aspx
Notice that it returns the type BOOL, suggesting a boolean value.
Now read the description of the return value.
Admin
A couple jobs ago, I worked for a place which preferred VB to C#.
Going in, I thought, "OK, it's the solutions to problems which make the job interesting, not the language in which they are written. So, it will be OK to work in VB."
I could not have been more wrong.
In addition to working with (by far) the least talented group of people with which I've been unfortunate enough to have an association, the main application was VB6 (although the newer things were .NET, somewhat less bad).
Admin
OMG you are sooo cool, can I kiss the ground you walk on?!?!
Bitchin' about vb was cool 10 years ago, vb.net is a decent language, and if you cannot make decent software with it, the problem lies with you...
Now run along and play...
Admin
Well, "professional" in the same sense that a $15 streetwalker is referred to as a "professional". i.e.: "does nasty things for money".
Admin
Rena forgot FILE_NOT_FOUND.
Admin
So does this mean two rights make a wrong?
Admin
-or-
No, but three rights make a left.
Admin
No, but three rights usually come out to a left.
Admin
How in the hell would you even remember this? haha
Admin
Wow, I wrote C++ Windows apps for years. while(GetMessage()) is a common core for many of them.
Of course, this is a legacy of C not having a true boolean type and not being typesafe
Admin
I would even go bit farther. The problem with VB6 and prior was never the language. Yes it some pretty epic syntax fails, but what language does not?
Truly the real problem with classic VB is error handling. If it was not for the On Error Goto paradigm, which totally destroys the structure of what otherwise might have been well organized quasi OO programs with VB's limited classes.
The real trouble with VB though was it was a little to easy to get into something beyond your depth. Getting beyond a "hello world" in C++ pretty much requires at least an hour of reading for someone who has never written a line of code before. Where you are bound to pickup a little something on typing and scope. VB would let people build half their (trivial) forms application drag and drop and glue it all together with global variables of type variant.
It would mostly work to, and then said app would grow to something less trivial with lots of cargo cult cult code and it would still mostly work. By this point the author would think they knew this programming stuff and start tackling larger and larger projects until they hit a proverbial brick wall somewhere at 200mph.
Admin
Makes me think of a nice feature in excel: This formula looks safe doesn't it: =IF(B1=0;0;100/B1) First check if what you're dividing by is not 0 (as you should).
Now if you put the boolean false into B1... then false=0 resolves to false, but when dividing by false it gets converted to 0, en results in a divide by 0 error.
So maybe the author was right to expect this kind of behavior from microsoft :p
Admin
if(the "feature" of encoding false as 0 and true as -1 is documented){ How do they document the behaviour if the value is neither 0 nor -1 ? Do they document what optimizations the compiler can do when "implausible" else clause is detected? }
also multiplying by True is wrong from the dimensional point of view. You should divide by it! This way it would work for any value they used for true... sadly it won't work for false.a
Admin
I used to use programs like that too. So when I was one of the coders on a very indie game project, I wrote code like this:
void entity::adjust_entity_hp(int damage) { int oldvalue = hp; if (damage == 0) return; hp -= damage; assert (oldvalue != hp); return; }
Admin
Y'know, "if" takes a boolean. You have a boolean. There's no need to compare it to the literal true or false.
Admin
I would disagree with this point. "On Error Goto" was not bad, it was just so commonly misused. Think of the "Try Catch Finally" pattern and translate those under the cover jumps to VB6.
On Error Goto Catch 'Do something Goto Finally :Catch 'Trap your error :Finally 'do some Cleanup
This works and mimics the Try-Catch-Finally that most people say is just fine. Remember all these are simply Jumps from one code location to another within a particular scope.
As for your second statement which I didn't quote. Yes VB6 made it far to easy for laymen to mock up something and call themselves programmers, the strength of VB6 was also it's own biggest problem.
Admin
Hence our propensity to check (FALSE != someBoolean) in C++ when faced with a BOOL type.
We know for most applications 0 = false, and everything else = true.
For anything that likes to return with a BOOL to indicate result but also failure, usually there's a define.
#define API_FAILED -1.
So, you would say:
int result; if (API_FAILED == (result = ApiMethod(args))) { // handle failure } else if (result != FALSE) { // result true } else { // result false }
Good ole days eh?
Captcha "jugis" - The folk food in some native culture made from the jugular from a rival.
Admin
No no no no... Go back 1 space, do not pass go, do not collect $200.
That only handles an error if one is explicitly stated and/or returned through the stack to this location. Any errors that don't bubble up, don't get caught here.
Not only that, you have to track layers of errors from any returning program. Oh it's hell.
try-catch-finally unwinds the stack, so any exception through at any point in the stack jumps to the innermost catch, at which point it can be rethrown to bubble up. Since the exception is an object, it never loses its contextual data.
Plus, GOTO breaks all logic. When using the stack wisely, one can bake in exit logic, so as the stack unwinds files are automatically closed, etc, even though there was an exception. GOTO skips over all this, leaving any exit logic undone.
It breaks RAII in C++, and it would totally break garbage collection in .NET if it worked the same way as VB6.0.
They aren't the same. t-c-f is not a goto.
CAPTCHA refoveo
Admin
It's true, and that's the advice that’s almost always given (use "if not value" instead of "if value == false"), but I don’t think it's that important.
When I have to code a conditional my thought process is "now we execute this only if value_x is 3", or "now we execute this only if value_y is not 'foo' ", or "now we execute this only if value_z is true". So isn't it natural to type the code in a similar way every time? Compare:
Doesn't one of those expressions seem unnecessarily odd?
Admin
Personally, I'd keep adding that extra else statement, just to amuse anybody else who looks at my code. ;)
Admin
if (savant == true) { msgbox('you are a savant'); } elseif (savant != true) { msgbox('your mind is a infinite junkyard'); } else { msgbox('you know how to use Google'); }
Admin
Admin
Another way to avoid the issue is to leave the VB variable untyped instead making it an explicit Boolean. Fix one bad thing by another...
Admin
It drives me crazy when people compare booleans with constants. It's like their mind can't process code unless it reads like natural language. And if that's the case then I'd say you're in the wrong profession.
Admin
Admin
Yes you some pretty epic grammer fails...
captcha: haero (a japenese hero)
Admin
That's like saying goto was not bad, it was just so commonly misused.
Yes, disciplined programmers can use primitive control flow constructs to emulate higher level ones. Programming languages that encourage you to use primitive control flow constructs are still bad outside of very specialized circumstances.
Admin
so now that you've taken a programming class in high school, are you going to build a website for your neighbor?
anyways, here's my version:
Admin
FTFY
Admin
My true is truer than your true.
Admin
Admin