4 ms·
I really like Nim, and every now and then I go back to Nim for a side project or a small tool. A couple of things that annoyed me personally about it though:
by captainmuon 5y ago
I really like Nim, and every now and then I go back to Nim for a side project or a small tool.
A couple of things that annoyed me personally about it though:
- Its object orientation story is weird. There is inheritance and there are methods, but there was something off and I can't remember what. I think it did not support runtime polymorphism, which to me is one of the main points of object orientation. (e.g. you have objects of different types in the same container and you call a method on each, instead of using an `if` statement.)
- Related: it had a way of specifying if a relation is covariant or contravariant. Covariance: If a TextBox is a Widget, then a Handle[TextBox] is a Handle[Widget]. Contravariance: If a function takes a list of Widget, you can pass a list of TextBox, but not vice versa. This never worked properly as far as I can see. I tried to fake it by defining implicit converters (another nice feature), but this caused extremely long compile times.
- Also somewhat related: I found there is an interesting effect system. I created some annotations that allow you to say: "this code must run on the main/network thread" and it would check it at compile time! Unfortunately it got a bit messy because there was no fine grained way to say "this code requires this effect", "this code sets this effect", "this code forbids this effect", so I ended up doing a lot of casting.
Granted, these were somewhat obscure features. If you use Nim as a kind of compiled python for small tools, it really shines. Its a bit unfortunate that there were a couple half-baked corners in there. But I guess that's expected if you are trying to innovate as a language. Looking forward to seeing how the language developed in the meantime!
- cyber_kinetist 5y agoNim supports runtime polymorphism, you need to use the ``method`` keyword instead of ``proc`` to achieve dynamic dispatch. (https://nim-lang.org/docs/tut2.html#object-oriented-programming-dynamic-dispatch https://nim-lang.org/docs/tut2.html#object-oriented-programm...) Note that at one point it could even do multi-methods (dynamic dispatch on multiple arguments at once), similar to what Julia could do. But this got removed because it complicated the language, had undesirable performance penalties, and was overall hard to maintain (https://github.com/nim-lang/RFCs/issues/65 https://github.com/nim-lang/RFCs/issues/65). It's still available via a flag, but might get eventually removed at some point. Overall, I view Nim as more of a procedural language in the spirit of C/Pascal rather than the OOP-isms of old C++ / Java.
- _dain_ 5y ago>- Its object orientation story is weird. There is inheritance and there are methods, but there was something off and I can't remember what. I think it did not support runtime polymorphism, which to me is one of the main points of object orientation. (e.g. you have objects of different types in the same container and you call a method on each, instead of using an `if` statement.) Are you thinking of multiple dispatch? i.e. runtime dispatch on the type of _every_ function argument. It used to have that but they took it out. It still has runtime dispatch on the first argument.