Reply to post: Strongly typed

It's Friday – and that means one thing: Yup, Microsoft's TypeScript 2.0 is out

Ken Moorhouse Silver badge

Strongly typed

Used correctly, strong typing can help document code and prevent accidental erroneous usage. For instance I can have a variable that holds a count of "apples", and another which counts "bananas". Both of them are integers but they are incompatible if you started adding apples and bananas together to work out how many apples you had. If you wanted to count how many items of "fruit" you had then the idea is that you create a variable of that type. Casting types from one to another is, as already mentioned in this thread, a very conscious decision on the part of the coder.

I've come across languages where a variable is derived, not from explicit declaration, but implicit usage. Take "1" for example: am I referring to an integer, a floating point number, a string, a boolean, or a date even? Classic example is Excel which goes ahead and assumes all sorts of wrong things about data you are entering: phone numbers, invoice numbers with leading zeroes, etc. aaargh.

I work with Delphi which engenders strong typing. Yes you can force everything as "variant" if you wanted to, but you wouldn't be getting the best out of the language if you did. I've also worked with languages such as Clipper where there are variable scoping problems too. From what I remember a variable can be used as a string one minute and an integer the next, depending on where it was called from. Delphi on the other hand has a very robust structure.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon