The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,909 other followers

Archive for July 3rd, 2014

Interesting comment by Joseph G. Mitzen delphi on my “Delphi – for … in on enumerated data types” post

Posted by jpluimers on 2014/07/03

Joseph G. Mitzen posted a very interesting (and elaborate <g>) comment on a post from me in 2009: Delphi – for … in on enumerated data types « The Wiert Corner – irregular stream of stuff.

The crux of his post is about consistency of your tools. And clearly, the Delphi team has some work to do in that regard especially when compared to the Python world where consistency is key (and takes a lot of time to introduce new features as a side effect).

He refers to the ADUG post For-in Enumeration | Australian Delphi User Group Members by DaddyHPriest that lists a number of areas where Delphi does not have enumerator support for.

Which reminds me I promised to publish some more enumeration demos showing what kind of code could be eliminated if things became more consistent.

Hopefully this summer gives me a bit more time for that (:


via: Delphi – for … in on enumerated data types « The Wiert Corner – irregular stream of stuff.

Posted in Delphi, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, Software Development | 4 Comments »

VB.NET: If you want to cast use DirectCast or TryCast; if you want to convert, use CType

Posted by jpluimers on 2014/07/03

I’ve done quite a bit of VB.NET maintenance lately.

Most of that code was riddled with CType, both for conversions and casts. Quite a bit code had Option Explicit and Option Strict Off. A lot of those CType constructions had empty Try / Catch / End Try blocks around them.

Those empty catch blocks are a code smell. They pretend to be able to survive any exceptional disaster, but in practice you can’t. You have to indicate what kinds of disasters you can handle, for instance if a meteorite hits your data center (thanks George Stocker).

Turning off Option Strict can be OK under many circumstances (the default is off), but having Option Explicit off is usually a code smell as well, just like On Error Resume Next (which was also in plenty of the source code).

I do understand a lot of VB.NET source comes from people having programmed in VB 6, VBScript or VBA for a long time where those constructs were more common. But writing code in the 21st century is much more about writing code that you can prove to be right. Having proper error handling and compiler type checking is a big part of that.

It pays to go with the idiom, for example read the good and bad ways of – Safest way to check for integer.

Back to CType: basically you have do distinguish between conversions and casts. The reason is that when you know it will be a form of cast, CType is way to expensive. And if you know you will be doing conversions, than casting is not what you want.

Casting Read the rest of this entry »

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, Development, Software Development, VB.NET, VB.NET 10.0, VB.NET 11.0, VB.NET 7.0, VB.NET 7.1, VB.NET 8.0, VB.NET 9.0 | Leave a Comment »

%d bloggers like this: