4 ms·
For the lay person, what is the advantage of ocaml over other languages? Why would I reach for it?
by terminalserver 5y ago
For the lay person, what is the advantage of ocaml over other languages?
Why would I reach for it?
- Steltek 5y agoJane Street, financial trading company, uses OCaml a ton and publishes a lot of their libraries. I played with it some back when I was dabbling in every language I could get my hands on. About when Scala was new (and constantly breaking between releases) and before Rust, Go, JS v8 were around. I really liked the functional aspect, which wasn't bolted on after the fact, and that it could be compiled to a real binary, not interpreted bytecode. In my naive youth, I viewed AOT compilation as the path to a true high level language that was also fast. While it was neat, I moved on to Lisps/Schemes and now modern JS is my very happy compromise of functional and practical.
- Taikonerd 5y agoOCaml is... * functional * strongly, statically typed * garbage-collected OCaml can compile to a native binary, or to JS via ReScript (formerly BuckleScript).
- christophilus 5y agoAlso, it compiles very quickly compared to most other statically typed languages; especially compared to more advanced ones.
- Zababa 5y ago> OCaml can compile to a native binary, or to JS via ReScript (formerly BuckleScript). It can also compile to JS via js_of_ocaml!
- richeyryan 5y agoOCaml is statically typed functional programming language. It's a cousin of Haskell. It has some nice things like automatic type inference so you don't have to write very many type annotations. It's not as focused on purity as Haskell so its easier to mutate state where you want to but you get a lot of the niceties of ML programming languages like pattern matching, variants, structural typing in places. It also has object-oriented features, though they aren't widely used the attitude is something like OO is there if we need it and we're definitely willing to use it in places that require it. Its pretty fast for a functional language and you could probably get pretty far with it before you'd have to consider using a real low level langauge. The disadvantages I think are pretty uncontroversial: a smaller community, not as many libraries, a bit of a fractured stdlib and build situation and until now no multicore.
- dunefox 5y agoAlso no unicode support which is a huge con.
- patrec 5y agoI'd take ocaml's unicode support over python's, javascript's or java's any day of the week.
- reom_tobit 5y agoTangent, but I’ve never really understood what the issue is with unicode support in various languages. Does anyone have any idea why it’s such a contentious issue?
- chubot 5y agoBasically because there's 2 major ways to do it: the Windows way and the Unix way (UTF-8). Unicode has the concept of encodings and it doesn't tell you which one to use. The Unix way is winning on the web, and I think Microsoft has made some moves toward UTF-8, but I don't understand what they are exactly: https://en.wikipedia.org/wiki/Unicode_in_Microsoft_Windows#Windows_9x https://en.wikipedia.org/wiki/Unicode_in_Microsoft_Windows#W... JavaScript and Java inherited the Windows way. Go and Rust use the Unix way (and apparently OCaml too). Python supports both which some say is a needless source of complexity, but it is flexible if you know how to use it.
- reom_tobit 5y agoAwesome, thanks for the info. Sent me down a rabbit hole for a little bit.
- chubot 5y agoIn case you didn't already get it, this is a good and readable summary: https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ https://www.joelonsoftware.com/2003/10/08/the-absolute-minim...
- Blikkentrekker 5y agoSome of the rather impressive type system features of Ocaml: - Modules can be stored in variables, based on runtime conditions, this is all statically type checked to ensure tht the module exports the binding of the proper type. Modules can also be passed to functions and functions can produce different results based on which module is passed. - There are keyword arguments and optional arguments with full static type checking. - It has full support for row type polymorphism, or “static duck typing” as some call it: it tests statically whether an object quacks like a duck. https://dev.realworldocaml.org/first-class-modules.html https://dev.realworldocaml.org/first-class-modules.html
- systems 5y agoOCaml is everything D wanted to be, but failed OCaml is high performance, Garbage Collected, hybrid system and application programming language You can use OCaml to write high performance Apps and System tools without worrying too much about performance, or doing crazy manual memory management I would also say, if you like Go, but think you hit a wall with it, then try OCaml system programming language: C, C++, Rust Hybrid system and application languages: OCaml, Go , D If you need a language in this class (Hybrid system and app)I think currently Go and OCaml are your only options, Go being closer to C, Java familly of languages and OCaml is an ML language, so choose as per your preference
- abhijat 5y agoIs Haskell a good fit for your hybrid category, similar to go and ocaml, considering it also compiles to native? I haven't heard of Haskell being used for the kind of "high level" systems programming that go is used for.
- willtim 5y agoIn my opinion, as a professional haskell developer, it is too hard to reason about the runtime space usage of Haskell programs to ever recommend Haskell as a "systems programming language". Haskell would be great for writing a DSL for generating such code though.
- vips7L 5y agoWhy do you think D isn't an option?
- systems 5y agoWell, D have a GC, and by design cannot have a GC with good performance, because of its complex mutable object system OCaml, can achieve good GC performance because its immutable by default D by design, will never outperform OCaml, at least this is my understanding That, and I think D's community is too small to fix the language, while it does have several brilliant members and developer, its just too small and underfunded So, you have two reason why D should not be an option the first technical ( D will never have a good GC ) the second is more of a logistics issue, the community is just not there to support a language as complex and as ambitious as D and deliver on all its claims
- rwmj 5y agoI develop in OCaml from time to time, and it's pretty practical. Separate compilation, makes small-ish binaries that most people wouldn't know weren't written in C/C++, fast, garbage collection reduces mental burden, easily call out to C if you need to. We steer clear of the more complex language features like functors because they confuse most programmers. Here's an example of one very widely used production application: https://github.com/libguestfs/virt-v2v/tree/master/v2v https://github.com/libguestfs/virt-v2v/tree/master/v2v It fits a similar niche to Golang or C++, but unlike those it's an enjoyable language to program in.
- lmm 5y agoI consider OCaml the baseline for what a language from the last 20-or-so years should be. It doesn't do much that really pushes boundaries, but it has all the basic things you want and no major blunders (which is a surprisingly rare thing). In particular it has a sensible type system with proper algebraic types (which so many languages manage to get subtly wrong, even today), full pattern matching, and very little in the way of control flow keywords.
- yawaramin 5y agoThat's difficult to answer without knowing what you want from a programming language/stack.