|
|
|
|
|
by asterite
4672 days ago
|
|
If your variable gets promoted to a union type, and all of the types respond to the methods you give them, then it will compile and run successfully (duck typing). Yes, it will have a small performance cost. If you then profile your app and find that the performance problem is that one, you go and fix it. You can always have a static analyzer tool (that works, because Crystal is compiled) that can pin-point all the locations of union types. You can then put some type restrictions wherever you need them, to know where the union types come from. The idea is that you can start prototyping something that works and is quite fast, and later you can always improve the performance without ever having to write C code. Also, the union of an int and float will probably be just float so it won't have any performance overhead. |
|