Geeks With Blogs
Mark Ritchie

At the recent PDC in LA I had the opportunity to speak to some of the C# team. I tried to make the most of this by voicing one of my biggest bugbears with the C# language: Why make numbers so overly difficult to use?


We have sbyte, byte, short, ushort, int, unit, long, ulong, float, double, decimal to represent the simple real world concept of a number. If we take the concept of a number into the software development paradigm what do we really want from it:

  • Fidelity (How many decimal places to we need to be accurate to)
  • Possible values (What is the range of numbers to be stored: Minimum & Maximum)

Pretty simple huh!

I do understand the reasons behind .NET’s numeric types:

  • Give the C, C++ and Java developers something familiar
  • Performance
  • Hmmm, maybe they didn’t think about it so long.

Personally I think that performance is a non-issue.  The .NET runtime is responsible for handling garbage collection as we’re too irresponsible to do this effectively ourselves, so why not handle numbers for us too. Maybe we might have to introduce some attributes to indicate what is most important to us:

  • [Optimisation=Speed]
  • [Optimisation=Space]

I certainly wouldn’t miss having to debug runtime errors where a DataReader returns an insignificantly different type from the attempted cast.

Posted on Tuesday, November 11, 2008 3:37 PM C# | Back to top

Comments on this post: Mad about numbers

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © markritchie | Powered by: