News for hackers. Stuff that matters.
Re:Elixir RAM and the Template of Doom by bpicolo on Tuesday April 26, 2016 @11:37AM (#11572751)
It's been getting a massive amount of attention lately, really. Well deserved too. Phoenix is the sanest out-of-box web framework I've experienced.
Re:Elixir RAM and the Template of Doom by colbyh on Tuesday April 26, 2016 @12:22PM (#11573181)
I love it too but I'll push a little on "sanest out-of-box" web framework. template/view rendering is a bit more complex than it needs to be. totally understand that it's a side effect of pattern matching but I'd appreciate a little less "magic" when it comes to matching views to render statements.

and not to throw yet another buzzword at this post but Phoenix is the best framework I've found yet for smaller networked services. so enjoyable to build with.

Re:Elixir RAM and the Template of Doom by chrismccord on Tuesday April 26, 2016 @12:51PM (#11573485)
I'm genuinely curious what you feel is too magical with how we handle rendering? Templates are compiled as `render/2` function clauses on the view module, so there's no magic going on. As you said, we do lean on pattern matching, but that's a product of the language and how you structure a large amount of your own code, not anything tricky we're doing.

For example, if I have an `user/index.html.eex` template for a `UserView` module, I can render it with:

    View.render(UserView, "index.html", name: "colbyh")
At compile time, we simply precompiled the index.html.eex template as a `def render("index.html", assigns) ...` function clause.

Now imagine I want a `bio.html` template. Instead of making a template file, I can literally do this in my view:

    def render("bio.html", assigns) do
      "Bio: name: #{name assigns.name}"
    end
    ...
    View.render(UserView, "bio.html", name: "colbyh")
    => "Bio: name: colbyh"
And it Just Works exactly because there's no magic going on. Templates are just function calls, whether they are precompiled from a template engine or defined by the user manually.
Re:Elixir RAM and the Template of Doom by bpicolo on Tuesday April 26, 2016 @12:56PM (#11573535)
I think the confusion mostly lies in the Views. The difference between controllers and Views and why views are actually necessary to render templates is not especially obvious, and it almost feels like the explicit view layer isn't entirely necessary. (From the developer API perspective, and not necessarily the framework design perspective)
Re:Elixir RAM and the Template of Doom by chrismccord on Tuesday April 26, 2016 @01:10PM (#11573682)
The distinction between views and templates is something that does trip folks up sometimes when coming from other areas that make no distinction or use the terms interchangeably. For us, this distinction is extremely important:

- templates are just functions

- Views render templates and serve as a presentation layer

Re:Elixir RAM and the Template of Doom by phlakaton on Tuesday April 26, 2016 @03:30PM (#11574828)
I'm just starting to learn Elixir and Phoenix. Here are two little bits of "magic" that have thrown me for a loop so far:

1. @var's in templates are not module attributes (though they do seem to be convenient!)

2. The form for `use` is different in Phoenix than it is in Elixir proper – instead of passing opts, you pass an atom that selects the implementation of __using__ you want. (This bit of magic makes no particular sense to me – why wouldn't you just use a submodule, say MyApp.Controller, that has the correct and single __using__ attached?)

Re:Elixir RAM and the Template of Doom by true_religion on Thursday April 28, 2016 @02:55AM (#11586941)
> The form for `use` is different in Phoenix than it is in Elixir proper – instead of passing opts, you pass an atom that selects the implementation of __using__ you want.

This isn't really true. If you check out the ExUnit, you can pass something like "use ExUnit.Case, aysnc: true" and it'll setup your module to run tests asynchronously. You can pass any atom/value combination into use.

HTTPoision.Base, and ExAws to name a few other projects also have the convention of passing options into __using__.

To me, the confusion comes from the fact that the Elixir get-started documentation doesn't say anything about this. It is however listed in the Kernel forms that "use Module" actually just translates to Module.__using__([])

Re:Elixir RAM and the Template of Doom by phlakaton on Saturday April 30, 2016 @07:35PM (#11604136)
That's the point though - in those cases, you're passing a keyword list, a set of options, instead of an atom which acts as a selector. IIUC the Web module violates the convention attached to and documented for `use`, which to me, who was already wrangling with the subtleties of what `use` does compared to, say, Ruby's include, or Elixir's alias/import, was a bit of confusing (and relatively unconventional) magic.
Re:Elixir RAM and the Template of Doom by colbyh on Tuesday April 26, 2016 @08:02PM (#11576819)
you can define `__using__` any way you want, and phoenix's default isn't technically any different. it's just a convention that you can choose to use or not, personally I try to rip out a lot of what the `web.ex` file does because I like being more explicit.
Re:Elixir RAM and the Template of Doom by colbyh on Tuesday April 26, 2016 @06:24PM (#11576248)
it's entirely possible that I learned the framework pretty early on and not keeping up with small API changes has made it seem more complex than it needs to be.

I seem to remember earlier documentation using a lot of render calls directly in the controller, and add to that the fact that view functions were available to both controller modules and templates without any explicit inclusions muddied the waters a bit. your explanation makes total sense though and the documentation is now clearer than I remember so chalk it up to growing pains? haha.

and having templates that precompile to render functions is pretty magical, tbh. would personally love it if the view documentation reflected this on some level.

Re:Elixir RAM and the Template of Doom by chrismccord on Tuesday April 26, 2016 @07:24PM (#11576587)
Our view system has been like this from day one, so not growing pains, but it's possible our documentation wasn't as comprehensive early on.

> having templates that precompile to render functions is pretty magical, tbh. would personally love it if the view documentation reflected this on some level.

You mean like in our nicely formatted ExDocs? :) The docs walk you through similar examples as I've posted here, but go more in depth. https://hexdocs.pm/phoenix/Phoenix.View.html

Re:Elixir RAM and the Template of Doom by colbyh on Tuesday April 26, 2016 @07:59PM (#11576800)
bad choice of words, I meant more of us growing to understand the framework. and since you've had to answer these sorts of questions before I def feel a little less crazy: http://www.jeramysingleton.com/phoenix-templates-are-just-fu...

and thanks for keeping up work on the docs!

Re:Elixir RAM and the Template of Doom by bpicolo on Tuesday April 26, 2016 @12:42PM (#11573394)
I mean, I have a bone to pick with most web frameworks in that they leave a lot out of what I'd consider ready-to-go for an app. Phoenix does a number things better than most, like sane JS env, consideration of production vs dev configs, and some other stuff.

Most out-of-box apps are too simple, and most web framework app skeletons are insanely overdesigned and, frankly, miserable. Certainly there are a number of big frameworks (django, rails) that can give you most things out of the box, but I'm not a fan of heavyweight frameworks in general. I think Phoenix strikes a great balance

Re:Elixir RAM and the Template of Doom by davidw on Tuesday April 26, 2016 @12:02PM (#11572991)
What in particular do you like about it? I've used Erlang plenty, but haven't had much occasion to use Elixir and Phoenix.
Re:Elixir RAM and the Template of Doom by jfaucett on Tuesday April 26, 2016 @12:16PM (#11573126)
"What in particular do you like about it?"

As someone who has also used Erlang in the past I can tell you what's nice about Elixir: super modern developer friendly ecosystem. Mix - the pkg manager - is dead simple and does the job well, the docs are amazing with tons of examples and direct links to source code everywhere. The language itself also has some nice syntactic sugar over standard Erlang, and integrating with Erlang was a breeze. Overall the whole system is just smooth and works. I was impressed.

Re:Elixir RAM and the Template of Doom by davidw on Tuesday April 26, 2016 @12:19PM (#11573155)
Yeah, Elixir is nice in a lot of ways, and is a much needed shot in the arm for Erlang.

I should have been more specific: what about Phoenix do you like?

Re:Elixir RAM and the Template of Doom by alexgaribay on Tuesday April 26, 2016 @12:12PM (#11573094)
I haven't used Erlang but I've been using Elixir daily for the past 5 months. Coming from Scala, it has been wonderful with pattern matching everywhere the syntax is very easy to get used to. The Elixir docs are very amazing as well as many of the core/common libraries. Phoenix is not excluded either. The performance of the framework is amazing as well as how simple and productive the framework is. The Elixir community as a whole is great.
Re:Elixir RAM and the Template of Doom by vvanders on Tuesday April 26, 2016 @12:28PM (#11573247)
Most of other comments are on the mark about Mix.

The other bit for me is Elixir's macro support. This lets you do really clean route matching in Phoenix. See http://www.phoenixframework.org/docs/routing for some examples.

Re:Elixir RAM and the Template of Doom by davidw on Tuesday April 26, 2016 @12:54PM (#11573514)
Coming from an Erlang background, those are potentially both a blessing and a curse, in that Erlang places a lot of value on being explicit and readable, to the point of being somewhat repetitive in places. It's something to use sparingly and with caution, IMO.
Re:Elixir RAM and the Template of Doom by dimgl on Tuesday April 26, 2016 @01:05PM (#11573630)
You can make an Elixir HTTP server without Phoenix and it's just as easy and intuitive. Pretty happy with it so far.
Re:Elixir RAM and the Template of Doom by melling on Tuesday April 26, 2016 @11:43AM (#11572810)
How's the editor support? I'm open to any editor or IDE.
Re:Elixir RAM and the Template of Doom by supernintendo on Tuesday April 26, 2016 @12:03PM (#11573004)
I use Emacs with Alchemist [1] and I love it. The integration of common tasks like module reloading, testing and inline evaluation have all increased my productivity when writing Elixir. Code completion, Phoenix support and the ability to quickly jump to function definitions within a project are all nice features as well.

[1] https://github.com/tonini/alchemist.el

Re:Elixir RAM and the Template of Doom by vdaniuk on Tuesday April 26, 2016 @11:52AM (#11572905)
Atom has recently gained a significantly better support with the atom-elixir package. Adding language-elixir and linter-elixir packages creates a moderately enjoyable experience.
Re:Elixir RAM and the Template of Doom by tmichael0 on Tuesday April 26, 2016 @11:54AM (#11572925)
I'm currently using Atom with this package: https://github.com/msaraiva/atom-elixir
Re:Elixir RAM and the Template of Doom by bpicolo on Tuesday April 26, 2016 @11:50AM (#11572888)
Depends on what you're used to. Certainly you get the normal bits that editors all support: text coloring, autocomplete + basic code complete stuff + whatever linter people have created. Not resharper or heavyweight sorts of IDE things yet.

I never had any issues here with sublime

Re:Elixir RAM and the Template of Doom by ane on Tuesday April 26, 2016 @11:51AM (#11572894)
Alchemist for Emacs is truly wonderful.
Re:Elixir RAM and the Template of Doom by schpaencoder on Tuesday April 26, 2016 @11:50AM (#11572882)
You really want to try Spacemacs (emacs with layers) with Alchemist
Re:Elixir RAM and the Template of Doom by gamache on Tuesday April 26, 2016 @11:47AM (#11572844)
I use MacVim + the Janus extensions[1] and it's great. I hear good things from people using Atom and Sublime too.

[1] https://github.com/carlhuda/janus

Re:Elixir RAM and the Template of Doom by andy_ppp on Tuesday April 26, 2016 @11:49AM (#11572876)
It's rubbish, but the IntelliJ plugin is improving at a rate of knots:

https://github.com/KronicDeth/intellij-elixir