[HN Gopher] Real World OCaml - 2nd Edition (2021)
       ___________________________________________________________________
        
       Real World OCaml - 2nd Edition (2021)
        
       Author : _benj
       Score  : 148 points
       Date   : 2022-05-05 11:47 UTC (11 hours ago)
        
 (HTM) web link (dev.realworldocaml.org)
 (TXT) w3m dump (dev.realworldocaml.org)
        
       | pkilgore wrote:
       | The design of OCaml/Reason is the sweet spot of functional
       | programming for me but every time I must deal with Dune after
       | working with the tooling of Go or Rust I want to stab myself in
       | the face repeatedly and I think that maybe that might just be
       | related to the general concept of "masses" + OCaml.
        
         | _benj wrote:
         | I haven't spent enough time with dune to form an opinion (go
         | and cargo are absolutely marvelous though) but a quick
         | search[0] reveals that dune is not the only option.
         | 
         | [0] <https://github.com/ocaml-community/awesome-ocaml#package-
         | man...>
        
         | Zababa wrote:
         | Dune is a great "window" in my experience with OCaml, it forces
         | you to do more than with every other language but you end up
         | with a better understanding of everything.
        
           | pkilgore wrote:
           | This is fair. It's also a reason the "masses" are going to
           | pick up Go or Rust instead.
        
             | Zababa wrote:
             | That's how I think things will go too. I really enjoy the
             | time I spend with OCaml but whenever I need to do something
             | I use JS because it gives me the frustration in lower doses
             | if that makes sense. I learn less but sometimes I don't
             | want to learn, I want to do.
        
             | LAC-Tech wrote:
             | Rust has a larger ecosystem, but it's not even on the same
             | planet as ocaml in terms of expressiveness.
             | 
             | Kind of disappointed facebook didn't run with ocaml,
             | instead of doing the whole Reason thing. They could have
             | been contributing to and using ocaml directly, instead they
             | decided that programmers will freak out if there's no curly
             | braces.
        
           | baby wrote:
           | I spent so much time reading the horrible documentation of
           | Dune and I don't think I learned much about the internals of
           | OCaml.
        
         | rashkov wrote:
         | Sorry could you explain your comment some more? Genuinely
         | curious what is bad about dune. Just started using it
        
           | pkilgore wrote:
           | We can start with that, upon starting down the road to
           | learning a (IMO great) but very, very different syntax than
           | most other languages in OCaml, Dune then asks you to write a
           | lisp file to do basic configuration and I suspect 90%+ people
           | who want to explore just say "fuck it" the second they
           | internalize this.
           | 
           | I'm sure there's a crowd, especially here on HN, that views
           | this as some sort of purity test for the language, but in my
           | opinion it's needlessly obtuse over <insert more readable and
           | traditional and lintable type here> used by modern build
           | systems.
           | 
           | Then there's the fact that several `init` commands don't
           | actually fully `init` a project (and up until recently, the
           | very example in OCaml's getting started documentation was
           | broken).
           | 
           | Then there's this insanity                   dune build
           | dune test         dune exec # hahaha no, no, this doesn't
           | work.
           | 
           | Then you gotta manually tape together crap between opam and
           | dune (and don't get me started on how insane the lockfile
           | situation is -- I swear to god I complained once and someone
           | told me I should learn to use nix!).
           | 
           | This is all very fun and yak shave-ey and I generally grin
           | and bear it, but boy do I totally get why most people look at
           | me like I'm a weirdo because I like this language.
        
         | LAC-Tech wrote:
         | What's wrong with dune? I thought it was really good.
        
           | baby wrote:
           | Horrible doc, the configuration files are a made-up language
           | with no extension, it is completely detached from managing
           | the versions of your dependencies, or their source of origin
           | (package manager? vendored? patched? internal?), horrible
           | CLI, transitive dependencies are imported by default and it's
           | hard to not do that, etc.
           | 
           | And then you try to use it in combination with opam and you
           | want to blow your head.
        
       | a-dub wrote:
       | cool! always happy to see more of this.
       | 
       | i learned out of the unpublished french ora book "developing
       | applications with ocaml". (incidentally it was so useful i had a
       | copy shop bind me a custom "book")
        
         | jasperry wrote:
         | I love that book! I have happy memories of poring over it until
         | I understood signatures and functors.
         | 
         | It's available free online as well:
         | https://caml.inria.fr/pub/docs/oreilly-book/html/index.html
        
       | clpm4j wrote:
       | Totally unrelated to the link/book, but sparked a question that
       | I've had for a while (curious to hear any answers) --> when you
       | take an initial look at a programming language that you're
       | completely unfamiliar with, and you glance through the syntax of
       | all the basic constructs, do you ever have a particularly strong
       | reaction (be it negative or positive), and if so have you tried
       | to identify why that might be the case?
        
         | _benj wrote:
         | such a good question! I don't think I've ever had a
         | particularly strong guttural reaction to a language, but I'm
         | definitively biased and either see things that I quite like or
         | dislike in a new language I see.
         | 
         | As I think about why those are I think one of the biggest
         | reasons is familiarity, it's easy to get comfortable doing one
         | thing and it truly sucks to feel like you don't know anything
         | again (I think somebody called this the curse of knowledge?
         | Idk).
         | 
         | Lately I've been intentionally the unknown, or, those languages
         | that I'd look at and be like, "but why!?", for example, why
         | would I want to learn or only use recursion when a for/while
         | has worked for pretty much my whole career? or, following the
         | same functional languages traits, why immutable data? seems
         | like a step backwards?
         | 
         | But the thing is that people, quite likely smarter than me, or
         | at least, a lot more familiar with challenges that I'm not
         | familiar with, came up with solutions that diverge from what I
         | know... and I want to know why! Why they came with immutable
         | data or recursion or a language that pretty much everything is
         | a list (LISP)... and the answers are quite surprising and at
         | the same time I feel that joy of discovery that has almost been
         | erased by years in the industry.
         | 
         | So when you come across a language that you have strong
         | feelings/opinions about, wearing the shoes of the people using
         | it might be quite enlightening and enjoyable.
         | 
         | While I say this, I'm a complete hypocrite because I won't give
         | such courtesy to OOP... but hey, none of us are perfect ;-)
        
       | hardwaregeek wrote:
       | I don't know about everybody else, but I don't find the "list of
       | language features" format that helpful. It's quite dry and it
       | doesn't contextualize how people use these features or what
       | patterns are common. The Guided Tour part at the beginning is the
       | best part IMO. I wish that'd be the entire book. Just a long
       | guided tour of OCaml through the lens of an in depth project, say
       | an interpreter of an ML language.
        
         | anthk wrote:
         | https://ocaml.org/about
        
       | iLoveOncall wrote:
       | Who would be cruel enough to expose the masses to OCaml?
        
         | midoBB wrote:
         | At least it ain't Clojure.
        
         | colesantiago wrote:
         | It was cruel to expose JS to the masses.
        
           | LAC-Tech wrote:
           | I like both JS and Ocaml. Should I seek medical attention?
        
           | elihu wrote:
           | I wouldn't mind living in the alternate universe where
           | browsers adopted Ocaml as the built-in scripting language
           | instead of JavaScript.
        
         | etaioinshrdlu wrote:
         | It seems like Haskell minus the laziness and enforced purity.
         | So really, far less cruel :)
        
         | synaesthesisx wrote:
         | One of the early programming classes I took in grad school
         | (taught at Harvard) was focused on OCaml. It was a wild jump
         | but gave me a newfound respect for functional languages.
         | 
         | Come to think of it though, I'm convinced the class was
         | sponsored by Jane Street or something.
        
         | percent wrote:
         | It's probably a great book, but I think Elixir is better for
         | the masses.
        
       | daenz wrote:
       | I'm sure this book is an excellent resource (upon skimming the
       | online version, it looks very thorough and well thought out). I
       | think there is some confusion about who "the masses" are though.
       | I don't think a subchapter titled "POLYMORPHIC VARIANT SUBTYPING"
       | is necessarily for--what I consider--"the masses."
        
         | jasperry wrote:
         | I don't necessarily begrudge the authors for including chapters
         | on advanced topics, it's not like people have to read the whole
         | book. But you raise a valid point. For languages like OCaml
         | that are both large and also veer into PL research territory,
         | some guidance about how many of the advanced topics one needs
         | to understand to be a "real world" programmer could be a big
         | help to the language's adoption.
        
           | rashkov wrote:
           | Yeah that's a great point. I've been writing front-end with
           | reasonml (an ocaml syntax) for a couple years now and I've
           | gotten a lot of benefit without writing functors at all.
        
       | anthk wrote:
       | An easier introductory book:
       | 
       | https://ocaml-book.com/
        
         | olah_1 wrote:
         | It was published in 2013, though. Much has changed in terms of
         | tooling, right?
        
           | anthk wrote:
           | Opam (the CPAN/PIP) counterpart will handle the library cases
           | fine.
        
           | mseri wrote:
           | Yes but it is not really relevant for that book. OCaml has an
           | incredible backward compatibility history, and the linked
           | book is about learning the language itself, not its
           | ecosystem.
           | 
           | Things are different for RWO since it relies also on a number
           | of extra tools and libraries which, indeed, change over time
           | (sometimes also substantially)
        
       | tgflynn wrote:
       | I'm a bit surprised to see this making it to the front page. It's
       | been available for a long time and is one of the first resources
       | anyone with an interest in OCaml is likely to encounter. It seems
       | a little like posting a link to cppreference.com.
        
         | rashkov wrote:
         | There are constantly new programmers joining the community
         | here. It's good for quality things to appear regularly.
        
         | throwamon wrote:
         | I, for one, have the attention span and knowledge organization
         | skills of a Phineas-Gaged goldfish, so it's good to be
         | externally reminded of the existence of good things from time
         | to time.
        
         | akavel wrote:
         | Even just "The lucky 10 000" can be already a reason good
         | enough (https://xkcd.com/1053/)!
        
           | baby wrote:
           | I wish someone posted that xkcd everytime someone posted a
           | comment like GP
        
         | AceJohnny2 wrote:
         | A more generous interpretation of your sentiment could be:
         | 
         | This is a fantastic resource that anyone with a passing
         | interest in the OCaml programming language needs to be aware
         | of.
        
         | pjmlp wrote:
         | True, but it appears to have been updated last year, I for one
         | wasn't aware of it.
        
       | ufo wrote:
       | Neat! I didn't know there was a 2nd edition. Does anyone know how
       | it differs from the 1st edition?
        
       | [deleted]
        
       | mirekrusin wrote:
       | This is great live/github based book.
       | 
       | Other great resources are Michael R. Clarkson's (from Cornell)
       | videos [0] and book-like format [1].
       | 
       | I took a lot of inspiration from it when playing with rb-trees
       | [2] and functional, ocaml-looking typescript in general [3].
       | 
       | [0]
       | https://www.youtube.com/playlist?list=PLre5AT9JnKShBOPeuiD9b...
       | 
       | [1] https://cs3110.github.io/textbook/cover.html
       | 
       | [2] https://github.com/preludejs/rb-tree
       | 
       | [3] https://github.com/preludejs
        
       | usrn wrote:
       | I'm not a huge fan of this book, if I get a book like this I'd
       | expect it to focus on the standard library and not third party
       | libraries.
       | 
       | On the other hand it says "real world" OCaml and as far as I can
       | tell that really is how OCaml used so It's hard to blame the
       | author.
        
         | jolux wrote:
         | The standard library is quite small and not very usable for
         | modern production applications. As an example a lot of the list
         | manipulation functions are not tail-recursive because the tail-
         | recursive implementation is less elegant.
        
           | yawaramin wrote:
           | For the pedagogical purposes of the book, you don't really
           | need Jane Street Base/Core though. Plus it ignores some
           | pretty widespread community libraries (like Lwt) and pushes
           | its own Jane Street version, Async (which incidentally
           | doesn't support Windows).
           | 
           | Anyway, this has all been hashed out before.
        
           | Zababa wrote:
           | > As an example a lot of the list manipulation functions are
           | not tail-recursive because the tail-recursive implementation
           | is less elegant.
           | 
           | What makes you say this has to do with elegance? This sounds
           | surprising.
        
       ___________________________________________________________________
       (page generated 2022-05-05 23:01 UTC)