Mind blowing Elixir

community
#21

I have to say the let it crash mentality, before meeting Elixir I always thought I should avoid crashes make sure that nothing crashes and deal with different crashes all the time.
After meeting Elixir threads finally clicked threads can crash we deal with it and are not afraid of it.
That basically changed my whole view point to threads, they are our friends not our enemy, at least when you know how to use them.
Immutability was great too, but let it crash mentality is the best thing that happened to my coding and made 10 times better in my job.
I think that since I met this forum I only had one instance of singleton problem and that was because ruby duplicate sometimes do weird things.

3 Likes

#22

I can’t even begin to say how much it opened my mind to FPs in general. Particularly, for me, as I do full time OOP every day ( aka, from jvm world).

There isn’t just one thing that I’ve come across and I’d say shut the f* up… this can be done? apart from what others have said, the absolute one thing that still astonishes me is the simple, yet most powerful concept of Erlang/Elixir is the pattern matching.

There’s this simple, argument pattern matching for argument – which is ok I believe, but slicing & dicing the input, simply blew my socks off!

Below is something I’m currently on

  defmodule Decoder do
    # 10 byte metadata
    # 5 bytes
    @redis_signature <<"REDIS"::utf8>>
    # 4 bytes - big endian
    @version <<3::big-size(24)>>
    # 1 byte
    @db_selector <<254::size(8)>>

    def read_metadata(
          <<@redis_signature, version::big-size(24), @db_selector,
            actual_data::bitstring>>
        ) do
    end
3 Likes

#23

honestly, coming from a main JS background, I was already doing fp anyhow, but the simplicity and elegance that elixir provide makes it a pleasure to work with it. I can’t say i have ever been in love with a language, but I think I am starting too fall for it… hahaa

3 Likes

#24

Although I was already familiar with some functional programming concepts, and had a glimpse of pattern matching and using tail-call recursion, I found Elixir quite approachable compared to other languages (at least for me) and Erlang/OTP’s approach to concurrency using processes/actors is what I found the most mind-blowing. I learn something cool and useful every few days and I’m just scratching the surface.

The core concepts of the language are straightforward: I doesn’t have a huge standard library and many things boil down to modules, functions and macros (which I’m not very familiar with yet), but when you need more advanced things (like concurrency, async code, additional standard libraries from Erlang, distributed computing, etc.) they’re there for you, and the whole tooling/documentation and conveniences of iex just make the whole experience of experimenting, debugging and coding more enjoyable.

4 Likes

#25

Threads as an actual PL abstraction, like objects, instead of a nasty implementation detail that you avoided unless you really needed them.

Processes: 4684 and, from what I’ve heard, that’s still not very much.

2 Likes

#26

Javascript will have pattern matching some time in the future :slight_smile: https://github.com/tc39/proposal-pattern-matching

2 Likes

#27

That is far from certain.

It’s a Stage 0 proposal with an initial commit of 2017-07-03 which hasn’t even been presented to the committee at this point.

Proposals at Stage 3 may be included in ES2019.

So a lot can happen and it is going to take some time …

7 Likes

#28

Enum.reduce/3

If you wrap your head around that function, you’ll be blown away at what you can do.

5 Likes

#29

I am using Elixir to mentor some people who have not been professional programmers. In some ways it’s easier for them to use a functional language after never having had experienced object oriented languages.

We are trying to invite 10-20 scholarship attendees to women and minorities for GigCityElixir, and we don’t want them to be lost when they get to hear the big guns: Dave Thomas, John Hughes, Chris McCord, Stu Halloway, etc.

Very cool.

6 Likes

#30

Well, for me, the day I really understood the BEAM is the day Elixir blown my mind. And two talks helped to understand that.

In the first one @josevalim takes some time to explain the concepts behind Elixir (which are pretty much the concepts behind the BEAM), and it blown my mind because it’s so much simpler and more organized than OO that I cannot call it other way than a masterpiece!

And in the second one, @sasajuric explains in a very practical way what is the real power of the BEAM: its concurrency model, the runtime guarantees it gives you, the price you pay to have them, and why this price is fair. :slight_smile:

I know one can argue that it was not Elixir that blown my mind then, but the thing is: other BEAM languages never got me interested enough since I felt too productive with Ruby compared to them, and Elixir changed that! The efforts on making it easy to learn and productive really paid out!

6 Likes

#31

I also watched this. This talk is truly amazing and an eye opener for the devs from other programming environment/languages. This talk alone is enough to establish erlang/elixir as mind blowing

1 Like

#32

Code maintainability and comprehension for decent multi-core performance on a stable VM.
I rarely get that sinking feeling of technical debt
i.e. oh crap why am I doing this… this is going to be hard to maintain or change 10 years from now.

As a part-time programmer and business manager, Elixir is incredibly refreshing to write and maintain systems with.

3 Likes

#33

I was already in love with pattern matching from other languages. That stuff is seriously addicting. Like no turning back addicting.

I started a new job and Elixir was the only language in a list of pre-approved languages to write new stuff in.

Honestly…what blew my mind the most was realizing that this is what Akka is emulating. Except this is the real deal. No more messing with ExecutionContexts or defining huge nests of case classes. Or worrying about Haskellisms.

I love Elixir. It’s scratching every itch.

3 Likes

#34

One silly thing that really surprised me (coming from a Java World a while ago…) was this simple snippet:

raise_msg = &"Ooooops... something went wrong! Something: #{inspect(&1)}"

# some logic and then...

raise raise_msg.("bad thing")

Maybe this is common to Rubists and the like but it’s simple and I like it.

The first thing that shocked me on the BEAM was the fridge example in Learn You Some Erlang for Greater Good. It was that moment when light weight processes made sense and from there to gen_servers was easy. This is still my recommendation when someone is new to the BEAM (although it is written in erlang, it is really well written and easy to follow…).

Here is the final code that made me understand how to deal with mutable state using processes in an immutable language with recursion:

-module(kitchen).
-compile(export_all).

start(FoodList) -> spawn(?MODULE, fridge2, [FoodList]).

store2(Pid, Food) ->
    Pid ! {self(), {store, Food}},
    receive
        {Pid, Msg} -> Msg
    after 3000 ->
        timeout
    end.

take2(Pid, Food) ->
    Pid ! {self(), {take, Food}},
    receive
        {Pid, Msg} -> Msg
    after 3000 ->
        timeout
    end.

fridge2(FoodList) ->
    receive
        {From, {store, Food}} ->
            From ! {self(), ok},
            fridge2([Food|FoodList]);
        {From, {take, Food}} ->
            case lists:member(Food, FoodList) of
                true ->
                    From ! {self(), {ok, Food}},
                    fridge2(lists:delete(Food, FoodList));
                false ->
                    From ! {self(), not_found},
                    fridge2(FoodList)
            end;
        terminate ->
            ok
    end.
4 Likes

#35

Just discovered this one:

iex
iex(1)> :wx.demo()
4 Likes

#36

There are a lot of features of Elixir that are great, but this is probably the first thing I would mention as well. It’s amazing how much code this feature alone can clear up.

Another thing that impresses me is how fast new versions of Elixir are released. I feel like it wasn’t even that long ago I got the Programming Elixir 1.2 book and now the 1.6 book is out, but 1.8 is the latest version :stuck_out_tongue_closed_eyes:

1 Like

#37

It blows my mind how much you can learn about good software practices by reading the debates here, watching Elixir conferences or taking a course on elixir.

8 Likes

#38

Something like that:

defmodule MyMind do
  @moduledoc "Simplified implementation of my mind on timeline!"

  @date_join ~D[2016-05-11]

  @doc "Not sure how much extra online English lessons affects those results …"
  @spec at(Date.t()) :: String.t()
  def at(date), do: date |> Date.compare(@date_join) |> do_at()

  defp do_at(:lt), do: "I think … I'm … fine … thank you …"
  defp do_at(_), do: "Yo bro! I'm great, thanks! And you?"
end

btw. Last time I tried to properly remind my past, but I hit such error:

Exception in thread "main" java.lang.StackOverflowError
        at java.io.PrintStream.write(PrintStream.java:480)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
        at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
        at sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:104)
        at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:185)
        at java.io.PrintStream.write(PrintStream.java:527)
        at java.io.PrintStream.print(PrintStream.java:669)
        at java.io.PrintStream.println(PrintStream.java:806)
        at MyMind.recursiveRemindPast(MyMind.java:65505)
        at MyMind.recursiveRemindPast(MyMind.java:65535)
        at MyMind.recursiveRemindPast(MyMind.java:65535)
        at MyMind.recursiveRemindPast(MyMind.java:65535)
        ...

Looks like there is still lots of work for me! :077:

2 Likes

#39

reduce is god. Didn’t really sink in until I started using a functional language for real.

Macros are fine, but macros calling other macros still makes my head hurt.

Pattern matching is the thing I miss most when working with other langs.

3 Likes

#40

Didn’t knew we had test coverage built-in.

Simply run:
mix test --cover

5 Likes