Live data from Hacker News

Phoenix 1.3 is pure love for API development

swanros.com

21–30 of 57 posts

Re: Phoenix 1.3 is pure love for API development

#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.

Re: Phoenix 1.3 is pure love for API development

#22
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.

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 experience has been great so far).

Re: Phoenix 1.3 is pure love for API development

#23
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.

My first thought when I read this was that it sounds like you're struggling against the language because you're trying to use it in an imperative fashion. I'm well aware this may not be correct but it's what I'm going to assume for the rest of this comment, so please forgive me if it's incorrect.

Elixir is a functional language, and while it's not pure, nested if statements deliberately do not belong.

The if statement itself is actually just a macro to a case/switch, the only reason it is there is to reduce the verbosity in cases where only one conditional branch is needed, José felt the practicality of this outweighed the fact it may get abused.

To use Elixir properly is to try and move away from conditional constructs as much as is realistically possible. This means instead using pattern matching, guard classes and multiple clause functions (both named and anonymous).

Once you take advantage of these you'll find your code stays flatter while keeping the individual branches of your conditional logic tied up into small independently testable functions.

If anyone would like to read more, I found these [1] [2] to be helpful.

[1] http://culttt.com/2016/05/30/branching-conditionals-elixir/

[2] http://blog.lucidsimple.com/2016/01/24/pattern-matching-help...

Re: Phoenix 1.3 is pure love for API development

#24
post #4

I've wanted to use Phoenix a few times but every tutorial to get me started relied 100% on ecto which for something like a transformation API was frustrating. I didn't want the complexity of a database I wanted to learn the request lifecycle in it. Overall, it was challenging with too many resources being out of date or just so focused on a different type of API than I needed to build

If you want to learn Phoenix without Ecto. Checkout my screencasts: https://www.youtube.com/playlist?list=PL_uO5Hv34JImYx9zN73wD... It builds a simple Broken Links application which finds broken links in an input url

Re: Phoenix 1.3 is pure love for API development

#25
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.

It is not an imperative language. You can't hit a nail with a screwdriver. Well, you can, but... ;)

Re: Phoenix 1.3 is pure love for API development

#26
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.

Elixir is essentially just erlang, with a more convenient syntax. Being a functional language, you shouldn't be doing nested if statements in the first place. The if statement in elixir is really just a case-switch macro.

Also writing elixir always feels like the lines of code are longer than the width of my IDE

This just seems weird to me. The pipe operator makes the code really compact in my experience, and I wish other languages had this feature.

I have a feeling you never bothered to really learn the language and just jumped on the new fancy framework, and tried to glue some code you didn't understand.

You struggling to write something isn't a language problem. I'm interested in seeing some examples that highlight your problems.

Re: Phoenix 1.3 is pure love for API development

#27
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.

Re: Phoenix 1.3 is pure love for API development

#28

I can't wait until May[0] for the new 'Programming Phoenix' book. I found the first edition to be a great learning experience. [0] http://shop.oreilly.com/product/9781680502268.do

Thanks for the tip - just bought a Kindle copy. I was going to get the hardcopy, but Yikes, WHAT has happened to the cost of freight recently?!? It was going to cost minimum $45 to ship a $35 book to Australia!!

Re: Phoenix 1.3 is pure love for API development

#29
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.

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 order (I'm sure that there is a nested comprehension for that but it's beyond my comprehension skills)

    from functools import reduce
    reduce(lambda x, sum: sum + x, \
    map(lambda x: x * x, \
    filter(lambda x: x % 2 == 0, \
    [1, 2, 3, 4])))
    # 20
The problem here is having to type Module.function(value) vs object.method

OO languages have a more compact notation because objects act as namespaces. Elixir has alias but it doesn't help much and must be used wisely. alias Enum, as: E would only confuse people and gain little.

Then Elixir has too many do end compared to Ruby (coming from Ruby I feel them unnecessary), but that's not a big deal.

Moving from syntax to programming patterns, having to define twice my functions in GenServer (internal API and public API) is too much boilerplate. I'd like to have time to study macros really well and end up with a DryGenServer that lets me def the external API with the internal implementation. Maybe I'll defmacro a defasync and a defsync, that generate the standard "double" GenServer functions.

Re: Phoenix 1.3 is pure love for API development

#30

I can't wait until May[0] for the new 'Programming Phoenix' book. I found the first edition to be a great learning experience. [0] http://shop.oreilly.com/product/9781680502268.do

Thanks for the tip - just bought a Kindle copy. I was going to get the hardcopy, but Yikes, WHAT has happened to the cost of freight recently?!? It was going to cost minimum $45 to ship a $35 book to Australia!!

I can only assume continental drift...
Post reply on HN