Elixir Blog Posts

blog-posts
wiki
stickies
Tags: #<Tag:0x00007fbcab76c270> #<Tag:0x00007fbcab76c130> #<Tag:0x00007fbcab76bdc0>

#347

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.


#348

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:


#349

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. ^.^;


#350

PHP

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');

Ruby

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

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

:heart:


Can even be written like this:

class Ball
  def initialize(colour); @colour = colour; end
  def is_red?; @colour == "red"; end
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
end

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

:003:


#351

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++.


#352

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.


#353

(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?


#354

Unfortunately i think that not too often :confused:


#355

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


#356

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.


#357

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.


#358

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


#359

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


#360

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