- 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
Lazy? He wrote loads of code! If it was lazy it would use all those pre-packed library functions. That's lazy.
Admin
Function names as return values...hey Fortran did that frist.
Admin
Actually, this is one of the very rare occasions where I'm not saying VB is TRWTF, because I actually find this feature quite practical. In C/C++ I often find myself having to declare a result variable (and thus repeat the result type, remember to return it on every exit etc.). An implicit one can save some boiler-plate typing.
Of course, the naming is secondary, whether it's the function name or a predefined one such as "result".
Admin
Admin
WTF
Admin
I didn't think VB.NET still allowed the "name as return value", I thought they required Return since like 2.0 (maybe even since the first version).
Admin
It still works, you just shouldn't do it.
Admin
Switch statements don't fall-through by default in VB? I thought that was the WTF as I spent several seconds looking for a mention of that in the description.
Admin
This comment applies to Visual Basic in general.
Admin
I was told there would be unicorns...
Admin
They can't in C# either - but because it's meant to look like C, you still have to have an explicit break statement.
Admin
Admin
Admin
Completely by accident, I found the source of the 'decode' part today:
http://www.devx.com/vb2themax/Tip/19163
It's almost OK when the WTF is internal, but when you find it while looking for genuine help it's a little scary...
Admin
Admin
Not strictly true:
string s = "12345", res = ""; foreach (char c in s) { switch (c) { case '3': case '5': res += "(3or5)"; break; default: res += new string(c, 1); break; } } Console.WriteLine(res); // Produces: 12(3or5)4(3or5)
Admin
Won't the decode function go into an endless loop if the input actually contains "&"? I'm not up on VB, but it looks like it decodes it to a literal ampersand, and the exit condition is "no more ampersands"
Admin
Admin
The first argument of Instr is the position to start searching at, so it should, eventually move forward and past the new ampersand, though this code works more by accident than by design.
Admin
Func = Something -> sets the value Return something -> sets the value and returns
Admin
Yes, multiple case labels can be applied to a single block, but that's still not the same as fall-through.
Admin
Because C#'s switch statement essentially boils down to a series of jumps. The VB.NET Case statement compiles down to conditional blocks.
Admin
Admin
They should have used quantum bogodecode:
Function HTMLDecode(ByVal html As String) As String Dim s as String
s = 'A random string selected using a quantum process If html = HTMLEncode(s) Then HTMLDecode = s Else 'TODO: Destroy the universe End If End Function
Admin
Bad and buggy? Sure! WTF-Worthy? Probably not. It's rather at the "oh dear!" level on the scale of fuglyness.
Admin
If using the function as a variable is a return statement. Then doesn't the 4th line return what was passed in before it even gets to any of the code being bashed?
If that is the case, then the rest of the code is unreachable. What's the point in critiquing unreachable code?
Admin
It only sets the value to be returned. It doesn't actually return from the function until you hit End Function.
Admin
The function name works as a variable that is ultimately returned. It is the same as declaring a variable at the beginning of the function and then returning that variable at the end of the function. The function does not exit as soon as the variable is assigned.
Admin
You might try actually looking up the behavior before posting. Then you'd appear less stupid. Your language bigotry would still shine through though.
CAPTCHA: inhibeo. I wish I could inhibeo all the anti-VB bigots.
Admin
Aw, crap.
Admin
Admin
On the plus side, it should be easy to refactor to use the standard library.
I'm sure all the carefully-crafted unit tests will work just right afterwards...
Admin
Note that the Language in this page says: VB4,VB5,VB6,VBS Seems to me that someone brought this code into VB.NET from VB6 (or below) and never cleaned up (Indicated also by use of "Mid" function, among all other old-VB-isms). Without the framework, you'd have to do something like this. So, this is more dinosaur code that a WTF IMHO...
Admin
I know not reading previous comments is kind of de rigeur on TDWTF, but this may be the first time I've seen a question that has been perfectly answered earlier in the thread.
Actually, I quite like VBs approach in a lot of ways. For many trivial functions a result variable is unnecessary, but for longer/more complex functions it's a long way from uncommon to declare your own result variable and return it at the end of the function. All VB does is encapsulate that paradigm in the language.
Addendum (2013-10-22 10:17): Sadly, taking so long to post that other people have already picked up on this makes me look less than smart :(
Admin
That makes more sense. Well, everyones reactions and comments make more sense. Why someone would use that method of returning values in VB.NET still doesn't.
Admin
Admin
Admin
Admin
Written for VB4-VB6 (and VBS) in 2001. So I have no problem with the original code. The real WTF is that someone blindly copied-and-pasted it into a VB.NET project without checking for something newer and better. Likely a straight upgrade project.
Admin
Lazy? Hey, the R-language deliberately uses lazy evaluation, you insensitive clod!
Admin
"A quick and easy way to generate WTF code is to find some deceptively simple problem that’s been well solved, and reimplement a naive solution to the problem.
Here's my puzzle contribution, which I think I posted to the forums a few years ago. Write the body of the following function:
Admin
Less gay bashing plz.
Admin
But yeah, I agree; I think C# has the best compromise (at least without a syntax change); it avoids the confusion with C/C++ semantics for people who expect it to work that way, but also doesn't have the same problems, and the times when you actually want fallthrough are rare enough that the extra syntactic burden is minimal.
Admin
Clbuttic, surely?
And there's absolutely nothing wrong with VB. Nor with the programmers who make such excellent use of it.
OTOH, I see nothing wrong with using the function label (name) as the return value, provided you have a duck-typey sort of language. Why bother explicitly defining the return type?
Not that VB (in any of its incarnations) is an FP language by any stretch of the imagination; but it's no sillier than requiring curly brackets all over the place. It's nothing more than a choice of syntax.
Admin
I just choked on the irony.
Admin
FTFY
Admin
heh. maybe I'm missing something. if you do FunctionName = val, and you do declare the Function with a return type, val is expected to be of that type (depending on your project settings, it may or may not compile).
Admin
Yes, both VB .NET and C# .NET allow "continue"
Admin
I've been hard-pressed to find a case where an If statement isn't better:
Admin