Imagine that this was enforced by the compiler/interpreter - maybe with a new keyword function, or something. I have the feeling that this would be very similar to how use strict works - giving the end user some kind of safety.
Friday, April 27, 2012
If all of your state is on the stack then you are doing functional programming
Tuesday, April 17, 2012
A Data::Dumper bug - or Latin1 strikes again
To get a character that has internal representation in Latin1 I could also use HTML::Entities::decode( 'ó' ) there with the same result. The output I get on 5.14.2 and 5.10.1 is:
When I check the dumped string - it has the right character encoded in Latin1 - and apparently eval expects UTF8 when
use utf8 is set. Without use utf8 eval works OK on it. If the internal representation of the initial character is UTF8 (like when the first line is my $initial = 'ó';) - then the dumped string contains UTF8 (which is again might be interpreted incorrectly if the code does not have use utf8 preamble).
Considering that Data::Dumper is a core module and one that is one of the most commonly used and that its docs say:
The return value can be evaled to get back an identical copy of the original reference structure.this looks like a serious bug.
Is that a known problem? Should I post it to the Perl RT?
Update: Removed the initial eval - "\x{f3}" is enough to get the Latin1 encoded character. Some editing.
Update: I tested it also on 5.15.9 and it fails in the same way.
Update: I've reported it to the Perl RT - I am not sure about the severity chosen and the subject - this was my first Perl bug report.
Update: In reply to the ticket linked above Father Chrysostomos explains: "The real bug here is that ‘eval’ is respecting the ‘use utf8’ from outside it." and later adds that 'use v5.16' will fix the problem in 5.16.
Saturday, April 14, 2012
Breaking problems down and defaults
The problem is that the criticized approach, a unified library that just converts Markdown to HTML, would result in a simpler API - for example something like this:
Maybe the difference does not look very significant - but after a while it can get annoying. For the 99% of cases you don't need to extra flexibility that comes with the replaceable parser - so why should you pay for it? If I had to use Markdent frequently I would write a wrapper around it with an API like above.
By the way, Text::Markdown already has this wrapper and it does present a double, functional/object oriented API - where the presented above simple, functional one does the most common thing, while the object oriented one gives you more control over the choices made. Only that it still couples parsing and generation.
Another way of simplifying the API is providing defaults to function arguments. For example to the object constructor. Dependency Injection is all about breaking the problem down and making flexible tools - but it might become unbearable if we not soften it up a bit with defaults.
Programming is always about doing trade-offs - here we add some internal complexity (by adding the wrappers or providing the defaults) and in exchange get a simplified API that covers the most common cases while still maintaining the full power under the hood. I think this is a good trade off in most cases, and especially in the case of libraries published to CPAN that need to be as universal as possible.
Wednesday, April 04, 2012
What if "character != its utf8 encoding" is overengineering?
Getting rid of the Latin1 internal encoding does not look like a big price for improving simplicity and getting rid of all these subtle mistakes. I think it is important that the language is understood by its users and if it is not, then maybe, instead of blaming the programmers, we could make it easier to understand? Sure it is nice to have the possibility to change the internal encoding from UTF8 to UTF16 or maybe something completely different in the future - but I have the feeling that this might be case of architecture astronautics.
Saturday, March 31, 2012
Plack::Middleware::Auth::Form - some updates and a possible name change
The bug reported in #75896: Cookie Expiry Date not set for "remember" session is quite interesting. Apparently Plack::Middleware::Session sends the session cookie on each request and if you don't set Expiry Date each time it will happily unset it.
I am thinking about changing the name to WebPrototypes::LoginForm. Some people did not like the name Plack::Middleware::Auth::Form from the start, because it is a bit more high-level then the other Auth middlewares, and now I have two more elements for quick web application prototyping under the WebPrototypes namespace.
Sunday, March 25, 2012
Blog writing and assuming stupidity
What happened there? Again, it is hard to tell anything interesting without some speculation - and possibly I'll have to apologize to Dave for this - but I think Dave has read "You must hate version control systems, we won't be using any" and assumed that this is is from a company that superficially rejected version control because they did not want to learn or, in other words, from someone that assumed that version control is useless. Talk about beams and eyes. That's not to say that I vouch for the 'pipelines' system or for replacing version control with it. I still don't know much about these pipelines - but new ideas don't have to work in every possible aspect to be worthwhile and you'll not have a break-through idea if you always stick to the accepted wisdom.
It is easy to assume stupidity - on average people are mediocre - but the internet is a big search space - expect to be surprised from time to time :)
Monday, March 19, 2012
Verbs and Nouns
Do we overuse nouns? Or maybe it is that actions are opaque and unstructured - and when we need to get to the the details, the parts that compose them - then it is more natural to treat them as things? Wouldn't it be easier to incorporate streaming in PSGI if the application there was an object with methods and attributes?
Sunday, March 11, 2012
WebNano - code experiments
- Keeping the parsed path as an attribute in the controller.
- Additionally to the above I tried adding three more controller methods: 'action_name', 'action_args' and 'action_postfix'.
- I wrote two additional test controllers for the simple url schema, both redirecting handling to DvdDatabase::Controller::Dvd::Record for the case where we have a record to handle: overriding local_dispatch, overriding handle
- having the path as attribute is handy for code retrieving the record
- the additional controller methods help with writing custom dispatchers
- splitting the processing to two controllers - one for the case where you have one object to work on (like viewing, editing, deleting), second for the case where we don't (like listing, creating) is very clean - you can have the object as controller attribute
- the the additional dispatcher methods are less useful for that more clean architecture
- the biggest problem was always preventing the methods that require the object to be called when we don't have the record id on the path (like '/view' when we assume that it should be '/1/view') - and the best method to do that is having the two controller classes
- overriding 'handle' is actually simpler - because it is a very simple method
Tuesday, March 06, 2012
Why Bread::Board looks mostly redundant
For example let's take the original example from Bread::Board synopsis: Now - let's do the same with just variables: You can also feel fancy and do it with Moose lazy attributes: This is not longer than the BB example and it uses generic tools.
Friday, March 02, 2012
Mason 2
Saturday, January 14, 2012
Schlep
Narrowing this down to my own Perl web development work - the schlep for me was always getting the basic web app running with user registration, login pages, password reset mechanisms, etc. - in every new project that was the most repeatable, boring work. I think everyone has the feeling that this does not need to be like that. I've started thinking about what could be a solution to this and here are my first experiments about fixing it: Plack-Middleware-Auth-Form, WebPrototypes::ResetPass, WebPrototypes::Registration (I might rename the first one to WebPrototypes as well). The point is to solve it across the multiple web frameworks, templating languages and storage layers - so that it can survive moving from project to project.
What is your schlep?
Saturday, December 10, 2011
A kind of call by name
$self->create_user( username => $username, email => $email, pass_token => $pass_token );I wish I could get rid of the naming redundancy in this call:
$self->create_user( $username, $email, $pass_token );(without changing 'create_user' of course).
Probably some new syntax would be needed.
Friday, November 18, 2011
'use strict' and cargo cult programming
I used to program without use strict; use warnings but after exposure to the usual propaganda I switched and I found that the cost of mindlessly adding it is negligible, the cases where I need no strict are very rare, and there are many benefits of doing it, especially when working with old code. This cult is rather effective in luring the cargo planes to land in my atoll. On the other hand I am all for deep analysis and checking your assumptions from time to time. There are many valid points in Marc Lehman common::sense and I would like to see them discussed. While we are on the road to have use strict by default we might also try to make it better.
Saturday, November 12, 2011
$ primes for money
Money has been said to change people's motivation (mainly for the better) and their behavior toward others (mainly for the worse). The results of nine experiments suggest that money brings about a self-sufficient orientation in which people prefer to be free of dependency and dependents. Reminders of money, relative to nonmoney reminders, led to reduced requests for help and reduced helpfulness toward others. Relative to participants primed with neutral concepts, participants primed with money preferred to play alone, work alone, and put more physical distance between themselves and a new acquaintance.from one of the first links in the query above. Pretty sad - can that apply to the Perl community? Another link from that list, an entertaining BBC video report suggests also some other effects: hunger and pain insensitivity.
Monday, November 07, 2011
Thesis: simple - antythesis: easy - synthesis: ...
The development sprints he attacks are not about doing the bulk of the work - they are about building a prototype on which we can test our assumptions. Without the understanding that we get from these prototypes we could simplify as much as we want but it would not change the fact that our solution solves the wrong problem. Agile is not an enemy of simple, it puts a lot of weight to doing the easy - but not because this is the goal - rather it uses easy as a mean to get to the correct. Agile is the answer to the paradox that we don't know what we should make until we already have a prototype of that thing. I wish more developers cared about simple - but only after they know what is needed.
Tuesday, November 01, 2011
Notes on the Synthesis of Form
Alexander's Notes on the Synthesis of Form was required reading for researchers in computer science throughout the 1960s. It had an influence[8] in the 1960s and 1970s on programming language design, modular programming, object-oriented programming, software engineering and other design methodologies. Alexander's mathematical concepts and orientation were similar to Edsger Dijkstra's influential A Discipline of Programming.The solution to the design problem that he proposes there does not look too attractive now, but his models, his metaphors, his insight into the design process - it's all still relevant and spot on. I am surprised that the Agile movement does not quote "Notes" as one of their foundation texts.
Saturday, October 15, 2011
Concentration and Flow or Yet Another Dependency Injection Note
Collaborators in an algorithm are like those tools, having them readily available lets you concentrate on the problem.
Friday, October 14, 2011
Object oriented versus functional interface
my $w3c = DateTime::Format::W3CDTF->new;
my $dt = $w3c->parse_datetime( $date_string );
I wish it was:
my $dt = DateTime::Format::W3CDTF->parse_datetime( $date_string );
and that the library created the parser on the fly as needed. It's not only less typing - but also much simpler mental model. This simpler model is sometimes too simple - for example if you parse a lot of dates then sparing the parser creation each time can make a difference.
I think the optimal thing to do is provide two APIs - like JSON - a functional one:
$perl_hash_or_arrayref = decode_json $utf8_encoded_json_text;
and an object oriented one:
$json = JSON->new->allow_nonref;
$perl_scalar = $json->decode( $json_text );
for those that need that extra control.
Monday, October 03, 2011
open expects filename as binary data encoded in the system characterset
use strict;
use warnings;
use autodie;
use HTML::Entities;
use Encode;
my $a = HTML::Entities::decode( 'ñ' );
open(my $fh, '>', $a );
print $fh "Without encoding\n";
close $fh;
open(my $fh1, '>', encode( 'UTF-8', $a ) );
print $fh1 "With encoding\n";
close $fh1
And here is the result when run on an system with UTF8 locales:
zby@zby:~/myopera/tmp$ ls
? a.pl ñ
zby@zby:~/myopera/tmp$ cat ñ
With encoding
'a.pl' is the name of the script itself, the mark '?' hides the F1 hexadecimal code and that file contains 'Without encoding'.
Friday, September 30, 2011
Courriel::MMS
It is a bit heuristic - for example many operators send a subject like 'You have received an mms' - which is useless for us, so the library tries to find something else that would act as the subject we need. For dealing with the various mobile operators, that each send a slightly different format of these emails, I used the Factory design pattern together with Module::Pluggable - this is a novel design for me so I wait for comments.

