7 ms·
Learning Elixir: My side-project
- jamesroseman 9y agoI had a brief stint of working with Elixir a while ago, and got side-tracked and spent that time going down the GraphQL/Relay rabbit hole instead. During that time I was ramping up to help out on the GraphQL Elixir project [1]. I don't know its current state, but it might be worth looking into vs Absinthe (which I'm pretty sure was branched off that project originally). EDIT: Looks like the repo is pretty abandoned actually, scratch that! [1] https://github.com/graphql-elixir/graphql https://github.com/graphql-elixir/graphql
- micmus 9y agoAbsinthe is completely separate from that project. I think the whole community effort is around Absinthe at the moment and it's shaping into a great library. There's also a PragProg book coming out in Autumn "Craft GraphQL APIs in Elixir with Absinthe" [1]. [1]: https://pragprog.com/book/wwgraphql/craft-graphql-apis-in-elixir-with-absinthe https://pragprog.com/book/wwgraphql/craft-graphql-apis-in-el...
- jamesroseman 9y agoIt's not completely separate. The maintainer of Absinthe got started working with the maintainer of GraphQL-Elixir. I'm not purporting they still work together, just that they have common roots. Though that's cool a book is coming out! I remember when these projects were just getting started.
- blindwatchmaker 9y agoPicking up new languages is fun. I have to say things like this tickle my funny bone though: > def backlog(board_id) when is_integer(board_id) do What happened to good old fashioned function foo (int bar) :) Is there an equivalent to typescript for elixir?
- ch4s3 9y agoThere are typespec annotations. The syntax using guards allows you to have for example: def backlog(board_id) when is_integer(board_id), do: something and def backlog(board_id) when is_list(board_id), do: some_list_thing
- chickenfries 9y agoI've been reading about Erlang recently, and guards (the when clause) seem much more expressive than something like type annotations for function parameters. For example, TypeScript's annotations can't express something like this (which also shows Erlang's pattern matching): right_age(X) when X >= 16, X =< 104 -> true; right_age(_) -> false. http://learnyousomeerlang.com/syntax-in-functions#guards-guards http://learnyousomeerlang.com/syntax-in-functions#guards-gua...
- jacquesm 9y agoCan't?
- chickenfries 9y agoThat was awkwardly phrased. I was trying to say "TypeScript's annotations can't express something this Erlang example."
- always_good 9y agoUnless you're telling me Elixir has static analysis that can tell me that `right_age(18) == true` then I'm not sure how that competes with types much less is so different from any other runtime conditional.
- rdtsc 9y ago> Unless you're telling me Elixir has static analysis Sure does: http://erlang.org/doc/apps/dialyzer/dialyzer_chapter.html http://erlang.org/doc/apps/dialyzer/dialyzer_chapter.html > I'm not sure how that competes with types much less is so different from any other runtime conditional. You can write: f(5) -> "got a 5"; f(X) when is_integer(X), X > 1000 -> "got an integer greater than 1000"; f(X) -> "not 5 and not an integer greater than 1000". Sure you can do it with an if statement in some languages. Except in Erlang can also have the same guards on process message receive expressions. There would have to process all messages then check the type and somehow re-insert it back into the message queue.
- bglusman 9y agoThis looks awesome! It's also a kind of perfect companion piece to an Elixir/Phoenix project a friend of mine, Travis, did over at Stride[1]. I also have my own social-good oriented learning-phoenix/ecto project[2], OpenPantry, which I started some months ago after I'd learned Elixir pretty well and done a little Phoenix micro-service, but still hadn't done anything full stack or involving Ecto or Channels... We're actively looking for help building out the feature set and it's for a great cause if anyone's interested, helping those with food-insecurity to get food more easily and with more choice than many pantry programs are currently able to provide! [1]https://github.com/stride-nyc/remote_retro https://github.com/stride-nyc/remote_retro [2]https://github.com/MasbiaSoupKitchenNetwork/open_pantry https://github.com/MasbiaSoupKitchenNetwork/open_pantry
- ponyous 9y agoI've been learning elixir for past 10 months and will be releasing a project to the public hopefully by the end of the month. Is anyone interested in any specific topics? I plan to write an accompanying blog post when I release. Stack: Elixir, RethinkDB, Inferno (react alternative) + Redux (The goal when I started was to learn new things, hence the unusual stack)
- captainbeardo 9y agoFirst time I've ever seen that stack. +1
- revmoo 9y agoVery cool writeup. Also thanks for the reminder of how awesome my life is now that I'm out from under capital A Agile.
- richjdsmith 9y agoElixir was my Koolaid when it comes to functional programming. After getting the hang of pattern matching, I was hooked. Everything I'd do on Ruby/Rails, I just do on Elixir/Phoenix instead.
- dmix 9y agoClojure was my FP Koolaid, but Erlang (which I learned before Elixir) really blew my mind with it's pattern matching heavy syntax. I'm happy Elixir kept it as part it's core design patterns. So agreed it's a great abstraction that every modern language should be using. That plus extensive use of list comprehensions when working with arrays.
- tmat 9y agoI think what I learned the most about my past year of working heavily in Elixir is this.. Don't learn elixir.. learn Erlang/OTP if you really want to harness the power of Elixir. Elixir is nothing but a series of macros which give erlang some convenience and better syntax. If you learn to harness the power of Erlang, while writing it in Elixir, then you will see the beauty of it. Get away from Phoenix as fast as possible. Seriously it will do you wonders. It's so unnecessary and cumbersome. OTP, OTP, OTP.. can't say it enough.
- deathtrader666 9y agoCan you please explain your position a bit more?
- Toast_ 9y agoHow does Phoenix detract from from the elixir/erlang experience? I was under the impression that it was just a web framework? I'm pretty naive on the subject—I've just never seen something like this brought up before.
- tmat 9y agoWell in my situation Phoenix is really overkill. I don't build monolithic apps anymore. To me Phoenix felt lake taking Ruby and slapping it on Elixir. It didn't really feel like, "The Elixir Way." So I set out and learned Plug(which is mostly what Phoenix is). I build all my front ends as stand alone ReactJS apps, so I found it very strange to need Phoenix at all. I started learning to work with OTP & Plug and realized that I can build a json-api spec API in complete Elixir without any phoenix requirements and if I need to add sockets it's very very trivial to do so. The amount of code needed to make this all work in pure elixir is minimal. Essentially I just didn't need it for the way I build applications these days.
- Toast_ 9y agoThat makes sense. I was under the impression that you were saying something along the lines "Phoenix breaks erlang," but the complaint that Phoenix is too bulky is pretty common.
- jesses 9y agoThanks for the write-up. Have you thought about using gigalixir.com instead of Heroku?
- eggy 9y agoI picked up Elixir and LFE (Lisp Flavoured Erlang) at the same time. I prefer Lisps, and so I stuck with LFE, so my knowledge of the current state and capabilities of Elixir is lacking. Robert Virding who co-created Erlang, created LFE. He responded to Jose Valim in 2013 in a LFE vs Elixir thread [1]. I was accused of spreading misinformation when I made the same point recently on HN in another Elixir thread [2]. So my question is: Does Robert Virding's point still hold about Elixir's macros only able to use its predefined syntax, and not create new syntax like a Lisp can. I like Elixir, I just prefer Lisp's syntax. However, if Elixir is making these type of improvements I may want to revisit it, and to ensure I am not repeating old, incorrect information. Robert Virding uses this example (look at the thread for context): >> (defmacro kl >> ((list* k v rest) `(cons (tuple ',k ,v) (kl ,@rest))) >> (() ())) >> which I can use >> (kl a (+ 2 7) b 6) ==> (#(a 9) #(b 6)) Can Elixir do this or not? Thanks! [1] https://groups.google.com/forum/#!topic/lisp-flavoured-erlang/ensAkzcEDQQ [2] https://news.ycombinator.com/item?id=14390916
- CoderPuppy 9y agoYes, sorta. The point I think he was trying to make was that Lisp's syntax is less restrictive, but that seemed to get confused by: - mentioning the some people say it has no syntax (which it definitely does have) - saying macros can create new syntax (which they can't in Lisp) Elixir macros are approximately the same as Lisp macros (apart from not being able to take a variable number of arguments). This is a straight port of that macro into Elixir: defp kl_i([k, v | t]) do quote do [ {unquote(Macro.escape(k)), unquote v} | unquote kl_i t ] end end defp kl_i([]), do: quote do: [] defmacro kl(l), do: kl_i l # usage IO.inspect kl [a, 2 + 7, b, 6] # => [{{:a, [line: 16], nil}, 9}, {{:b, [line: 16], nil}, 6}] Note: Elixir's syntax does get in the way a bit here, the `a` and `b` are converted into nullary calls, you could use a different escaping function to fix this defp escape_key({v1, v2}), do: {escape_key(v1), escape_key(v2)} defp escape_key({:{}, pos, els}) when is_list(pos), do: {:{}, pos, Enum.map(els, &escape_key/1)} defp escape_key(els) when is_list(els), do: Enum.map(els, &escape_key/1) defp escape_key({sym, pos, nil}) when is_list(pos), do: Macro.escape sym
- 9y ago