Title: VB.NET sucks
Slug: vb-net-sucks
Date: 2006-07-31 11:15:00
Author: Kartones
Lang: en
Tags: Development, Visual Basic .NET, C#, .NET
Description: A rant about the frustrations of working with VB.NET for a C-style developer.

 <p>I know each programming language has it's good and bad things... but man,
after some years working with C/C++ and C#, how the hell am I supposed to work
with VB.NET!</p>
<p>I'm right now working with VB.NET (CLR 1.1), a custom framework/application
blocks that the client/user has for external developments, and third party
web-controls (Infragistics... another day I'll talk about this "amazing"
controls...), so I'm in unknown territory.</p>
<p>I'm trying to do the "better" parts (SQL stored procedures, custom controls
and user controls' logic, learning how infragistics works *in theory*, learning
the custom framework,...), but I have to code in VB.NET anyway.</p>
<p>So apart from the multiple bad things for a C-like developer (constructors,
line breaks, null &lt;-&gt; nothing, [] &lt;-&gt; (), and such things that makes
me have sort of 10-15 syntax errors each time I create a new code-behind or
logic class), one problem we had really pissed me off.</p>
<pre><span style="font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"><span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">date</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> NullableDateTime<br><br><span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">' This works correctly</span><br><span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">If</span> (webDate.Value <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Is</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Nothing</span>) <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Then</span><br>    <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">date</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> NullableDateTime.Null<br><span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Else</span><br>    <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">date</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> NullableDateTime.Parse(webDate.Value)<br><span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">End</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">If</span><br><br><span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">' This throws an exception because false part is processed and tries to parse a Nothing/null value</span><br><span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">date</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">IIf</span>(webDate.Value <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Is</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Nothing</span>, NullableDateTime.Null, NullableDateTime.Parse(webDate.Value))</span></pre>
<p>Why VB.NET processes the false IIF part if the condition is true? I'm doing
the IIf just to do that check BEFORE parsing the WebDate control's value, so if
that value is null/nothing it don't throws an exception. I don't want VB to
pre-check <b>both</b> IIf results!</p>
<p><br></p>
<p>It gets me mad... I hope I won't work again with VB.NET, because I'm too
"C-style" oriented and it's hard to be "switching the chip" from one programming
style to another when some things are down to compiler issues...</p>
