Lunatics, Perl, and Java

So I don't forget this - my expanded version of something our Larry Wall once said:

"Looking at Perl code, it is easy to tell whether you are looking at the ravings of a lunatic. With Java, you can be several weeks into the project before you realize that you are dealing with the demented discourse of someone who should be trusted with nothing sharper than a spoon."

Strings in YAML - To Quote or not to Quote

+++ This article has been refurbished and moved to +++

www.yaml.info/learn/quote.html

(June 2020)


Old version:

This article covers scalar styles in YAML 1.1 and 1.2. It mostly works the same in both versions.

YAML is a data serialization language, and one design goal was that it's human friendly. It should be easy to read and edit, even if that makes parsing it harder.

Let's look at strings, specifically.

If you look at JSON, you have only one style to encode strings, and that's the double quoted style which doesn't allow literal linebreaks.

YAML files are used for many different purposes, and there are many types of strings, especially multiline strings. For each use case, you can choose the type of quoting (or no quoting) that makes the string readable and easy to edit.

This gives you lots of freedom, but you also have to learn using it to avoid mistakes.

Fix Moose Case

Its another case day here in the Moose-Pen

Yesterday I left off with this result

Expected--> SELECT CASE WHEN Price < ? THEN ? WHEN Price >= ? AND Price <= ? THEN ? WHEN Price > ? AND Price <= ? THEN ? ELSE ? END AS price_group FROM Products

Generated-> SELECT CASE WHEN Price < ? THEN ? WHEN Price >= ?andPrice <= ? THEN ? WHEN Price > ?andPrice <= ? THEN ? ELSE ? END price_group FROM Products
In the above I see at least fourt problems;
  1. No space between my 'AND' conditionals
  2. The conditional is in lower case it should be coming into the DAD in upper case and
  3. There is no 'AS' between the 'END' and the 'Alias' 'price_group'
The first one should be no problem as this little patch fixes that

Guiding Fate

Fate

Somebody once said, that the power of a programming language is not what it lets you do, but what it lets you do easily. Might be Larry himself who said it, not sure, but I heard it at the London Perl Workshop. I started learning Perl from an old second hand book I found in a charity shop a few years ago. I can't say I am any good at it. While previously I could find lots of resources available, these are increasingly harder to find, more outdated, and less able to address modern use cases. Some folk even suggest it is terminal decline. It would be a pity. It is a powerful language, and using it for me has given me a daily discovery for some feature that I didn't know, and exposed me to a large number of clever folk who can bring a different angle to a problem you have struggling with. To my mind it reflects the versatility of a language that has more than one way to to anything.

Using Docker to Check for Prerequisites

While updating Set::Jaccard::SimilarityCoefficient to v1.6.1, I realized that I should install it on a clean, clean system so I find all missing prerequisites (not just the ones I already knew about). So where do I get a clean, clean system? Aha - a minimal Docker container (like the plain-vanilla Ubuntu 16.04 LTS) would be just the ticket as I am using an Ubuntu 16.04 LTS laptop. As an example, here are the steps I ran through:

  • Run: "sudo docker run -v /home/mark/src/perllib/Set-Jaccard-SimilarityCoefficient/Set-Jaccard-SimilarityCoefficient-1.6.0:/Set-Jaccard-SimilarityCoefficient-1.6.0 -it ubuntu".

  • Because this is a plain-vanilla Ubuntu, I need to install some development tools (including missing pieces of Perl) by running: "apt-get update; apt-get install gcc make perl-modules-5.22". Followed by: "cpan -i App::cpanminus"

(If anyone points out in the comments how I could use the direct "curl" install for "cpanm" rather than using "cpan", I will update these directions.)

Perl 6: On Specs, Versioning, Changes, and... Breakage

Read this article on Rakudo.Party

Recently, I came across a somewhat-frantic comment on StackOverflow that describes a 2017.01 change to the type of return value of .sort:

"you just can't be sure what ~~ returns" Ouch. […] .list the result of a sort is presumably an appropriate work around. But, still, ouch. I don't know of a blog post or whatever that explains how P6 approaches changes to the language; and to roast; and to Rakudo. Perhaps someone will write one that also explains how this aspect of 2017.01 was conceived, considered and applied; what was right about the change; what was wrong; etc.

Today, I decided to answer that call to write a blog post and reply to all of the questions posed in the comment, as well as explain how it's possible that such an "ouch" change made it in.

On Versioning

Send in New Dist::Zilla!!

In the Dist-Pen today I am looking at another plugin to help with my many versioning woes.

In my last post I had a look at a Dist::Zilla plugin that helped me out with versioning my distributions. Today I am going to see if there is a plugin that will help me out with my Module versions as well. So a quick look about and I see we have a few options so I will start with the most likely candidate 'Dist::Zilla::Plugin::PkgVersion'

Like all the Dist::Zilla plugins I have used so for this one is quite simple; Just add

[PkgVersion]
in my '.ini' Now there are a number of attributes I can play with but before I do that lets see what I have I my Database::Accessor classes;

Perl 5 Porters Mailing List Summary: February 12th-18th

Hey everyone,

Following is the p5p (Perl 5 Porters) mailing list summary for the past week.

Enjoy!

Set::Jaccard::SimilarityCoefficient v1.6.1 Released

Somehow I missed most of the prerequisites for Set::Jaccard::SimilarityCoefficient, so I have released a version v1.6.1 that:

  • Has all of the prerequisites in the Makefile.PL.

  • Uses the new (and internally simpler and more correct) ReadonlyX instead of the retired warhorse Readonly.

  • Has additional Kwalitee tests in t-kwalitee/.* (All Kwalitee tests pass.)

(This passes most of "perlcritic --theme pbp" except for the unknown word in POD and the POD before END checks.)

Enjoy!

Safely load untrusted YAML in Perl

Usually people deal with YAML files from trusted sources. But maybe you want to load input from a Website as YAML. This can lead to problems, and this article will talk about what you can do to make the loading safe.

The problems I'll talk about are loading objects, cyclic references and general parsing problems.

I will cover YAML.pm, YAML::Tiny, YAML::XS, YAML::Syck and YAML::PP.

Moose Does Case

Finally its Driver::DBI Case day in the Moose-Pen

Has it really been since August 15th that I have been mucking about with Case? I guess after almost two weeks I am glad to finally get into the DBI::Driver part of things. As usual to start (well recap really) lets look at this SQL;

SELECT ProductName,
       CASE WHEN Price < 10 THEN 'under 10$'
            WHEN Price >=10 AND Price <= 30 THEN '10~30'
            WHEN Price >30 and Price <= 100 THEN '30~100'
            ELSE 'Over 100' END AS price_group
  FROM Products
which will translate into this hash ref using my Database::Accessor model language;

Perl Toolchain Summit 2018: Oslo, Norway

Every year we bring together the lead developers of the Perl and CPAN toolchain! This event was previously known as the QA Hackathon, but in 2016 it became the Perl Toolchain Summit (PTS) to more accurately reflect the scope and purpose.

This is an event where pressing issues around Perl’s toolchain, CPAN, testing infrastructure and much more are hacked on, fixed and improved, and where important issues are discussed and decided on. The focus is the continued support and development of the tools used every day by individuals, organisations, and companies that rely on Perl in Production.

Many improvements in the CPAN ecosystem can trace their roots to this event, including Test2 improvements, the “River of CPAN” analogy, numerous MetaCPAN additions, improvements to the Perl Authors Upload Server (PAUSE), policies on how to handle CPAN distribution adoption and takeover, work on the CPAN Testers service, several consensus documents and much, much, much, more!

Lab::Measurement 3.620: More Modern Perl

Lab::Measurement 3.620 was released yesterday.

The most important addition is a new high-level sweep framework written with Moose. Check out the new tutorial Lab::Moose::Sweep::Tutorial!

Comparing with the older Lab::XPRESS framework, the main new feature is support for block data. This is needed when working with instruments like spectrum analyzers or vector network analyzers which return an array of data in each measurement.

Perl in Romania

perl romania.jpg

Perl is a programming language created by Larry Wall in 1987. It gained popularity in the 1990’ and was also referred to as the “duct tape that holds the Internet together”. For esthetic and practical purposes I will be referring to Perl 5 in this article as Perl.

Last December it turned 30, an important milestone for every language, 30 years of Perl, 30 years of people and companies from all over the world using Perl.

And I do mean, all over the world, Perl developers are everywhere, from California to Japan, from the Netherlands to Romania. Actually, the most popular countries are United States, the United Kingdom, Germany, Spain, The Netherlands, Japan. Romania is also on the list, but that’s not the point here, the point is that the Perl bug is in Romania and has been for some time now.

Before diving into the local Perl scene there are a few things that should be pointed out about software development in Romania.

transfagarasan.jpg

Transfagarasan, Romania

IT in Romania


Another Moose Test

Well it why stop a good thing day here in the Moose-Pen

I usually try once a week to do a full regression test on both Database::Accessor and Driver::DBI so I figure I might as well keep that going and have another testing postette again.

Looking at Database::Accessor I see that we had quite a few changes since my last full regression

8 files changed, 579 insertions(+), 158 deletions(-)
but I have been trying to keep up so I am expecting fairly good results. On the first test run I get;

All tests successful.
Files=29, Tests=484, 78 wallclock secs ( 0.22 usr  0.05 sys + 75.39 cusr  1.90 csys = 77.56 CPU)
Result: PASS
so bonus.

Now let's see what sort of sorry shape Deriver::DBI is in.

Videos for London Perl Workshop 2017

The organisers of the London Perl Workshop 2017 are very happy to announce that the videos of the talks are now on YouTube. In the rest of this post we'll give a summary of the videos, with links to each talk.

App-RemoteCommand

Last Friday, kichijojipm was held at Shinjuku, Tokyo, Japan. It is a japanese local Perl Monger group organized by magnoliak. The talks were about not only Perl but also a wide variety of subjects.

I talked about App::RemoteCommand there, which is a simple remote command launcher via SSH, built on top of an excellent module Net::OpenSSH.

Here is the slide. I hope you try it!

Perl 5 Porters Mailing List Summary: February 1st-11th

Hey everyone,

Following is the p5p (Perl 5 Porters) mailing list summary for the past week and a half.

Enjoy!

Not Tomorrow for Moose

No!! Still on a case here in the Moose-Pen.

I just started my first test for '22_fields_extended.t' and then I saw one other little point I forgot to take into account. I should add in some validation for my 'Case' class as it is invalid to have a case that has only one condition.

Therefore this test;

Easily back up your Github repositories and/or issues

It's been in the works at the lower-end of my priority list, but after having a bit of a bug-closing weekend, thought I'd tackle getting out an initial release of Github::Backup.

The cloud is a great thing, until the sun evaporates it one way or another. Github, although fantastically reliable, is prone to issues just like any other site on the Internet. I'd go as far to say that even they could be prone to data loss in very rare circumstances.

This distribution, which provides a command-line binary, allows you to quickly and easily back up your repositories and issues to your local machine. The repositories are cloned so all data is retrieved as-is as legitimate Git repos, and the issues are fetched and stored as JSON data. Useful if there was ever a catastrophic issue at Github, or simply for offline perusal of your information.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.