This is PerlMonks "Mobile"

Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  


in reply to Curious about Perl's strengths in 2018

Programming languages can be compared in many different ways, of course. But there is a metric which is the most important. Economy: capturing, harnessing and training programmers (much like mustangs) or just mass-producing them at university breeding stables (much like work-horses). Then it is the ease of breaking down programming tasks and their distribution to teams all over the world (in order to exploit local wage differences etc.). Also, risk of bugs, cost of maintenance and refactoring. In this metric Perl is somehow inferior to others. But strictly-typed, OOP languages will always win here anyway.

The second most important metric, again based in my very limited experience and less on knowledge, is how much it allows you to build on the work of others: 3rd party libraries. CPAN is full of high quality modules in standard more or less format (wrt doc/test/install). Last night I needed a tree implementation. LOTS of trees in CPAN! Add to this excellent package managers, for example cpanm, and excellent multi-environment managers like Perlbrew. And excellent forums like PerlMonks. In this metric Perl is in par with every other contestant if not winning single-handedly.

Third metric, built-in data structures. The Hashtable was first given to the masses via Perl (ok, awk has it much earlier but we are not talking about masses exactly here).

And the masses loved it and swear by it ever since. What an impact by Perl! But who remembers it and who cares?

Python picked it up too but later (correct me if wrong). Then Java (and JS/ES). But C++ never dared to do that then, when it did matter. Today they introduce any nilly-willy idea they read in Cosmopolitan every couple of weeks to the point of ridiculousness (and the breaking of my systems). Who needs knee-jerk reactions?

So, in this metric Perl won but victory has no meaning. Now all contestants offer this and some of them overdo it (e.g. Java). So all equal here I believe.

Lastly, there is the question of Optimisation of practices, resource allocation, distribution galaxy-wise if possible. Bear with me for a moment...

There is a top-down approach to it where a path is followed to optimality, much like climbing a mountain. And there is an "anarchic" way: unleash a billion ants to climb to the honey at the top each following a random path. Very useful when we are not sure where the highest peak is. And have lots of ants. Darwin expressed the idea of the survival of the fittest. Something that is often ovderlooked is that it requires a massive population breeding and eating each other.

Genetic Algorithms, as in AI, model exactly that but in Computer Systems. And Genetic Programming takes it even further to creating optimal (computer) programs as a result of breeding and eating each other along with random mutations here and there. (Do not hurry to say that GP did not fly. Neural Networks died and resurrected many a times, each time stronger.)

It is my opinion that Optimisation should be the first concern in the mind of any person who is a "scholar" in the sense that he/she cares to see a bit further than how the daily bread is brought to the family table. To any manager and "chief executive" (gosh!), to any government official (gosh!) should be the first in their mind. Alas it is not. Because the (prevalent) economic system dictates that it is short-term profit maximisation which matters. De facto: Bonuses are distributed every year, CEOs and politicians are elected every five (~~). What incenctive do they have to think long-term? Like 30 years from now? 50 years ago the "short-term" was 30 years, today is maybe 18 months. (Interesting side-note: the taking of GKN which is a supplier for Airbus Airbus warns over Melrose's £8bn GKN takeover : Airbus, said the industry was not suited to "short-term financial investment")

I digress. Anyway, Optimisation should be first in our mind when we judge anything that has to do with our future. And because nobody is sure about which path to take to the highest peak (which we can not see anyway) I favour the second model, the "anarchic" bottom-up massive unleash of tha ants. Maybe with educated top-down guesses and heuristics and of course with a set of rules which are HUMANE. No need for the deadly competition of today, neither the marginalisation of people and ideas.

And here is where the Programming Languages come in: what is their role in this Optimisation? Now this is a Metric!

This is a Digital era and there is no going back (unfortunately i say). The spade and the steam-engine of our times is Computer Systems and Computer Programs are what move them. And so Programming Languages are important part of Optimisation. But we need to ensure that the competition of ideas and toolsets is as wide as possible in order to have better chance to arrive to good solutions - to evenly visit the landscape so-to-speak.

One of Perl's underlying (and I guess uncompromising) principle is There's more than one way to do it (edit: a point many fellow Monks mentioned already here and also I mentioned it in another comment which is cited here). It fits exactly in the model of Optimisation I have just described. It is very important. And in my opinion it is Perl's most important strength for 2018 until 2058 and 2258. Please note: underlying principle and not just a random side effect. You are what you program with. Maybe Perl will die out one day but the spirit survives and also within the walls of this Monastery.

Onwards Brothers and Sisters! The spirit of Optimisation is the spirit of Perl.

Contrast and compare that to others notably Java, C++ and Python. Btw the latter I distaste so much - both language, creators and users - I thought it unfair to make any further comment about it.

bliako

Replies are listed 'Best First'.
Re^2: Curious about Perl's strengths in 2018
by bliako (Monsignor) on Apr 14, 2018 at 18:05 UTC

    "In contrast [to Tim Toady] part of the Zen of Python is, "There should be one — and preferably only one — obvious way to do it." (from the article on "There's more than one way to do it", link above).

    Worlds colliding...

    bliako
Re^2: Curious about Perl's strengths in 2018
by Crosis (Beadle) on Apr 15, 2018 at 09:16 UTC
    Contrast and compare that to others notably Java, C++ and Python. Btw the latter I distaste so much - both language, creators and users - I thought it unfair to make any further comment about it.

    That may be the case but as far as the evolutionary computing you talked about is concerned, unfortunately there doesn't appear to be anything in CPAN comparable to DEAP.

    (Side note: evolutionary computing cannot generally be considered to be an optimizing approach, despite contrary language (including something I'm about to mention) and there is at least one approach in the field where the evolution is in memes rather than genes and so where no one breeds and no one dies, namely particle swarm optimization.)

      At the end all these languages are Turing complete and will eventually arrive at the same tape square. What interests me is the spirit and the inspiration. Pretty metaphysical I agree... A comment to your side-note: I am not sure what is more "scary": genes dying out or ideas? Ideas I should think.

      I have whipped up some code to get me started with Perl's evolutionary computing toolkit.

      #!/usr/bin/env perl # Brief and dirty attempt to solve a system of simultaneous equations +(2) # using Genetic Algorithms in particular CPAN module # Algorithm::Evolutionary # Perl module for performing paradigm-free evolutionary algorithms # by J. J. Merelo, jmerelo (at) geneura.ugr.es # (parts of my program were copied from manpage) # # The toy problem here is to find INTEGER solutions to the system of e +quations y-x=2 and y-2x=11 # wrt x and y. # Our 2 genes are 'x' and 'y'. We encode these as 8-bit integers # 7+1sign bit. The algorithm will mutate/crossover etc the bit string +of each member of # the population. Then it will evaluate how well the genes of each mem +ber of the population # solve the problem at hand. This is called the fitness. The fittest g +enes survive and the # rest are discarded, with some probability. # Author: bliako # Date: 16/04/2018 use strict; use warnings; use Algorithm::Evolutionary::Experiment; use Algorithm::Evolutionary::Op::Easy; use Algorithm::Evolutionary::Op::Bitflip; use Algorithm::Evolutionary::Op::Crossover; my $num_genes = 2; my $fitness = sub { my $individual = shift; my $genes = chromosome2genes($individual->Chrom()); return calculate_discrepancy($genes); }; my $m = Algorithm::Evolutionary::Op::Bitflip->new(2); # flip this numb +er of bits randomly my $c = Algorithm::Evolutionary::Op::Crossover->new(2); # crossover wi +th 2 points # every iteration applies the above operations to the population along + with a fitness function # and selection rate (prob of good genes to survive, lower means more +"bad" genes enter the next generation) my $ez = new Algorithm::Evolutionary::Op::Easy $fitness, 0.4, [$m,$c]; my $popSize = 500; # population size, each individual in this pop has +a chromosome which consists of 2 genes my $indiType = 'BitString'; # the chromosome is a sequence of bits as +a string my $indiSize = 8*$num_genes; # 8 bits per gene my $e = new Algorithm::Evolutionary::Experiment $popSize, $indiType, $ +indiSize, $ez; my $populationRef; my $previous_fitness = 0; my ($current_fitness, $best); while(1){ $populationRef = $e->go(); $best = $populationRef->[0]; print "Best so far: ", $best->asString(), " (", individual2string( +$best),")\n"; $current_fitness = $best->Fitness(); if( $current_fitness == 0 ){ print "bingo!\n"; last } #if( ($previous_fitness - $current_fitness) == 0 ){ last } $previous_fitness = $current_fitness; } print "\nI tried to solve the system of equations: y-x=2 and y-2x=11. +The solution should be x=3, y=5\n"; print "Final solution found: ".individual2string($best)."\n"; exit(0); sub individual2string { my $individual = $_[0]; my $genes = chromosome2genes($individual->Chrom()); my $fit = calculate_discrepancy($genes); return genes2string($genes) . " -> discrepancy=" . $fit } # interpret an array of genes wrt our problem, i.e. an x and a y sub genes2string { my $genes = $_[0]; return "x=".$genes->[0].", y=".$genes->[1]; } # convert a huge bit string into an array of genes # the array to place the genes in is given sub chromosome2genes { my $achromosome = $_[0]; # chromosome bit string containing all ge +nes as 10101 my @retgenes = (0)x$num_genes; # convert a chromosome which consists of genes which consist of bi +ts(alleles) # into a set of numbers to be applied to our problem. # each chromosome below consists of 2 genes which consist of 8 bit +s (1sign+7) # these 8bits are interpreted as integers in +-127 range (which is + enough for our problem # however if solution involved bigger numbers we need to increase +range/bits) my $i=0; while( $achromosome =~ /([01])([01]{7})/g ){ my $sig = $1 eq '1' ? -1 : 1; my $g2 = $2; # Here is how a sequence of 8bits is converted to integers. 1s +t bit is sign. # I am sure there is a better way using pack. my $g = 0; my $j = 1; map { $g += $_*$j; $j*=2; } split(//, $g2); $g *= $sig; $retgenes[$i++] = $g; #print "$g2->num=$g\n"; } return \@retgenes } sub calculate_discrepancy { my $genes = $_[0]; # Our problem is to solve the simultaneous equation: y-x=2 and y-2 +x=11 # where genes[0] -> y, genes[1]->x my $e1 = $genes->[0] - $genes->[1] - 2; my $e2 = $genes->[0] + 2*$genes->[1] - 11; # we calculate discrepancy but we need to return fitness: return -($e1*$e1 + $e2*$e2); }

        Nice example code!

A reply falls below the community's threshold of quality. You may see it by logging in.