Hacker News new | ask | show | jobs
by ufo 4113 days ago
Elegance is subjective... While its undeniable that you often need to type less characters in Python and list/dictionary comprehensions are wonderful syntactic sugar, its kind of nice that there is much less magic going on under the hood in Ocaml. In a highly dynamic language such as Python or Ruby you never know exactly what your code is doing: any method call can can be overloaded and even things like function calls and array indexing can be overloaded too. On the other hand, in Ocaml almost everything is statically dispatched and the static typing is really great (I'm sure Python wouldn't look as nice if you added the required modifications necessary to make it statically types as ocaml is)

While you might not see this dynamism as a big problem in Python, its something that I always found confusing about Ruby. Over there, people everything is a method call and people are super happy to monkeypatch extra methods to classes, which makes it very hard for me to understand the program by reading it. At some point, things get so dynamic that static analysis in your head gets too hard and you are better off just running the program and seeing if it worked...

In any case, I can't give you a concrete example right now because my laptop doesn't have ocaml installed on it but in my other post I already listed some of the bigger differences that the ocaml version has. The tldr is that some of the features you are using in Python aren't available in the ocaml stdlib (so you would need to write the sorting comparator the long way or create the helper function yourself) and that creating the polymorphic hash table is not very beginner friendly (this is a cost we pay for stronger typing). What I wanted to say is that the big things about the Python function (hash tables and generic sorting) are both things you can do in Ocaml just fine.