RubyTapas Episode 4: Barewords

13 comments

  1. I always thought which version is better:

    def full_name; “#{@first_name} #{@last_name}”; end
    def full_name; “#{first_name} #{last_name}”; end

    So you’re suggesting to stick with the second variant when there’s attr_reader for both :first_name and :full_name specified?

  2. Great video, and a neat pattern. Elixir has a similar mechanism — mixfiles take advantage of it (see deps):

    defmodule MyApp.Mixfile do
    def project do
    […,
    deps: deps]
    end

    defp deps do
    [{:ecto, “~> 0.3.0”}]
    end
    end

    When reading more complex code, barewords for function calls does make the references harder to trace; you have to check multiple contexts to know how a reference is being resolved. I rambled about that here: http://jtmoulia.pocketknife.io/blog/2015/03/12/elixir-fun-call-parens/

Leave a Reply

Your email address will not be published. Required fields are marked *