Would you use Erlang now when there is Elixir?

Thanks, it’s a good reminder.

[Edit: As Eiji points out, my snippet here leaves out the assignment (facepalm). Should of course be x = if x == 2, do: x in which case x becomes a nil. And I guess something like x = if x == 2, do: 4, else: x does start to seem a bit cumbersome.]

Though when I try in iex with a false value I get the condition returning nil but x is still bound to the original value.

iex(1)> x = 1
1
iex(2)> if x == 2, do: x 
nil
iex(3)> x
1  

I don’t think I understand why this happens, and thanks for mentioning the implicit else: nil.

2 Likes

You did not made an assignment. Add x = at start of this line.

3 Likes

I just realized that and came back, omg I need some sleep, thanks!

Should have been:

iex(4)> x = if x == 2, do: x
nil
iex(5)> x
nil
2 Likes

Contrary to what other people coming from Ruby think, I started to like Erlang’s syntax more than Elixir’s.
Two days ago I tweeted about it,

3 Likes

I wonder if we need a dedicated thread about Erlang syntax - not just with examples comparing it to Elixir but in comparison to other languages too, because we often hear people from lots of different languages say the Erlang syntax was a blocker for them.

I also wonder if the Erlang team are working on a new ‘modernised’ version of Erlang? In the same sort of way Apple did with Swift and Obj-C (wonder if Robert or @bjorng has any info here?)

Anyway back to the syntax, here’s an example from the Elixir site: https://elixir-lang.org/crash-course.html#running-code

Erlang

% module_name.erl
-module(module_name).  % you may use some other name
-compile(export_all).

hello() ->
  io:format("~s~n", ["Hello world!"]).
Eshell V5.9  (abort with ^G)
1> c(module_name).
ok
1> module_name:hello().
Hello world!
ok

Elixir

# module_name.ex
defmodule ModuleName do
  def hello do
    IO.puts "Hello World"
  end
end
Interactive Elixir
iex> c("module_name.ex")
[ModuleName]
iex> ModuleName.hello
Hello world!
:ok:

Personally I prefer def and ends as visual indicators of where function/module definitions start end. I am not keen on white-space dependency like in languages like Python (I find it difficult registering them at a quick glance).

I’ve also read comments about the . in Erlang was used because it mimics normal sentences, but I just feel they are superfluous (in the same way ;'s are in JS).

For me personally I prefer syntax that:

  • looks balanced when viewed
  • feels natural
  • is intuitive
  • isn’t convoluted (endless/needless brackets and semicolons etc)
  • isn’t too sparse (like Pythons)
  • isn’t whitespace dependent (like Pythons)

Having said that, these are just preferences and perhaps a big factor in how much I might ‘love’ a language. So while this may not stop us using a language, it’s probably fair to say if we had to choose between two languages where all else is similar, we would, understandably, opt for the one which has the syntax that resonates with us most. (Imo anyway)

4 Likes

The elixir syntax is full of a lot of weird stuff like the one with with I mentioned above. Here is another

def foo
do
  IO.puts "Hello World"
end

which is illegal. You say you don’t like languages that isn’t whitespace dependent but elixir is very newline dependent. Which is something that annoys me immensely.

I honestly don’t really understand how people can find syntax to be a blocker. I have used many different languages with many different syntaxes, some of which I like and some of which I dislike, but they have never been a blocker. However you look at it syntax is just a RTFM and get over it.

Semantics that’s where the real difficulties lie. And how you use the semantics in a good way.

6 Likes

Do you write it like that intentionally or it happens by accident and then annoys you when it blows up?

I personally don’t mind newline dependence as it’s something I would probably be doing anyway as it makes code look cleaner and more readable.

So for example in JS you might have the following code:

var greeting = "Hello world";
if (greeting) {
  console.log(greeting);
}

You are using newlines anyway so the extra ;s just feel unnecessary to me. In Ruby the equivalent might be:

greeting = "Hello world"
if greeting
  puts greeting
end

You can use semi-colons instead if you want them on the same line though:

greeting = "Hello world"; if greeting;  puts greeting; end;

Although you rarely see that, most would probably just do the following if it’s a single check:

greeting = "Hello world"
puts greeting if greeting

I would actually prefer Elixir’s def to be more like it is in Ruby (so without the do on the end). Tho I don’t mind the do if there are technical reasons why omitting it wasn’t a feasible choice.

This is actually a really good question! And “RTFM and get over it” is a good point :rofl:

While I can’t give you a conclusive answer as to why it matters, I think it is fair to say it does (to some) because people often chose one language over another in no small part due to syntax.

I can give you some ideas on why tho…

Choice

I guess we are lucky that we have lots of languages to choose from. When I first started learning programming Ruby and Python were in my shortlist. They both had similar sized communities, were roughly the same speed (back then) both had excellent web frameworks, and while both had other slight pros and cos there was not much in it at all. I clearly remember why I went with Ruby… yup, you guessed it, syntax (and semantics!) were definitely big factors. Community was another (the Ruby community are famous for being super-welcoming).

I wonder if when you started out the choices were much more limited and you just ‘got on with it’ and a side effect of that is you became accustomed to various types of syntaxes and therefore somewhat immune to choice being a factor.

Actually one of the questions I wanted to ask you when we were going to do our Spotlights on EF is, if you were creating a new language today what would it look like? :upside_down_face:

Many users of these languages do not have a CS background

I think it’s possible this may play a part, and why people get frustrated when languages aren’t intuitive and work as ‘they’ expect them to. Again I think this has been a positive for languages like Ruby because they were designed to ‘feel natural’ if you expect something to work it should, eg. you can immediately deduce that you’re asking whether something is large from this code: something.large?

I think there’s a certain beauty to this.

Beauty

Speaking of beauty, I think how something looks on a page matters too. When I look at Ruby code it looks nice. Everything seems nicely balanced. It’s difficult to pin point but I definitely feel Ruby code looks beautiful and I guess is a big reason why I like Elixir too.

Simplicity

This is probably more about semantics and an extension of how natural feeling a language is, but how a languages works matters, and syntax is the bridge:

dogs.each do |dog|
  dog.best_friends_name = "Scooby Doo!"
  dog.score = 100
end

This definitely matters (although I think they are usually fairly closely linked as syntax is the gateway).

This is really good advice!! :rofl: :rofl: :rofl:

Searching for perfection in a language is futile because everyone’s different and so unless you create the language yourself none of them are going to do everything as you want them to - the best thing you can do is just find a language that you are happy with and like you said, just get on with it! :robot:

I also think that over time, the more languages you are experienced with the less syntax matters - at least that’s the impression I get reading threads about syntax over the years :man_shrugging: I think I’m beginning to fall in that camp too. Only just beginning to tho! :joy:

4 Likes

I saw this page at elixir-lang[dot]org for the first time, and it’s nice one. Thank you!

3 Likes

@rvirding is right. I don’t choose languages for their syntax. There are many more things you consider about a language. I chose PHP for WordPress (and later used CodeIgniter too), Ruby for Rails, JavaScript for being the only option in the browser.

I chose Go for its performance, compilation to a single binary, goroutines and channels, and later I discovered that it’s syntax which I initially considered more verbose than Ruby’s, was actually simpler and the gofmt made everybody’s code identical, so reading other people’s code was easier.

The only language I chose for its syntax was Elixir, but again, if it didn’t have BEAM and all of goodies BEAM offers, I might not have learnt it. I needed a language great for real-time applications and I had three options, one imperative, Golang, and two functional, Clojure and Elixir. As I already knew Ruby, so I thought I will learn Elixir quicker than Clojure.

I only heard from others that Erlang’s syntax was alien. When I started to learn it, I liked its syntax.

4 Likes

Although I have used PHP I wouldn’t say I chose it, because I didn’t really have a choice - it was the language that software I was using was built-in so had to use it.

I did choose Ruby and Elixir tho :smiley:

However, I think nowadays the liberty to choose is dwindling. Back then many of us were making web apps and you could use lots of different languages to get the job done. Ruby, Python, PHP, Java, etc it didn’t really matter for the most part.

Things are different now because even some of the more specialised areas are actually now quite mainstream - maybe even as much as building web apps was back then because the internet has continued to explode. If you want to realistically do ML, your options are limited. If you want to do mobile apps, your options are limited. If you want to create SPAs, your options are limited. If you want to build massively scalable fault tolerant systems, you options are even smaller still :wink: haha!

Using the right tool for the job, in the sense that your options are more limited, is more prevalent now in mainstream than it was 5 10 years ago. Hence I’ve resided to the fact that I need to stop being picky and in Robert’s words “RTFM and get over it” :rofl: (however I will say that the moment realistic choice becomes an option again, syntax will almost certainly play a role - we are just human after all, and we all have preferences on things like this).

3 Likes

Hah, I ran into the same issues with the syntax, which really sucks because that syntax used to work but was broken back in 1.4 or 1.5 or so, which was very bugging for one of my libraries… >.>


Overall though I still prefer erlang’s syntax to this day, I would just sorely miss its macro system. lfe should become more popular. ^.^

3 Likes

Our LFE portal is up now so maybe you or Robert could post some threads about it :nerd_face:

3 Likes

:cry:!
I’m revisiting Erlang and loving its syntax, and preparing contents for a course on Git, a tool which is widely used yet misunderstood, and meanwhile you people reminded me of LFE. Now a part of me wants to visit lfe.io and the sane part of my brain tries to stop it, sensing procrastination.

2 Likes

I’m not sure why but I always thought LFE was a hobby project for Robert (I mean he already created Erlang!) but after revisiting the site after its redesign it seems people are using it in production:

LFE boasts seamless interoperability with Erlang and the BEAM ecosystem of libraries. It not only has been used in stable production applications since 2015, it has also been employed by start-ups as their differentiating tech. LFE is flexible enough to be everything from your go-to scripting solution to your preferred syntax for massively scalable, soft-real time services.

I’d like to see more threads about LFE :smiley:

2 Likes

I think erlang2 was his hobby project, lol. LFE is fully fledged though. :slight_smile:
I think erlang2 was his, maybe one of the others, it had some aspects of elixir like multiple modules in a file and all, but was definitely a little hobby thing that wasn’t finished.

4 Likes

Reminds me of a presentation I did 10 (what, 10!!) years ago now. Erlang for Ruby developers.

Blog post:

Link directly to the presentation:
https://beg-erlang-for-ruby-devs.herokuapp.com

3 Likes

Nice one Karmen! I enjoyed going through that! And wow - TEN YEARS!!! Think I was only just getting into programming them :rofl:

What are the most used Erlang frameworks now btw? I need to add portals for them :nerd_face:

3 Likes

Thanks!

Other than the ones I mentioned: Chicago Boss and Nitrogen, I see there are others like Zotonic and Nova. I haven’t personally used them. YMMV.

3 Likes

I loved these slides. Thanks for sharing!

2 Likes

You’re welcome. Thanks!

3 Likes