<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Maddingue</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/maddingue/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/maddingue/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/maddingue//738</id>
    <updated>2012-07-09T00:37:11Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Is PCLI possible?</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/maddingue/2012/07/is-pcli-possible.html" />
    <id>tag:blogs.perl.org,2012:/users/maddingue//738.3505</id>

    <published>2012-07-08T23:13:36Z</published>
    <updated>2012-07-09T00:37:11Z</updated>

    <summary>At the French Perl Workshop (and probably elsewhere before), Matt Trout talked about why and how some ideas could succeed and most other fail. An interesting talk. The last part was a rant against the numerous modules on the CPAN...</summary>
    <author>
        <name>Maddingue</name>
        <uri>https://github.com/maddingue</uri>
    </author>
    
    <category term="psgipcliapimst" label="PSGI PCLI API mst" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/maddingue/">
        <![CDATA[<p>At the <a href="http://journeesperl.fr/fpw2012/">French Perl Workshop</a> (and probably elsewhere before), Matt Trout <a href="http://journeesperl.fr/fpw2012/talk/4154">talked</a> about why and how some ideas could succeed and most other fail. An interesting talk. The last part was a rant against the numerous modules on the CPAN to parse command-line options. His proposal was to do the same thing to command-line programs (CLI) than PSGI did to web applications: formulate a generic specification, that developers can use to build applications and not depend on a specific implementation.</p>

<p>A very interesting idea. We were a few (<a href="https://metacpan.org/author/BOOK">BooK</a>, <a href="https://github.com/cmaussan">cmaussan</a>, <a href="https://github.com/ngrunwald">niels</a> and myself) to begin thinking about what this PCLI specification could look like. I wrote down on paper what I've been doing in the numerous CLI programs (for a broad value of the terms) I wrote over the past years.</p>

<p>A CLI program has to go through these steps:<br />
<ol><br />
<li>fetch and parse environment variables (<code>%ENV</code>); errors may be warned about or fatal</li><br />
<li>fetch and parse command-line options (<code>@ARGV</code>); errors are fatal</li><br />
<li>handle usage and help (<code>Pod::Usage</code></li><br />
<li>parse configuration file; errors are fatal</li><br />
<li>check all parameters (mandatory options, exclusive options, etc); errors are fatal</li><br />
<li>apply all parameters default values</li><br />
<li>setup logging; errors may be silent, warned about, or fatal</li><br />
<li>become a daemon, for the programs intended to run this way</li><br />
<li>setup basic signals managements (<code>INT</code>, <code>TERM</code>, <code>QUIT</code>, <code>HUP</code>), usually for daemons, but can also be useful for programs running for a long time<br />
</ol></p>

<p>Now, I didn't know what PSGI looked like (I'm a sysdev, not a webdev). Today, I read the specification, and it confirmed what I had already identified: yes, PSGI is brilliantly "simple" because it was written by people knowing very well this field, helping themselves with the experience of similar specifications (WSGI, Rack, JSGI). But it is also simple because it is a protocol built on top of a protocol (HTTP), built on top of a protocol (TCP), built... At PSGI level, there's just a bidirectional channel with data going in both directions. And it's platform agnostic.</p>

<p>However, in the CLI world (and let's limit ourselves to the Unix world for the sake of simplicity), we have multiple channels of input (<code>%ENV</code>, options, configuration file(s), <code>STDIN</code>, input data files, signals) and output (<code>STDOUT</code>, <code>STDERR</code>, logging, output data files), and no standardized protocol of any kind.</p>

<p>Now, I'm afraid that either we try to cover most of the features we need, and we end up with a specification too complex, or we limit to a subset of the features, and we end up with a specification too simple to be actually useful.</p>

<p>Did I miss something? Was Matt too optimistic or am I once again too pessimistic?</p>]]>
        
    </content>
</entry>

<entry>
    <title>Beginning with an end</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/maddingue/2011/11/beginning-with-an-end.html" />
    <id>tag:blogs.perl.org,2011:/users/maddingue//738.2384</id>

    <published>2011-11-01T22:15:02Z</published>
    <updated>2011-11-01T23:08:20Z</updated>

    <summary>The last day of September was also my last day at Orange, after 5 years and 9 months working there as a sysadmin/sysdev. Because I was &quot;the Perl guy&quot; other there, my last message couldn&apos;t be a standard &quot;it&apos;s been...</summary>
    <author>
        <name>Maddingue</name>
        <uri>https://github.com/maddingue</uri>
    </author>
    
    <category term="perlobfuscationtiming" label="perl obfuscation timing" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/maddingue/">
        <![CDATA[<p>The last day of September was also my last day at Orange, after 5 years and 9 months working there as a sysadmin/sysdev. Because I was "the Perl guy" other there, my last message couldn't be a standard "it's been a pleasure working with you blah blah". Obviously, I had to send a Perl obfuscation.</p>]]>
        <![CDATA[<p>Unfortunately, I didn't have the time to work more than one or two hours on it, so I ended with something simple:</p>

<p><tt>use 5.010;$:=v117.116.102.56;eval"use encoding $:=>STDOUT=>'$:'";$c=<br />
1e4;$i=-1;$b=0x3041;@f=(20,71,41,72);while($i<4){@v=map+int rand(86)<br />
,1..4;@v[0..$i]=@f[0..$i]if$i>0;$c--if$c&&$v[1+$i]%4==0;$c=+5e3,$i++<br />
if$c==0&&$v[$i]==$f[$i];print+chr($b+$_)for@v;print"\r"}print"\n\x4"</tt></p>

<p>(I know, it barely deserve the title "obfuscation", but I don't have BooK's or cognominal's experience in this domain. At least, it's correctly justified.)</p>

<p>The aim of this code is to print, in a funny way, 5 important characters. The first 4 are the Japanese characters さよなら (sayonara). The last character is ASCII 0x04, EOT (End of Transmission). I'll assume I need not explain the meaning and references.</p>

<p>Now, if I began writing about this code, it's to explain the mistake I did in it. Can you see it?</p>

<p>It's not very apparent because the code basically works. In fact, it works faster than I expected. This is the problem. On my PowerBook G4, it takes a bit more than 5 sec to execute. On a more recent computer, usually less than a second.</p>

<p>The reason? I stupidly used loops to simulate sleeps. This is surely lesson one when making a <a href="http://en.wikipedia.org/wiki/Demo_(computer_programming)">demo</a> or a game: <a href="https://github.com/PerlGameDev/SDL_Manual/blob/master/src/04-game.pod">fix your timestep</a> so the program performs consistently on different platforms. That's not something we're used to think of in sysdev, but that's the basis when making a <a href="http://sdl.perl.org/">game</a>.</p>]]>
    </content>
</entry>

</feed>
