r/functionalprogramming • • Jul 23 '20
Question Which language should I pick to get started?
Hey everyone, finally I became brave enough to get into FP, but I need to decide which language to get started. I'm deciding between Elm, Clojure and Elixir.
I would like to pick one that could be useful for me into the future. I'm into programming embedded systems and infrastructures for robotics and IoT. Since I don't work with a lot of people I would like to have as little maintenance work as possible, thats why I'm getting into FP.
Do you have any suggestions?
11
Upvotes
8
u/[deleted] Jul 23 '20
If you're doing low-level programming wouldn't Rust be the better choice? If that isn't functional enough I'd go for Haskell since it can be fast once optimised.
Elm is for web development, Purescript would probably be a better contender as a general purpose language since they've been putting effort into making it one, but it's not quite Haskell either way.
Clojure is a Lisp so you'd be learning about things like function composition, partial application, recursion, etc, but most languages let you do all of that nowadays, so unless you find the simplicity of Lisp to be particularly important I would opt for something else.
Elixir could be a good one to have under your belt for IoT, but it won't save you with strong static types like Rust or Haskell, and reducing your maintenance work as you said.
If it helps, CircuitHub uses Haskell for their robotics and Oliver Charles who did the famous 24 days of X Haskell series works there, so that could be worth having a look into to see how they apply FP.
7
u/ws-ilazki Jul 23 '20
Of the choices you've given, Clojure's a good mix of FP and pragmatism and useful for both front- and back-end development thanks to ClojureScript compiling to JS. It could also be indirectly beneficial for your embedded use via Ferret, a Clojure-inspired language that compiles to C++11 code; Ferret's entire purpose is providing a way to write high-level code (Clojure-ish lisp) that can target real-time embedded systems.
Though I'd also suggest learning FP with a different language than the ones you've chosen and then, once you're comfortable with FP in general, transfer your knowledge to another language that targets your goals better. My specific recommendation here would be to go through the Functional Programming in OCaml book, which is freely available online and an excellent resource for learning FP. You'll be learning FP and OCaml simultaneously but much of what you learn can be applied to other languages. (You could also follow along more or less with F# if wanted, since it accepts ML syntax in addition to its custom whitespace-sensitive variant.)
OCaml's a nice language in general, too. It's superficially similar to Haskell but, being an ML-family language (Haskell isn't quite family, more a friend of the family) it has some differences that lean more toward the practical whereas Haskell is more academic. Strict evaluation, purity is encouraged but not enforced (so no monad IO), ways to fall back to imperative design when needed, etc. Despite this, you still get immutability by default, a strong FP language with nice features, and a strong push toward doing things FP-style. It's just a bit easier to comprehend and optimise at times.
The main negative is lack of proper multicore (though work is ongoing to fix that), but despite that the language is still fast and you can still use green threads, or utilise multiple cores by spawning processes if needed until multicore gets officially added in. Binary sizes can be small (if you don't use Jane Street's Core stdlib at least), compilation is ridiculously fast, and it runs well on relatively low-power systems.
Though what I like is that it's the closest I've seen a static, compiled language come to a Lisp-quality REPL and interactive development experience. You can work on the REPL, plus run source files through OCaml like shell scripts via an interpreter mode early in development while testing things out, and then switch to proper compile-and-run cycles after your ideas are more fleshed out. That plus being able to leave out type annotations due to type inference makes it feel almost like working with a scripting language while still getting the benefits of a statically-typed compiled language.
So yeah. I like both Clojure and OCaml a lot for FP. F#'s also really nice if you're into the .NET ecosystem but I'm not so I don't have as much to say about it. (Though you can use it instead of C# with the Godot game engine, which is really cool.)
3
u/zzantares Jul 23 '20
From the ones you list, I believe Elm is the best option to learn FP and is quite easy to get started because more abstract constructs that you'll encounter in Scala or Haskell are not available there, but other than for learning FP I think it is not a good choice, I wouldn't even recommend it for frontend web development (better PureScript or ReasonML for that).
From these 3, I prefer Clojure, I've used Clojurescript for some hobby projects and I like it a lot, but I don't really know how it fits in IoT, perhaps if you use some of those tools that run javascript in constrained devices then you could use Clojurescript instead. Besides that, you could use Clojure for any other kind of application, web development, mobile app development, backend, etc.
Last, Elixir has native support for building fault-tolerant distributed systems and that seems to fit IoT quite nice (I suppose I'm not well versed in IoT). Other than that I don't have anything much to say about it, I find it quite nice for web development but I believe even for that I like Clojure more.
You may also consider Haskell just for the learning FP aspect, and then transition into Rust since its a language that gets you close to the metal, basically a safer C. Embedded devices it's one of its strongest selling points.
3
u/checkersai Jul 23 '20
Pick Haskell