3 ms·
How do you deal with lack of types? (I know elixir is adding types but from my understanding it's nothing like e.g. typescript) I'm thinking about learning eli
by anhner 2y ago
How do you deal with lack of types? (I know elixir is adding types but from my understanding it's nothing like e.g. typescript)
I'm thinking about learning elixir but lack of types is kind of a turn off for me.
- cess11 2y agoIn Elixir specifically you've got structs that are somewhat similar to types, %MyStuff{}, and if you need to you can use Ecto to get some guarantees. You also tend to focus more on the shape of data than the name, e.g. with pattern matching in places like function declarations and case expressions, which emulates quite a bit of what you typically use a type system to accomplish. Here's a summary of the type system they're exploring for Elixir: https://hexdocs.pm/elixir/main/gradual-set-theoretic-types.html https://hexdocs.pm/elixir/main/gradual-set-theoretic-types.h...
- TacticalCoder 2y ago> How do you deal with lack of types? Not GP but I'm using Clojure for both the front-end (ClojureScript) and the "back-end" (server running Clojure), sharing Clojure code between the two. Clojure is not typed but I use Clojure specs. It's not a type system but it's really nice. You can spec everything, including specc'ing functions: for example you can do stuff like: "while in dev, verify that this function returns indeed a collection that is actually sorted everytime it is called". I'm not saying: "no types + clojure specs" beats types but it exists and it helps to solve some of the things types are useful for. https://clojure.org/guides/spec https://clojure.org/guides/spec
- anhner 2y ago> _for example you can do stuff like: "while in dev, verify that this function returns indeed a collection that is actually sorted everytime it is called"._ This sounds interesting. Do I understand correctly, this checks the "spec" at runtime? What happens if a spec fails?
- shawa_a_a 2y agoNot the other commenter, but my team has been using Elixir in production (soft real-time distributed systems) for several years to great success. The approachable syntax has been great for folks new to the language coming on board and sort of, not realising they’re “doing FP”. Generally I’d say Elixir’s lack of “hard” static typing is more than made up for what you get from the BEAM VM, OTP, its concurrency model, supervisors etc. That said if you’re interested in leveraging the platform whilst also programming with types I’d recommend checking out Gleam (https://gleam.run https://gleam.run), which I believe uses an HM type system.