8 ms·
> When I say perfect, I mean, there has been never once in my career where I hit a roadblock due to the language's limitation or complexity or flawed assumption
by mcintyre1994 7y ago
> When I say perfect, I mean, there has been never once in my career where I hit a roadblock due to the language's limitation or complexity or flawed assumption. I faced this with other languages, but not Elixir.
This is pretty amazing praise! Are many of the other languages you've used strongly typed? That's the thing that gives me pause - I feel like I rely on the compiler a lot in languages where it can do a lot for me, and that I'd be really frustrated managing a large project without it.
I'm not sure what other languages you have a lot of experience with, but does anything in Elixir stand out to you as the reason dynamic typing works well there? I think dynamic typing is the main reason I nod along with "horrible programming languages like Javascript", for instance.
- AlchemistCamp 7y agoStatic typing is far from a panacea. Don't forget that the rise of Perl and PHP, and then later Ruby and Python was in response to statically typed languages like Java. There are trade-offs.
- conradfr 7y agoTo be fair PHP, while still dynamic, has eventually evolved to be (optionally) a strict and strongly typed language.
- mcintyre1994 7y agoI agree, I wasn't trying to imply otherwise. It's just that static typing is the first thing that looks like a theoretical trade-off of Elixir based on my experience, and I was curious why it doesn't feel that way in practice.
- AlchemistCamp 7y agoStructs and pattern matching help quite a bit.
- paultannenbaum 7y agoDialyzer via Dialyxir also helps as well
- andy_ppp 7y agoOne of the things I like about Guards is that you can enforce/match against types as needed.
- theonething 7y agoGuards are nice, but compared to static typing, they a run time check whereas static typing alerts you to errors at compile time.
- 1_player 7y agoGuards are mostly used to do pattern matching, not to specify which types a function accepts, though you can use them as such.
- andy_ppp 7y agoI’m a fan of static types don’t get me wrong, I’m just saying with guards and dialyser it’s 60% of the way there compared to nothing. Also I don’t seem to make to class of errors I do in other languages because 90% of this time passing the wrong thing breaks immediately due to pattern matching.
- nickcox 7y agoDon't Perl and PHP both predate Java? By quite a bit in Perl's case.
- pmontra 7y agoThe rise in popularity can happen later than the creation of a language, see Python (1991). In my case I left Java for Ruby for web programming in 2006 because working with Rails was infinitely easier than working with Structs. I didn't even know that Ruby was a programming language before Rails.
- mtnGoat 7y agoFWIW: Perl, 1987. PHP & Java, 1995.
- gfxgirl 7y agoWhat I want hear on static types vs dynamic is how it plays out on a team of say 30 to 100 people. I love JavaScript when it's just me but I much prefer types when using someone else's code because they provide guidance that otherwise isn't there.
- QuinnWilton 7y ago> Are many of the other languages you've used strongly typed? That's the thing that gives me pause - I feel like I rely on the compiler a lot in languages where it can do a lot for me, and that I'd be really frustrated managing a large project without it. As someone who has been writing Elixir professionally for 4-ish years, and who is otherwise about as big of a proponent of static types as is possible, this is simultaneously my biggest critique of Elixir, and also a critique that has ended up being more theoretical than not. I wish that it were statically typed, but in practice that hasn't been slowing me down. Part of the reason for that is that while Elixir is dynamically typed, I've found that it's possible to pretend it is a statically typed language if you squint just right. By that, I mean making judicious use of typespecs [0], dialyzer [1], Norm [2], and just generally constraining the way you write code to mirror the sorts of code that you'd write in a language that offers algebraic data-types, like Haskell. I've been meaning to put together a blog post on what I mean by this, because I often hear people talking about how unusable Dialyzer is, so I feel like my team is a rare example of a large production app that requires that Dialyzer typechecks on every build. This makes large-scale refactoring of our app almost (but not quite) as easy as it would be in Haskell. The macro system in Elixir also means that it's possible to write libraries like typeclass [3], that offer compile-time guarantees (using compile-time property tests!) that your implementations correctly implement a given interface. I think that as the language evolves, we'll be seeing a lot more examples of macros that move runtime logic into the compilation step, to offer compile-time guarantees and safety. For example, a few weeks ago, I prototyped an experimental library in a few hours that added support for compile-time OCaml style parameterized-modules. [4] Obviously, all of these techniques don't get you quite as far as proper static typing would (though the Whatsapp team is working on static types for Erlang! [5]), but the rest of the language and the ecosystem is just so well thought out, that I've been okay with that! [0] https://hexdocs.pm/elixir/typespecs.html https://hexdocs.pm/elixir/typespecs.html [1] https://github.com/jeremyjh/dialyxir https://github.com/jeremyjh/dialyxir [2] https://github.com/keathley/norm/ https://github.com/keathley/norm/ [3] https://github.com/witchcrafters/type_class https://github.com/witchcrafters/type_class [4] https://github.com/QuinnWilton/daat/ https://github.com/QuinnWilton/daat/ [5] https://www.facebook.com/careers/jobs/229713254864749/ https://www.facebook.com/careers/jobs/229713254864749/
- 7y ago
- neya 7y agoBefore Elixir, I considered Scala because static typing was a strict requirement for me. After I tried Elixir, I found out that good, reliable and maintainable code doesn't have to be necessarily static typed.
- mcintyre1994 7y agoThat's an encouraging answer because I currently use Scala :) Thanks!
- gregkerzhner 7y agoFor me static typing is essential not when I am writing a new application from scratch, but when I am coming into huge old legacy code projects. For example, I am currently working on a messy and old Swift / Objective C application and having first class IDE support for things like calling hierarchies is pretty amazing to unwind spaghetti code. Also, it's a good feeling to be able to delete a big chunk of code and be 100% confident that its not being used anywhere if your project compiles. Does Dialyzer seem like it would allow you to do things like this safely as well? My other huge gripe about Elixir when I worked on it last year was lack of IDE autocompletion. This to me is a the #1 dealbreaker in working with dynamically typed languages. Im a horrible speller and having to run my program every time just to find out that I missed a capital letter somewhere in my code is infuriating. Has Dialyzer and IDEs (VSCode I assume) gotten good enough yet to have decent autocomplete support? When I was using Elixir with WebStorm the experience was less than optimal.
- strofcon 7y agoI definitely get the point about static typing. I've seen the same need in legacy codebases myself. :-) That said, I'm head-over-heels for Elixir. As for autocomplete and such, there's a pretty good project for vscode called something like "Elixir LSP (fork)". Be sure to use the fork version, it's a continuation of the old stale original extension. In more general terms, the `elixir-lsp` project is pretty solid (and lies underneath the VSCode extension, FWIW), and I've had good luck with it so far in neovim with CoC + coc-elixir.
- jeremyjh 7y agoI've been programming Elixir professionally for three years. I wish Elixir was statically typed, but there isn't a statically typed language that I really like better all around. I've done a lot of Haskell development but it seems like I always spent too much time playing type tetris and polishing abstractions instead of getting work done. Elixir feels more static than most dynamic languages; you'll get compile errors or warnings if function arity doesn't match or if you use names that are undefined. There is a static analyzer called Dialyzer that can detect a lot of errors you'd catch with static language compiler such as passing the wrong type to a function (often, even if there are no type specs defined). Yet at the same time you get the benefits of a dynamic language with excellent meta-programming capabilities.
- dnautics 7y agoOver time I find my Elixir is more and more "statically typed". Since you get access to basically the full language at compile time, with a bit of hand-coding you can opt-in to features that statically type critical sections of your code at compile time. Critically important things can be guarded by relatively advanced checking, if you want to get really clever you can yank those checks for performance in prod deployments. I have been doing this with configurations, so that configs are checked at compile time instead of at deploy time, and I'm pretty happy with it.
- keithnz 7y agoI was excited to the other day to see https://gleam.run/ https://gleam.run/ on HN, which is statically typed and will interop with elixir... but still early days for the language.