Clone Wars

Apologies to those that have OO steeped in their blood. I am a wary traveller in OO space,  maybe I am an technician, not an architect at heart. So for me, no sweeping frameworks unless and until they are needed. And, frankly, one can go a long way on procedural code with subroutines to gather repetitive code sequences.

(And don’t get me started on functional programming…)

Some time ago, I was tasked to write a LIMS in old perl. Physical ‘aliquots’ with injections of various liquids would be combined and recombined by bio-machines. This led to a dawning realization that these aliquot objects could be modelled in an object style with parent / child relationships. After a few weeks, I proudly delivered my lowly attempt at ‘Mu’ for this (and only this) problem. Kudos to the P6 team – after a couple of weeks in here, it’s just sensational the level of OO power that the real Mu delivers:

Screenshot 2017-09-20 19.32.21

Now, hard at work, on the perl6 version of Physics::Unit, I am wondering how to put the OO theory into productive practice. One of my aims was to find a medium sized (not core tools) problem that (i) I know something about and (ii) would be a good-sized problem to wrangle.

So I am enjoying the chance to design some classes and some interfaces that will make this all hang together. But – as an explorer, it has become clear that I only have three options. The problem runs like this:

  • There is a parent Measure class that contains the methods for any real-world measurement handling dimension, units, value and errors.
  • Then there are child classes for my Distance $d = ’42 m’, my Time $t = 3 s’, etc.
  • First level, I have an operation like … my $r = ’23 ft’ + $d;

Initially I had some success with object types ::T – but these only let you read the type and  duplicate if needed for a new left hand side container. Then I tried the built in (shallow) clone method. But…

  • What about the operation … my $s = $d / $t?
  • How do I create a new Speed object programatically?

Ultimately, thanks to rosettacode.org, I worked out that $x.perl.EVAL with some ~~ s/// substitions on the way would do the trick!

Phew. Please comment below if you have a better way to share – or would like to point out the risks of this technique…

Advertisements

perl6 Atomic Fission

I have been listening to the reaction on the web to the incorporation of an emoji as a unicode symbol in perl6 rakudo. Here’s a flavour…

(https://p6weekly.wordpress.com/2017/08/21/2017-34-going-atomic/ )

The rationale for the use of unicode symbols is as follows:

  • These represent operations that are rare
  • They relate to a specific domain (in this case, concurrency)
  • Programmers can always fall back on the ASCII version (e.g. atomic-inc )

BTW- ASCII versions are known as Texas versions since they are always bigger

Certainly this has caused some consternation – ranging from how can I type ⚛️ on my keyboard (hit CTRL-CMD-SPACE if you are on macOS ) to this will never be accepted for the coding standards of my company.

On reflection, while it is understandable that programmers have a well established comfort zone of ASCII text and using English for keywords, I think that perl6 is leading the way on an irresistible path. Of the 6.5bn people on the planet, only a small fraction prefer to work in English – or even in Latin alphabets. Now, the pioneering work to embed unicode in a programming language will open the doors to all kinds of invention. What about:

  • A slang (i.e. a perl6 sublanguage) for the French, Germans or Japanese programmer
  • Ability to parse all unicode alphabets – so linguists can digitize,  analyze and compose writing from all parts of the globe, even dead scripts like Egyptian
  • Or, back to the point, opening a new world of symbol space to side step the crammed ASCII non alphanumeric characters that confines our programming

And this, in combination with perl6 Grammars, opens some interesting conceptual doors.

~p6steve

perl6 Module How To

Some investigation has discovered great resources on how to write and then list a perl6 module….

Physics::Unit in perl6

First and foremost, homage to the original authors of Physics::Unit and related perl5 CPAN modules. I would be honoured to hear from you and to collaborate in any way.

What’s the big picture? TOP down, I have in mind:

  • exploring the expressive and modelling potential of Grammars, Unicode, types and junctions for real people (well thinking high school level Physics teachers and students here)
  • providing a set of tools to help embed real Physics (and Maths) concepts into programmatic form with nouns (variables) and verbs (functions)
  • imagine a toolbox that can interpret and implement (e.g.) Mechanics laws of motion, formulae and expressions
  • such a thing would need a Grammar that can parse things like F=dp/dt (such as written in Latex or Unicode)
  • there are probably vector (and matrix) representations of things such as velocity
  • visual output of some form would be nice (plot this thing)

So, that said, given my poor state of knowledge of most of these things, my thinking is to start build BOTTOM up and see the shape of things that emerges, while learning some perl6 on the way.

So, first I am going to need some MEASUREMENTS which are VALUES expressed in UNITS with associated ERROR.

I took a gander at this CPAN module Physics::Udunits2 which is a perl5 interface to udunits2 and felt that the richness of it’s units and adherence to NIST guidelines were not of sufficient benefit to overcome my sense of incoherence.

So, to cut a long story short, decided to take inspiration from Physics::Unit .

Next, I needed some guidance on How to Build a perl6 module…

perl6, really?

I have been waiting for perl6 for over 15 years since it was first conceived. Recently, I have had an urge to get back to hands’ on coding and, having seen the latest Rakudo* release of perl6 felt that it is now sufficiently mature for my nefarious purposes.

No doubt I am not the only person to have been frustrated by the slow progress of perl6, and certainly many have dropped by the wayside. Perhaps going to the siren call of Python(2 or 3), Ruby, Swift or Go. And now it is finally here, the community is obviously worried that no one will adopt the fruits of their work.

Here ‘zoffix’ makes a desperate plea to change the name from ‘perl6’ to ‘rakudo’ to reboot the brand…. https://www.reddit.com/r/perl6/comments/6lstq3/the_hot_new_language_named_rakudo/

My rebuttal to this concept is reproduced here.

I’m a slow thinking guy who has had two careers:- perl5 dev and marketing manager. I have been wrestling with Zoffix’ proposed change and it is certainly a well construed argument made with feeling. Here’s my line:

  • NO_ONE cares about the community
  • WHAT_THEY_NEED is UniCode & Rats
  • WHAT_THEY_LIKE is poetry (not golfing, but an expressive professional medium not desecrated by ‘public void’ line noise)
  • WHAT_THEY_KNOW is CPAN, DWIM and REGEX (the easy is easy and the hard is possible)
  • WHAT_THEY_WANT is Grammar, Functional, OO, Declarative, Concurrency, Dynamic Type … oh and Procedural done v clean
  • WHAT_THEY_HAVE is Ruby, Python, C#, Go, Perl5, ECMAScript, Java — demand for p6 is pent up.

So, I detect some natural frustration within and without the community. Keep the faith. We have a new audience, they value truth and beauty, and a story of battling the odds. They need this TECHNOLOGY. It is [perl6 | rakudo] – who cares. It may have to start in academia, it may have to start in the p5 stalwarts. It will ignite. Finish the journey. Do not deny your heritage.

So, yes, I think that perl6 is awesome (whatever it’s called). And I believe that it will be an interesting personal journey to come to grips with the ultimate programming power tool and to deliver something interesting on the way. As a user and sometime low level contributor perhaps.

~p6steve