4 ms·
This is the most logical way to add optional typing: var i = 1 //Type inference var i:Int = 1 //Explicit type i.e allowing you to optionally e
by mythz 11y ago
This is the most logical way to add optional typing:
var i = 1 //Type inference
var i:Int = 1 //Explicit type
i.e allowing you to optionally enhance existing code with explicit type info without changing the existing definition.
- guelo 11y agoThe type and colon could be placed anywhere and achieve the same goal. Int:var i var:Int i var Int:i
- hyperpallium 11y agoLogical, but assuming Int is reserved, I can't see why type-first would give the parser or developer any problems: var i = 1 //Type inference var Int i = 1 //Explicit type But it seems a common convention for optional typing. Maybe it suits dynamic developers?
- PeCaN 11y agoPersonally I just consider that uglier. Also you can parse var i: Int = 1 unambiguously without backtracking, while you have to backtrack on var Int i = 1 (unless you enforce some constraint like type names must start with capitals, in which case you may as well just do Int i = 1).