Elixir Blog Posts

Tags: #<Tag:0x00007fcf97d8bcd8> #<Tag:0x00007fcf97d8b9e0> #<Tag:0x00007fcf97d8b878>


Please give it a try. If anything is not working or is confusing, please open issues on https://github.com/cogini/elixir-deploy-template or ask questions. I am reachfh on the Freenode group and jakemorrison on discord (in UTC+8 time zone).

Deployment is never going to be a one-size-fits-all solution, but I want it to be as easy as possible.


Great article about pros and cons of Elixir, in comparison to Ruby. https://www.netguru.co/blog/elixir-vs-ruby-which-one-is-the-language-for-your-next-project and how to choose the right one depends on your next project. :slight_smile:


Reading well-written Ruby code is also a pleasure.

Isn’t this the case for about any language? A good question is how often does the ‘well-written’ code pop up? :wink:

Ruby on Rails, created back in 2005, was a really disruptive piece of technology. It changed how we write web applications - it was just mind blowing how much you could achieve by writing so little code. It also made prototyping applications faster.

I’m guessing they weren’t Perl users. ^.^

Ruby is a really expressive language. A couple of lines in Ruby can do the same job as whole chunks of code in other languages.

I’ve… not actually seen this yet for Ruby. I keep hearing that such-n-such languages do this, but it is surprising how often they some how end up more verbose than ‘big-fast’ languages such as C++ or OCaml… Anyone have some code that examples this that also fulfills the well-written part (please no perl-golfing horrors)?

Also, if they are really going to say FP is a Con for Elixir, then they really badly need to say that OOP is a Con for Ruby. ^.^;



class Ball
    private $_colour;
    public function __construct($colour)
        $this->_colour = $colour;
    public function is_red()
        return ($this->_colour == 'red' ? true : false);        

$the_ball = new Ball('green');
echo ($the_ball->is_red() ? '' : 'The ball is not red');


class Ball
  def initialize(colour)
    @colour = colour    
  def is_red?
    @colour == "red"

the_ball = Ball.new("green")
puts "The ball is not red" unless the_ball.is_red?


Can even be written like this:

class Ball
  def initialize(colour); @colour = colour; end
  def is_red?; @colour == "red"; end

the_ball = Ball.new("green")
puts "The ball is not red" unless the_ball.is_red?

Or this:

class Ball
  def initialize colour; @colour = colour; end
  def is_red?; @colour == "red"; end

the_ball = Ball.new "green"
puts "The ball is not red" unless the_ball.is_red?



I don’t think your example shows that ruby gains a lot compared to php. The php and ruby are almost exactly the same when written in the full format. Only small syntactic differences. And for your shorter version, they can be written shorter in php as well.

This link has a research paper comparing erlang and C++ (https://www.researchgate.net/publication/221211369_Comparing_C_and_ERLANG_for_motorola_telecoms_software)

The C++ code us 7.8 times larger for one of the components and 3 times larger for another component. An interesting quote from the paper (which I think is a summary of Ericssons report regarding the AXD301 ATM switch (which is based on 1M SLOC))

Moreover, the systems developed in Erlang and in conventional languages exhibit similar error rates per unit SLOC, and similar SLOC per unit time programmer productivity. Hence, the Erlang system shows at least a fourfold gain in productivity and reduction in errors

Perhaps modern C++/java are not as verbose as they once were and the gain is no longer as big but many years ago a ruby/python/perl project would see similar gains in reduction in SLOC compared to C++.


That’s fine :slight_smile: different strokes for different folks.

Languages like PHP always made me want to scream, yet, I know many people who love it. That’s totally cool - the world would be a boring place if we all thought the same.


(Initially, PHP I find abhorrant after near a decade working with it a decade ago, so not a great comparison language ^.^; )

I’d find it far more succinct and safe both to do it in OCaml but I think Ruby is older than OCaml (mid 1990’s or something?), so bad example, but in perl that would be like:

package Ball;
sub new {bless({colour => $_[1]}, $_[0])};
sub is_red {shift->colour == "red"}

Used like:

my $ball = new Ball("green");
print("The ball is not red") if(!$ball->is_red());

If I remember right (been years… >.>)

Or C++:

struct Ball {
  string colour;
  Ball(string colour_) : colour(colour_) {}
  bool is_red() { return colour == "red"; }

Etc… etc…

A class example is a pretty bad example overall. I’m guessing from the ‘can express more in less code’ that usually means algorithms, not syntax, hence why a class example was a poor example?

Yeah they really can…

Modern ‘styles’ are significantly shorter yes, but even ‘back in the day’ they could have been shorter as well, just most people had longer ideas in mind because fortran and so forth. I’d argue that even ‘back then’ C++ could still be about as succinct as Python in any non-trivial code, while still being substantially safer than the 3 listed languages as well.

PHP is a mishmash of decisions, it’s very Perl’ish in many ways, but probably better, except it’s ecosystem, which is worse. ^.^;

I may hate on PHP but it’s not because of the language itself, which actually has some really cool design decisions, but mostly in that the naming conventions are inconsistent, the ecosystem knows no concept of security (though it seems Ruby is similar on that as well from what I’ve read), etc… etc… PHP7+ is actually rather blazing fast as well and on benchmarks I’ve seen it absolutely blowing Ruby away in speed, and it easily can be more succinct than ruby (you can do some rather impressive perl-style-golfing in PHP).

Even then, I’m unsure why Ruby would have been picked over, say, Python, and I’ve not seen anything that says that it would have if Rails was not built on it. I’m unsure what it has over Python as of yet, especially as it’s slower and has a slightly worse and more verbose syntax…

/me thinks this may should go in another thread…

But still, I’m curious how does Ruby do more in given lines of code than, say, C++? Sure I know C++ has #include's and other such noise, but they are collapsed by any decent IDE, and even then Ruby was not competing with C++, it was competing with the likes of Perl, which yes Perl’s syntax is a bit of a horror aberration but it still seems far more ‘expressive’ than Ruby? And I’m still curious what Ruby gains over Python as well?


Unfortunately i think that not too often :confused:


PSA: Be careful using Elixir’s “with” special form in tests.


Check out how I used Wireshark to help reduce the tedium of testing my Elixir-based serializers and parses for Bitcoin’s binary peer-to-peer protocol:

Generating Test Fixtures with Wireshark

FWIW, the tests resulted in an almost immediate positive return on investment. I immediately noticed an issue with one of my serializers that was causing all kinds of mysterious behavior within my node.


Bring your variables back from the dead! https://engineering.tripping.com/bring-your-variables-back-from-the-dead-ea250cf58ba4

Resurrect your variables after you restart an iex session.


I have recently published a short blog post about supervision strategies and DynamicSupervisor.


I just published a short blog post about me customizing the parameters of my contoller actions in phoenix:


4 posts were merged into an existing topic: Blog Posts: Evangelising Elixir


Composing Elixir Plugs in a Phoenix application
23 Mar 18

Elixir is a functional language, so it’s no surprise that one of the main building blocks of the request-response cycle is the humble Plug. A Plug will take connection struct (see Plug.Conn) and return a new struct of the same type. It is this concept that allows you to join multiple plugs together, each with their own transformation on a Conn struct. A plug can be either a function or a module that implements the Plug behaviour.



7 ways of doing Fizz Buzz in Elixir and other clickbaity stuff https://minhajuddin.com/2018/07/06/7-ways-of-doing-fizz-buzz-in-elixir-and-other-clickbaity-stuff/


Composing Ecto queries



Hi folks!

I just published a new blog post: A dive into database multi-tenancy in Elixir with Ecto, and I wanted to share with you all. It’s a blog post with some tips and experiences about the migration of an application with a regular database to a multi-tenancy one in Elixir with Ecto.


https://embedded-elixir.com/ Embedded Elixir has lots of Nerves related posts


How to use private hex dependencies in your docker images while building your releases https://engineering.tripping.com/how-to-use-private-hex-dependencies-in-your-docker-images-42b2d01d8d70