Live data from Hacker News

Phoenix 1.3 is pure love for API development

swanros.com

31–40 of 57 posts

Re: Phoenix 1.3 is pure love for API development

#31
post #21

While action fallback sounds pretty useful, it feels like a framework solution to a language problem. The language just doesn't handle nested if statements very well. Also writing elixir always feels like the lines of code are longer than the width of my IDE. It is so much text... My Elixir (and phoenix) experience so far, has been far from amazing contrary to all the hype on hn all the time.

Why are you using if statements in a functional language geared towards pattern matching?

Re: Phoenix 1.3 is pure love for API development

#32

Can anyone point me to a decent fully contained example of a smallish app in Phoenix on something like github? I've spent a couple of hours reading some of the Elixir docs and getting familiar with some concepts, but I still have no idea how an Elixir app or a Phoenix app would actually look.

Sure! Josh Adams of Daily Drip recently did a Kickstarter [1] to build an open source forum in Elm, Phoenix & Elixir. You can follow the progress either with Daily Drip or just by watching the repository [2] as all the work is happening in the open.

For other repos, Elixir and Phoenix both have "topics" on github now so you can filter a search by repos which are tagged with those topics and order them by stars (obviously this does not sort the wheat from the chaff or the libraries from the projects though). [3]

Welcome to the community :)

[1] https://www.kickstarter.com/projects/1003377429/firestorm-an...

[2] https://github.com/dailydrip/firestorm

[3] https://github.com/search?o=desc&q=topic%3Aelixir+topic%3Aph...

Re: Phoenix 1.3 is pure love for API development

#33
post #29

Earlier quoted context omitted.

Interesting. While Elixir syntax definitely requires writing more code, than for example Ruby which I use the most, I have not been struggling too much. Could you give some examples of these long, problematic snippets? Also, what are the other things you did not like about Elixir/Phoenix? I am really curious to hear about them since, here on HN they are mostly praised and I wonder myself what are the cons (my experie…

$ irb [1, 2, 3, 4]. select {|n| n % 2 == 0}. map {|n| n * n}. reduce {|sum, n| sum + n} # 20 vs $ iex [1, 2, 3, 4] \ |> Enum.filter(fn(n) -> rem(n, 2) == 0 end) \ |> Enum.map(fn(n) -> n * n end) \ |> Enum.reduce(0, fn(n, sum) -> sum + n end) That Ruby code is so compact that I split it on multiple lines only to make the comparison easier. Even Python is more compact even if it's harder to read because of the reverse…

    scala>
    List(1,2,3,4).
      filter(_ % 2 == 0).
      map(x => x * x).
      reduce(_ + _)

Re: Phoenix 1.3 is pure love for API development

#34

Can anyone point me to a decent fully contained example of a smallish app in Phoenix on something like github? I've spent a couple of hours reading some of the Elixir docs and getting familiar with some concepts, but I still have no idea how an Elixir app or a Phoenix app would actually look.

I have worked with Elixir quite a lot, and I think I have a fair idea of how the language works in general, and how OTP apps are structured.

Even so, I find myself having the exact same issue as you are having when using Phoenix and Ecto. The way I like learning something new is by looking at something someone else has made. This gives me a much better view of how things are done than just reading getting-started guides and docs. I have looked, but I haven't found a lot of examples that actually applies to the latest versions of Phoenix and Ecto.

Re: Phoenix 1.3 is pure love for API development

#35
post #29

Earlier quoted context omitted.

Interesting. While Elixir syntax definitely requires writing more code, than for example Ruby which I use the most, I have not been struggling too much. Could you give some examples of these long, problematic snippets? Also, what are the other things you did not like about Elixir/Phoenix? I am really curious to hear about them since, here on HN they are mostly praised and I wonder myself what are the cons (my experie…

$ irb [1, 2, 3, 4]. select {|n| n % 2 == 0}. map {|n| n * n}. reduce {|sum, n| sum + n} # 20 vs $ iex [1, 2, 3, 4] \ |> Enum.filter(fn(n) -> rem(n, 2) == 0 end) \ |> Enum.map(fn(n) -> n * n end) \ |> Enum.reduce(0, fn(n, sum) -> sum + n end) That Ruby code is so compact that I split it on multiple lines only to make the comparison easier. Even Python is more compact even if it's harder to read because of the reverse…

I know you want to show it as parallel as possible, but: "pythonic" python (sum admittedly is a shortcut that only works for the special case +):

    sum(x * x for x in [1,2,3,4] if x % 2 == 0)

Re: Phoenix 1.3 is pure love for API development

#36
post #29

Earlier quoted context omitted.

Interesting. While Elixir syntax definitely requires writing more code, than for example Ruby which I use the most, I have not been struggling too much. Could you give some examples of these long, problematic snippets? Also, what are the other things you did not like about Elixir/Phoenix? I am really curious to hear about them since, here on HN they are mostly praised and I wonder myself what are the cons (my experie…

$ irb [1, 2, 3, 4]. select {|n| n % 2 == 0}. map {|n| n * n}. reduce {|sum, n| sum + n} # 20 vs $ iex [1, 2, 3, 4] \ |> Enum.filter(fn(n) -> rem(n, 2) == 0 end) \ |> Enum.map(fn(n) -> n * n end) \ |> Enum.reduce(0, fn(n, sum) -> sum + n end) That Ruby code is so compact that I split it on multiple lines only to make the comparison easier. Even Python is more compact even if it's harder to read because of the reverse…

[deleted]

Re: Phoenix 1.3 is pure love for API development

#37
post #29

Earlier quoted context omitted.

Interesting. While Elixir syntax definitely requires writing more code, than for example Ruby which I use the most, I have not been struggling too much. Could you give some examples of these long, problematic snippets? Also, what are the other things you did not like about Elixir/Phoenix? I am really curious to hear about them since, here on HN they are mostly praised and I wonder myself what are the cons (my experie…

$ irb [1, 2, 3, 4]. select {|n| n % 2 == 0}. map {|n| n * n}. reduce {|sum, n| sum + n} # 20 vs $ iex [1, 2, 3, 4] \ |> Enum.filter(fn(n) -> rem(n, 2) == 0 end) \ |> Enum.map(fn(n) -> n * n end) \ |> Enum.reduce(0, fn(n, sum) -> sum + n end) That Ruby code is so compact that I split it on multiple lines only to make the comparison easier. Even Python is more compact even if it's harder to read because of the reverse…

I'd like to share some solutions. This is a compact notation for Elixir using the capture operator `&` and importing all Enum functions:

  import Enum

  [1,2,3,4] \
  |> filter(& rem(&1,2) == 0 ) \
  |> map(& &1*&1) \
  |> reduce(0, & &1 + &2)

Also ExActor (https://github.com/sasa1977/exactor) library does exactly what you want: generates "standard double" GenServer functions and significantly reduces GenServer boilerplate.

I've discovered that it's significantly easier for me to get in the flow state of mind while programming in Elixir. Comfortable and powerful. Definitely a worthwhile investment of time and effort.

Re: Phoenix 1.3 is pure love for API development

#38
post #29

Earlier quoted context omitted.

Interesting. While Elixir syntax definitely requires writing more code, than for example Ruby which I use the most, I have not been struggling too much. Could you give some examples of these long, problematic snippets? Also, what are the other things you did not like about Elixir/Phoenix? I am really curious to hear about them since, here on HN they are mostly praised and I wonder myself what are the cons (my experie…

$ irb [1, 2, 3, 4]. select {|n| n % 2 == 0}. map {|n| n * n}. reduce {|sum, n| sum + n} # 20 vs $ iex [1, 2, 3, 4] \ |> Enum.filter(fn(n) -> rem(n, 2) == 0 end) \ |> Enum.map(fn(n) -> n * n end) \ |> Enum.reduce(0, fn(n, sum) -> sum + n end) That Ruby code is so compact that I split it on multiple lines only to make the comparison easier. Even Python is more compact even if it's harder to read because of the reverse…

Why not `import Enum` to get rid of the redundant `Enum.` part? As imports are lexically scoped there is no need to worry about name clashes (e.g. Enum vs. Stream):

        import Enum
        [1, 2, 3, 4]
        |> filter(fn(n) -> rem(n, 2) == 0 end)
        |> map(fn(n) -> n * n end)
        |> reduce(0, fn(n, sum) -> sum + n end)
While we're at it, why not use a `&` operator to shorten the lambdas:

        import Enum
        [1, 2, 3, 4]
        |> filter( &(rem(&1, 2) == 0) )
        |> map( &(&1 * &1) )
        |> reduce(0, &(&1 + &2))
...is it that much worse than Ruby then? It's a bit different - the syntaxes are different, after all - but it doesn't look much worse, I think.

Elixir, as well as Erlang, are peculiar languages. To achieve succinct code you need to phrase your code in a slightly different way, using pattern matching and guards, an occasional macro and alias/import commands (in Elixir's case).

And the separation between the external interface and an internal implementation of any GenSomething is a valuable thing! Even if in most cases the external interface does relatively little, it's important to have them separated. That is because the external interface functions execute in the caller process, while the implementation code executes in the OTP process. If the caller submits an invalid value to be called/cast to your server, do you want to crash the caller or the server? With the usual pattern, you get to make this choice. And let's be honest - in the simplest case, it's three one-line functions (start, call, cast) per GenServer - it's not that bad of an overhead. There's also Agent module for when you don't need a full GenServer, using it eliminates all the overhead (in terms of lines of code) you normally get when using GenServer.

Re: Phoenix 1.3 is pure love for API development

#39
post #35
post #29

Earlier quoted context omitted.

$ irb [1, 2, 3, 4]. select {|n| n % 2 == 0}. map {|n| n * n}. reduce {|sum, n| sum + n} # 20 vs $ iex [1, 2, 3, 4] \ |> Enum.filter(fn(n) -> rem(n, 2) == 0 end) \ |> Enum.map(fn(n) -> n * n end) \ |> Enum.reduce(0, fn(n, sum) -> sum + n end) That Ruby code is so compact that I split it on multiple lines only to make the comparison easier. Even Python is more compact even if it's harder to read because of the reverse…

I know you want to show it as parallel as possible, but: "pythonic" python (sum admittedly is a shortcut that only works for the special case +): sum(x * x for x in [1,2,3,4] if x % 2 == 0)

Works in Elixir, too...

    Enum.sum(for x 
Edit: BTW: I'm not sure, but I think Erlang had list comprehensions even earlier than Python.

Re: Phoenix 1.3 is pure love for API development

#40
post #34

Can anyone point me to a decent fully contained example of a smallish app in Phoenix on something like github? I've spent a couple of hours reading some of the Elixir docs and getting familiar with some concepts, but I still have no idea how an Elixir app or a Phoenix app would actually look.

I have worked with Elixir quite a lot, and I think I have a fair idea of how the language works in general, and how OTP apps are structured. Even so, I find myself having the exact same issue as you are having when using Phoenix and Ecto. The way I like learning something new is by looking at something someone else has made. This gives me a much better view of how things are done than just reading getting-started gui…

For what it's worth, this is generally where the "build a blog" type examples come in handy.

It's a simple, repeatable process that gets you through the basics of the architecture across the board. You'll get a couple of routes, a couple of controllers, a little bit of database access, a bit through the view layers and by the time you're done you'll have a simple app that you can experiment with. It's generally my go-to "learn the language" process for anything.

I didn't open source it, but here's a little write up on mine.

http://www.brightball.com/articles/insanity-with-elixir-phoe...

Post reply on HN