Simberon Design Minute
 

Accidental Fractions

I sometimes see Smalltalk code that performs calculations on numbers but does many automatic type conversions when it does. In one example, I saw code that divided two numbers then sent rounded to the result. This caused the system to create a fraction temporarily then do a calculation with fractions. Although this technique isn't horrible when it's not called frequently, it runs the risk of performing very badly. If that code happened to be called millions of times a second, the performance of the system could be severely impacted. If you intend to do floating point calculations, it's best to explicitly convert the numbers to floats first before starting the calculations. If you accidently convert to fractions, you may find your system acting a lot slower than you expected.

Download