- 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
this is hilarious...coming from a VB shop, that is how a lot of people I woked with would have done it.
Admin
lol
Admin
I'm not a VB programmer, but the code at the bottom looks wrong. It doesn't handle the radio case , IRadioButtonControl.
Admin
Hah, I'm glad she left the original code in there, though it needs a long comment in the same tone about learning the language you're trying to develop in.
'Way To Go Programmers !!! 'Gotta love these programmers who don't KNOW 'wtf language they're trying to develop in. 'but you know, 10 minutes of reading would just be 'TOO hard wouldn't it?!
Admin
5th?
Admin
O.O.Doh!!
Admin
Even the clean solution looks like garbage to me, but I doubt that's the fault of the submitter.
Admin
The solution may have been a tad sub-optimal, but the original programmers gripe has merit...
Admin
ICheckBoxControl is an interface. Both the checkbox and radiobutton implement it. I.e., anything that is "checkable" is checked by the replacement code.
Admin
The radio button control extends the checkbox control.
Admin
IMHO, the above code is also a WTF. The type of the control is being checked twice. The below C# is the best way of doing the above logic.
ICheckBoxControl c = FindControl(controlName) as ICheckBoxControl;
if (c != null) c.Checked = true;
Not having used VB.Net, I'm not sure if it has an equivalent to the 'as' operator, but it doesn't, its a crime against .Net.
Admin
Based on the comment I expected to see code along the lines of:
if (checkbox)
checkboxobject.checked = true;
else if (radio button)
radiobuttonobject.checked = selected;
Admin
Actually, the second block of code is correct as far as checking the control's type, because RadioButton implements the ICheckBox interface (the 'I' in the name is .NET's naming convention for interfaces). So, testing for that interface would succeed on both radio buttons and checkboxes. This only makes the original programmer's taunt all the more hilarious, because you DON'T need to know which of the two types of controls it is to access its Checked property. You simply access it through the interface, which is why the interface is there in the first place.
Admin
Off the top of my head, i would think that this code would throw an exception if controlName was not a CheckBox or RadioButton, while her code would fail gracefully.
Admin
'hay guys micro$oft sux am i rite?
Admin
Nah, the "as" keywords attempts to convert to the requested type. If the attempt fails no exception is thrown; instead, null is returned. Thus his check for null on the second line.
Admin
Nope - the as operator returns null if the type cast cannot be completed. From http://msdn.microsoft.com/library/en-us/csref/html/vclrfAs.asp?frame=true:
The as operator is like a cast except that it yields null on conversion failure instead of raising an exception. More formally, an expression of the form:
is equivalent to:
except that
expression
is evaluated only once.Note that the as operator only performs reference conversions and boxing conversions. The as operator cannot perform other conversions, such as user-defined conversions, which should instead be performed using cast expressions.
Admin
Anyone who would ok Vb.NET for corporate development is the true loser here. Years back when .net came out I was able to sucessfully move all of my VB6 programmers over to C# in a matter of days. After about a month working with C# I sent one of my programmers a VB6 program to fix a bug and he almost quit on me, begrudgingly he pulled up VB6 and went to work on it. Then he decided that perhaps we were making a bad decision moving everything over to C# instead of VB.net (he thought losing VB skills was a bad thing) so he took a course on VB.net, after the course he agreed with me C# was the way to go. Everytime I see VB.net code I am thoroughly reminded I made the right choice.
Admin
The C# 'as' operator will return null if it can't successfully cast its operand.
Admin
Gotta love a language that has "AndAlso" operator...
Cheers, Mike5
Admin
This is why I use SubVersion now everywhere. Anytime I see someone checking in bullshit like that get's caught, tagged and released. I usually also prepend in the XML comments something like:
Admin
Not to mention ctrl.ID is already a String!
Admin
Simple rule: Whenever you think the people that designed the framework you're using are idiots, it's probably you who is the idiot.
Admin
Correct. Vb.NET is an attempt at a programming language, and it is a bad business decision to write web applications in a programming language (or an attempt thereof).
Admin
That's stupid, its all the .NET framework. There are only a handful of things that you can do in c# that you cannot do in vb.net. Explain to me which aspects of c# would be neccesary to prevent production from grinding to a halt if you were forced to use vb?
Admin
Two of the most moronic, ignorant posts I've ever seen here ... which is actually quite an impressive achievement at this site.
I hope at least one of these is sarcasm.
Admin
In my opinion, a cleaner, more elegant and more easily readable syntax.
Admin
Yeah, that kind of threw me. What's the difference between "AndAlso" and "And"? Does it have something to do with lazy vs strict evaluation?
Admin
gotta love these comments
Sincerely,
Gene Wirchenko
Admin
It's a "bitwise" And versus the "logical" And with left-to-right associativity with early drop-out from expression evaluation if any of the terms on the left evaluate to false.
Admin
Yes, I would say that mine is sarcasm. I would think that most people would have caught that. Sorry I over estimated... I'll never do it again.
Admin
Idunno... implementing short-circuit boolean evaluation as an unintuitive "AndAlso" seems pretty idiotic to me.
-dZ.
Admin
The funny part is how they've confused an attribute of the type system with the object oriented paradigm. There are dynamically-typed OO languages where they could write code like this that would function. Ruby and Smlltalk are just two examples.
Admin
BTW, there is nothing wrong with the re-written VB.NET code. The ICheckBoxControl interface (which only exists in .NET Framework 2.0) is implemented by the CheckBox class. The RadioButton class, in turn, derives from the CheckBox class, therefore, inherits the interface. Both RadioButton and Checkbox, in turn, have a Checked property.
Given an instance of an object, the 'Is' comparison operator is used to determine if it can be coerced to an ICheckBoxControl interface. If so, the code then changes the type (equivalent to a C# cast or similarly the C# as operator) to the interface and sets the 'Checked' property. Nice, clean, and obviously object-oriented.
Admin
Whew ... thank you, Keith ! The problem with this site is you have to be really clear when you are being sarcastic .... some of the posts I've seen here are pretty frightening! (e.g., the one you quoted and responded to)
Admin
That's the first time you'll hear this athiest say Amen.
Admin
AndAlso would seem to be more intuitive than ||. I think the whole point of this WTF is you should learn the language before criticizing it.
Admin
We've covered this a million times here. They left "And" as a non-shortcurcuting operator for backwards compatability with previous versions of VB. They added "AndAlso" to introduce a short-circuiting And operator to VB.NET. Same with "Or" and "OrElse".
You can say that maybe the names are a little silly, or they could have used symbols like in C#, but if you don't understand it, don't criticise it.
Admin
The main thing (besides the fucking god-awful syntax that makes me want to vomit blood forever) that drove me to C# was the lack of commenting support -- VB.NET (as supported in VS.NET 2003) does not support XML comments without a VS plug-in.
/sarcasm?
Admin
Interesting. I find VB.NET to be more closely related to actual language... by far. I started in C++ and found myself continually pulling my hair out due to braces and semicolons.
More elegant? Why? Because it makes you feel like you're programming a space shuttle?
Cleaner? Why? Is this not due to the programmer's abilities?
I'm always hearing why everyone should use C# instead of that "toy language" VB.NET, and I never hear why. AndAlso, I've found I can accomplish the same tasks in both languages in the same amount of time.
Admin
Of course "AndAlso" would be much more intuitive than "||". That's because "||" actually maps to "OrElse" in VB.NET. Yes, I knew you meant "&&". However, both those operators are 'mnemonics'. I prefer using a mnemonic; to me, it makes the code seem less verbose or 'busy'.
Admin
I'm just excited that the submission was made by a woman. Three cheers for smart chicks!!!
p.s. fake Gene Wirchenko, you've got to do better than that if you aspire to Wirchenkism.
Admin
It would also be better, considering that || is more like "or" than like "and"... :P
Admin
Whoah there Cowboy. I did remember to note that it was my opinion. No, I do not find that it feels remotely anything like programming a "space shuttle"; that's quite an odd comparison.
However, having used assembly language, C and C++ for quite some time, I have become accustomed to mnemonics and terse reprentation of complex expressions without the need for it to read like "Green Eggs and Ham".
It was a matter of becoming accustomed to that programming style. Learning C# has made me more productive "out of the box". Having used Visual Basic 6.0 for quite some time, I can read VB.NET as well --it just hurts my eyes.
Admin
ok, I admit it, it was fake. But I always wanted to be like Gene Wirchenko when I grow up. He is my role model and inspiration.
Sincerely,
Fake Gene Wirchenko
Admin
I find c#/c++/java/anything not VB cleaner and more elegant because it is less verbose, using brackets instead of words for delimiting blocks. I also think "WEnd" is totally unnecessary.
Admin
C# version of the code:
Control thisControl = FindControl(controlName);
if (thisControl != null && thisControl is ICheckBoxControl)
{
((ICheckBoxControl)(thisControl)).Checked = True;
}
Admin
That's a really interesting point... like being able to pick out numbers on a page of text because they stand out when imbedded in regular text. Hmm. Thanks.
Admin
WTF does that say?
Ahhh ... so much clearer ...
(Yes, I know what you meant -- just a joke)
Admin
I second your base sentiment, but it's wrong of you to associate programming with "smarts". This industry does suffer from sausagefestivess.