Phoenix 1.3 is pure love for API development
51–57 of 57 posts
Re: Phoenix 1.3 is pure love for API development
#52Earlier quoted context omitted.
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…
Hi, Take a look at the Building Umbrella Project from elxirconf: https://github.com/poteto/elixirconf-201620 by Wojtek Mach. The source: https://github.com/wojtekmach/acme_bank22 is a great example of an umbrella app. For example, he uses two instances of phoenix (backoffice and bank_web). It's a working app, so you can experiment with it too. The talk is here: https://www.youtube.com/watch?v=6NTmUQClHrU18 I found it…
https://github.com/poteto/elixirconf-2016
Re: Phoenix 1.3 is pure love for API development
#53Re: Phoenix 1.3 is pure love for API development
#54Earlier 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)
sum(x * x for x in [1,2,3,4] if not x % 2)
and it matches this Ruby 2.4.0 (which added Array#sum) [1,2,3,4].map{|x| x.even? ? x * x : 0}.sum
You understood correctly that the point was not sheer compactness. I only wanted to provide a context to judge the Module.function syntax compared to the object.method one. The filter, map, reduce example was accidental and I'm sure there are clever ways to compact that example further in both languages.So the pythonic way is be
reduce_function(map_function(x) for x in input if filter_condition)
I prefer to write it in the order it runs (filter -> map -> reduce) but that's it. Thanks.Re: Phoenix 1.3 is pure love for API development
#55Earlier 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…
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)…
Re: Phoenix 1.3 is pure love for API development
#56While 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.
One of the advantages of this language I've found is that I specifically DO NOT need to nest "if" statements anymore! Hie thee to pattern-matching and private functions that take different states (which are normally handled by nested ifs).
Also, nested ifs are REALLY hard to test well, and breaking them out into separate functions with the same name but different clauses makes it MUCH easier to unit-test.
Re: Phoenix 1.3 is pure love for API development
#57Earlier quoted context omitted.
Be careful: that is a framework, not a language feature.
Is a language useful without useful frameworks around it?