Tuesday, 24 June 2008
Specific Data Types Avoid Primitives Confusion
An interesting confusion occured today at work one the interpretation of a method parameter named something like 'widgetPercentage'. One developer took 5% as being 0.05 and the original author expected 5% to 5.0. My first thought is that we are missing a 'Percentage' type to remove this ambiguity. But, this would require a constuctor that took a percentage as a sting like 'Percentage("5%")'. Seems fine, but both an example of my loathing of such strings and the lack of use of strong types. I do 'feel' that a strong type could have avoided the problem here.