Comment On Way To Go O.O.!

Michelle was hired by a software company to "clean up" an ASP.NET application they have been developing/maintaining for the last three or four years. A lot of the former team members were begrudgingly forced out of their VB6 comfort zones to use new-fangled things like "Objects", so you can imagine the state of the code. There is nothing unique about the quality (or lack-there-of) of this wonderful piece of code, but it was the accompanying comments that inspired Michelle to send it and me to post it ... [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Way To Go O.O.!

2006-03-07 14:51 • by milestogofromhere.com
this is hilarious...coming from a VB shop, that is how a lot of people I woked with would have done it.

Re: Way To Go O.O.!

2006-03-07 14:52 • by Morbii
lol

Re: Way To Go O.O.!

2006-03-07 14:55 • by blah
I'm not a VB programmer, but the code at the bottom looks wrong.  It doesn't handle the radio case , IRadioButtonControl.

Re: Way To Go O.O.!

2006-03-07 14:56 • by Mike J
63148 in reply to 63146
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?!

Re: Way To Go O.O.!

2006-03-07 14:57 • by Joe
5th?

Re: Way To Go O.O.!

2006-03-07 14:58 • by X
63150 in reply to 63146
O.O.Doh!!

Re: Way To Go O.O.!

2006-03-07 15:00 • by YAYitsAndrew
Even the clean solution looks like garbage to me, but I doubt that's the fault of the submitter.

Re: Way To Go O.O.!

2006-03-07 15:00 • by Rafial
63152 in reply to 63148
The solution may have been a tad sub-optimal, but the original programmers gripe has merit...

Re: Way To Go O.O.!

2006-03-07 15:05 • by Michael
63154 in reply to 63147
ICheckBoxControl is an interface. Both the checkbox and radiobutton implement it. I.e., anything that is "checkable" is checked by the replacement code.

--Michael

Re: Way To Go O.O.!

2006-03-07 15:06 • by DSx
63155 in reply to 63147
Anonymous:
I'm not a VB programmer, but the code at the
bottom looks wrong.  It doesn't handle the radio case ,
IRadioButtonControl.




The radio button control extends the checkbox control.

Re: Way To Go O.O.!

2006-03-07 15:07 • by diaphanein
Alex Papadimoulis:


Dim thisControl As Control = FindControl(controlName)

If Not thisControl Is Nothing AndAlso TypeOf (thisControl) Is ICheckBoxControl Then
CType(thisControl, System.Web.UI.ICheckBoxControl).Checked = True
End If


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.

Re: Way To Go O.O.!

2006-03-07 15:09 • by chrismcb

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;

Re: Way To Go O.O.!

2006-03-07 15:09 • by nimrand
63158 in reply to 63147
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.

Re: Way To Go O.O.!

2006-03-07 15:09 • by DSx
63159 in reply to 63156
Anonymous:
Alex Papadimoulis:


Dim thisControl As Control = FindControl(controlName)
If Not thisControl Is Nothing AndAlso TypeOf (thisControl) Is ICheckBoxControl Then
CType(thisControl, System.Web.UI.ICheckBoxControl).Checked = True
End If


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.





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.

Re: Way To Go O.O.!

2006-03-07 15:12 • by John Hensley
'hay guys micro$oft sux am i rite?



Re: Way To Go O.O.!

2006-03-07 15:13 • by Talonius
63162 in reply to 63159
Anonymous:
Anonymous:
Alex Papadimoulis:


Dim thisControl As Control = FindControl(controlName)
If Not thisControl Is Nothing AndAlso TypeOf (thisControl) Is ICheckBoxControl Then
CType(thisControl, System.Web.UI.ICheckBoxControl).Checked = True
End If


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.




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.


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.


 

Re: Way To Go O.O.!

2006-03-07 15:15 • by diaphanein
63163 in reply to 63159
Anonymous:
Anonymous:
Alex Papadimoulis:


Dim thisControl As Control = FindControl(controlName)
If Not thisControl Is Nothing AndAlso TypeOf (thisControl) Is ICheckBoxControl Then
CType(thisControl, System.Web.UI.ICheckBoxControl).Checked = True
End If


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.




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.


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:

expression as type

is equivalent to:

expression is type ? (type)expression : (type)null

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.


 

Re: Way To Go O.O.!

2006-03-07 15:16 • by e.thermal

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.


 


 

Re: Way To Go O.O.!

2006-03-07 15:16 • by Willie
63165 in reply to 63159
The C# 'as' operator will return null if it can't successfully cast its operand.

Re: Way To Go O.O.!

2006-03-07 15:18 • by mike5
Gotta love a language that has "AndAlso" operator...

Cheers, Mike5

Re: Way To Go O.O.!

2006-03-07 15:20 • by Subversion Rocks
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:


/*        
* CCCC RRRRR AAA PPPPP
* CC RR RR AA AA PP PPP
* CC RRRRR AA AA PPPPP
* CC RRRR AAAAA PP
* CC RR RR AA AA PP
* CCCC RR RR AA AA PP
*
* Architecture Violation Removed
* By: {programmer name}
* Hours spent refactoring: X.XX
*
*/

Re: Way To Go O.O.!

2006-03-07 15:24 • by frito
Alex Papadimoulis:



Case Else
strCtrlId = Trim(ctrl.ID.ToString)



Not to mention ctrl.ID is already a String!

Re: Way To Go O.O.!

2006-03-07 15:31 • by JS
Simple rule: Whenever you think the people that designed the framework you're using are idiots, it's probably you who is the idiot.

Re: Way To Go O.O.!

2006-03-07 15:32 • by KeithSpook
63170 in reply to 63164
e.thermal:

Anyone who would ok Vb.NET for corporate development is the true loser here....  ...Everytime I see VB.net code I am thoroughly reminded I made the right choice.



 

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).

Re: Way To Go O.O.!

2006-03-07 15:33 • by Andrew Hare
63171 in reply to 63164
e.thermal:

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.


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?

Re: Way To Go O.O.!

2006-03-07 15:38 • by Jeff S
63172 in reply to 63170
Anonymous:
e.thermal:

Anyone who would ok Vb.NET for corporate development is the true loser here....  ...Everytime I see VB.net code I am thoroughly reminded I made the right choice.



 

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).



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.

Re: Way To Go O.O.!

2006-03-07 15:43 • by Anonymaly
63174 in reply to 63171

Andrew Hare:
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?


In my opinion, a cleaner, more elegant and more easily readable syntax.

Re: Way To Go O.O.!

2006-03-07 15:45 • by Snagglepuss
63175 in reply to 63166

mike5:
Gotta love a language that has "AndAlso" operator...


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?

Re: Way To Go O.O.!

2006-03-07 15:46 • by Gene Wirchenko
63176 in reply to 63172

gotta love these comments


Sincerely,


Gene Wirchenko


 

Re: Way To Go O.O.!

2006-03-07 15:48 • by Anonymaly
63177 in reply to 63175
Snagglepuss:

mike5:
Gotta love a language that has "AndAlso" operator...


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?



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.

Re: Way To Go O.O.!

2006-03-07 15:48 • by KeithSpook
63178 in reply to 63172
Jeff S:
Anonymous:
e.thermal:

Anyone who would ok Vb.NET for corporate development is the true loser here....  ...Everytime I see VB.net code I am thoroughly reminded I made the right choice.



 

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).



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.


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.

Re: Way To Go O.O.!

2006-03-07 15:50 • by DZ-Jay
63179 in reply to 63169

Anonymous:
Simple rule: Whenever you think the people that designed the framework you're using are idiots, it's probably you who is the idiot.


Idunno... implementing short-circuit boolean evaluation as an unintuitive "AndAlso" seems pretty idiotic to me.


          -dZ.


 

Re: Way To Go O.O.!

2006-03-07 15:51 • by Chris F
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.

Re: Way To Go O.O.!

2006-03-07 15:56 • by Anonymaly

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.

Re: Way To Go O.O.!

2006-03-07 15:57 • by Jeff S
63184 in reply to 63178
Anonymous:
Jeff S:
Anonymous:
e.thermal:

Anyone who would ok Vb.NET for corporate development is the true loser here....  ...Everytime I see VB.net code I am thoroughly reminded I made the right choice.



 

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).



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.


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.


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)

Re: Way To Go O.O.!

2006-03-07 15:58 • by Vector
63185 in reply to 63166
Anonymous:
Gotta love a language that has "AndAlso" operator...

Cheers, Mike5


That's the first time you'll hear this athiest say Amen.

Re: Way To Go O.O.!

2006-03-07 15:58 • by WangTF
63186 in reply to 63179
DZ-Jay:

Anonymous:
Simple rule: Whenever you think the people that designed the framework you're using are idiots, it's probably you who is the idiot.


Idunno... implementing short-circuit boolean evaluation as an unintuitive "AndAlso" seems pretty idiotic to me.


          -dZ.



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.

Re: Way To Go O.O.!

2006-03-07 16:01 • by Jeff S
63187 in reply to 63185
Vector:
Anonymous:
Gotta love a language that has "AndAlso" operator...

Cheers, Mike5


That's the first time you'll hear this athiest say Amen.


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.

Re: Way To Go O.O.!

2006-03-07 16:04 • by wintermyute
63188 in reply to 63171
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?

Re: Way To Go O.O.!

2006-03-07 16:04 • by Pope
63189 in reply to 63174
Anonymous:

Andrew Hare:
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?


In my opinion, a cleaner, more elegant and more easily readable syntax.



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. 

Re: Way To Go O.O.!

2006-03-07 16:06 • by Anonymaly
63190 in reply to 63186
Anonymous:

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.



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'.

let's hear it for the ladies

2006-03-07 16:11 • by januarys

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.

Re: Way To Go O.O.!

2006-03-07 16:11 • by Emmanuel D.
63192 in reply to 63186
Anonymous:

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.



It would also be better, considering that || is more like "or" than like "and"... :P

Re: Way To Go O.O.!

2006-03-07 16:13 • by Anonymaly
63193 in reply to 63189
Pope:
Anonymous:

Andrew Hare:
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?


In my opinion, a cleaner, more elegant and more easily readable syntax.



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. 



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.

Re: let's hear it for the ladies

2006-03-07 16:15 • by Fake Gene Wirchenko
63194 in reply to 63191

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

Re: Way To Go O.O.!

2006-03-07 16:15 • by zip
63195 in reply to 63189
Pope:
Anonymous:

Andrew Hare:
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?


In my opinion, a cleaner, more elegant and more easily readable syntax.



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 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.


 


 


 


 

As is just like casting, even performance wise

2006-03-07 16:15 • by Brian Kemp
63196 in reply to 63163

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:

expression as type

is equivalent to:

expression is type ? (type)expression : (type)null

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.


 

The best part is that the as operator seems to just do the try-catches for you...well, it feels like it.  There's noticable lag in my debugger when I get a null result from an as operator, which would be the exception being thrown then caught before your code ever sees it.

C# version of the code:

Control thisControl = FindControl(controlName);
if (thisControl != null && thisControl is ICheckBoxControl)
{
    ((ICheckBoxControl)(thisControl)).Checked = True;
}

Re: Way To Go O.O.!

2006-03-07 16:15 • by Pope
63197 in reply to 63190
Anonymous:
Anonymous:

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.



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'.



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.

Re: Way To Go O.O.!

2006-03-07 16:19 • by Alex Papadimoulis
63198 in reply to 63188

wintermyute:
VB.NET (as supported in VS.NET 2003) does not support XML comments without a VS plug-in. 



//open up a connection to the database server


WTF does that say?



//<comment>open up a connection to the database server</comment>


Ahhh ... so much clearer ...


 


(Yes, I know what you meant -- just a joke)

Re: let's hear it for the ladies

2006-03-07 16:24 • by Djinn
63199 in reply to 63191
januarys:

I'm just excited that the submission was made by a woman. Three cheers for smart chicks!!!



I second your base sentiment, but it's wrong of you to associate programming with "smarts". This industry does suffer from sausagefestivess.
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment