Definitely looks like empirical proof to me :) On Mon, May 23, 2016 at 12:35 PM, max s <[email protected]> wrote:
> @Onorio > > You're right, we should not take assumptions before benchmarking even > though I think my intuition was justified. I wrote a quick code that I > profiled with fprof and I get 3~4 better performances using the matching on > constants ; you can see the gist here > https://gist.github.com/anonymous/3cf62215407b829da4ab013d111cebfe (let > me know and correct me if there's a mistake in my profiling). > > @José > > Agreed and actually it'd be more in line with erlang philosophy of doing > things > > Max > > On 23 May 2016 at 17:45, José Valim <[email protected]> > wrote: > >> Why not use atoms? Atoms are precisely that: constants. >> >> >> >> *José Valim* >> www.plataformatec.com.br >> Skype: jv.ptec >> Founder and Director of R&D >> >> On Sun, May 22, 2016 at 12:16 PM, Nytz12 <[email protected]> >> wrote: >> >>> Hi >>> >>> I use the following pattern to define cross module constants >>> >>> defmodule Visitor do >>> >>> defmodule FilterTypes do >>> def c_GREATER_THAN, do: "greater_than" >>> def c_LESS_THAN, do: "less_than" >>> def c_IS, do: "is" >>> def c_IS_NOT, do: "is_not" >>> end >>> ... >>> >>> Which lets me do something like this from other modules >>> >>> Visitor.FilterTypes.c_GREATER_THAN # == "greater than" >>> >>> Problem is that I just discored that these 'constants', which are really >>> function calls, cannot be used to do pattern match like: >>> >>> def filter(query, filter, field, value) do >>> case filter do >>> FilterTypes.c_GREATER_THAN -> greater_than(query, field, value) >>> FilterTypes.c_LESS_THAN -> less_than(query, field, value) >>> FilterTypes.c_IS -> is(query, field, value) >>> FilterTypes.c_IS_NOT -> is_not(query, field, value) >>> _ -> {:error, "unknown filter", filter} >>> end >>> end >>> >>> Is there a better approach i'm missing? >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "elixir-lang-talk" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/elixir-lang-talk/ace6b869-dfce-4d3f-aeeb-2d9bc4583f03%40googlegroups.com >>> <https://groups.google.com/d/msgid/elixir-lang-talk/ace6b869-dfce-4d3f-aeeb-2d9bc4583f03%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "elixir-lang-talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-talk/CAGnRm4KmHUN5PHYgoV4hT9tyOnN--o9ysuRoofi5V%2B%3DfJSth8Q%40mail.gmail.com >> <https://groups.google.com/d/msgid/elixir-lang-talk/CAGnRm4KmHUN5PHYgoV4hT9tyOnN--o9ysuRoofi5V%2B%3DfJSth8Q%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to a topic in the > Google Groups "elixir-lang-talk" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/elixir-lang-talk/l-7rK9_bT2Q/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-talk/CAOPKHev-O0ZdDURxp144Xp4UrT-0FWECVYfNRwxyrg6HRkP0vQ%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-talk/CAOPKHev-O0ZdDURxp144Xp4UrT-0FWECVYfNRwxyrg6HRkP0vQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Onorio Catenacci http://onor.io http://www.google.com/+OnorioCatenacci -- You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/CAP%3DvNq8U5rmL%3DxfZ2UT4VJ4hDOgPaUqzThKZoSmOO8FJjZLRhw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
