Gtk3 with Perl and AnyEvent
Gtk+ its an awesome toolkit, cross platform, cross language it is all great but the documentation is terrible specially on scripting language’s side. Basically if you want to get anything done you have to browse the official (yet incomplete) documentation, StackOverflow questions, blogs and even so you may not be able to find the answer for your problem.
Gtk3 is even more complicated because is relatively new and because most implementations use introspection to generate the bindings so there is no way to read the source of anything to see what methods or classes are available. The other day I was looking for an example on how to draw a widget that can be updated based on an event, in other words, how to mix AnyEvent and Gtk3. It took me couple days to come up with a solution that works (Gtk3 changes things a little bit).
Here is the code…
#!/usr/bin/env perl
use warnings;
use strict;
use Cairo::GObject;
use Gtk3 '-init';
use AnyEvent;
my $window = Gtk3::Window->new('toplevel');
$window->signal_connect( 'destroy' => sub { Gtk3->main_quit } );
my $drawable = Gtk3::DrawingArea->new;
$drawable->signal_connect(
'draw' => sub {
my ( $widget, $context ) = @_;
my $alloc = $widget->get_allocation;
$context->move_to( rand( $alloc->{width} ), rand( $alloc->{height} ) );
$context->rel_line_to( 10, 10 );
$context->stroke;
}
);
$window->add($drawable);
$window->show_all;
my $timer = AnyEvent->timer(
interval => 0.5,
cb => sub { $drawable->queue_draw }
);
Gtk3->main;
Blogging from my iPad
After having an iPad unopened in my drawer for 6 months I’ve decided to give it a try, it was a gift and I was planning on selling it as it’s not a RMS compliant device. I was very disappointed that I was not able to sell it to the price I’ve set for it - even I lowered it couple times - so I imagined that I could give it a use after all and would mainly use it to read books and browsing Internet.
Was not long after that I wanted to at least be able to blog or write documents from it, I was very surprised in a bad way that it’s hell too difficult to do. My setup it’s quite simple text editor + Github but it seems to much for an iPad, I couldn’t find any app to use Git from an iPad. I even tried cloud editors such as Cloud9 but none of them work in iPad’s Safari.
Also discovered that asking for a file browser is asking too much as well. A friend told me that the device wasn’t designed for that type of work. He’s right but I didn’t give up so I went for alternative app repositories - meaning Jailbreak - then things changed quite a bit. I got iFile, OpenSSH, Git, Emacs, MobileTerminal. After all it’s possible to use the iPad to produce content. It ain’t easy but possible, as a matter of fact I’m waiting this post using it.
My next target it’s being able write some code on it, and there Textastic looks promising.
Agile ain't a silver bullet
Through my career I’ve experienced many software development methodologies such as Waterfall, XP and most recently Kanban, I’ve even worked with no methodology whatsoever. I don’t consider myself a big fan of the methodologies specially when they become the answer to problems like delays, low quality, misunderstandings between the product owner and the development team.
Methodology changes are the usual reaction from management to the problems mentioned earlier and I can totally understand that as it’s the main tool within their power. In my experience process and methodologies help - or at least don’t get in the way - but are never the deciding factor of the success of a team.
Last October I attended to the keynote speak of James Shore in Agiles 2011 and he was saying that today’s agile teams (or most of them) are nothing like the agile teams when the agile movement just started, like if something happened along the way and now the agile teams act like the old waterfall teams. I can totally see that happening but I don’t think it is related to the methodology those teams are working on. Even more I’d bet that Kent Beck would be still a rock-star in any methodology he works on, just because he is an A-class employee.
Where am I going with all this? my point is that ultimately what determines the success or failure of whatever you do is the people it always was and it always will be. You want results, uh? then make sure you got the right people and then start speaking about tools and processes doing otherwise is dooming yourself.
If you don't need to then don't do it
Recently I’ve submitted a patch for one of the CPAN modules, the module connected to a server to make sure the server its alive before sending any command to it.
Let me sketch the code:
sub new {
...
eval {
$self->test_connection($target_host);
};
if ($@) {
die "Can't Connect";
}
}
The problem is even more complex, because depending on the server the test connection message could return 200 as response code or 500. I was trying to point out that the extra step was completely unnecessary, the author was pointing out that just because the server answers something means that is alive, that’s true, but what value does it brings?, Does that means the it will be able to process commands? ehrr.. I don’t know, Does it means I’m sure the server will be available when I start sending commands to it? I can’t tell.
The former approach has other downsides:
- Let’s assume that server changes the behavior and instead of returning error 500 returns 404, then our code won’t caught that and it will be broken because our code is expecting 200 or 500.
- Now let’s say we create an object but we don’t use it, with this code since the test_connection is part of the new method that means it will be executed always even if then we don’t use the object.
- We have extra overhead because instead of sending our first command when we need it is always sending a “ping” before
What will happen if the server responds the first time and then it crashes? But… it was working a minute ago… so????
In my opinion it’s better to limit the number of times you call an external resource and call it only when you need them.
DBD::Mock 1.43 released!
I’ve just finished uploading version 1.43 of DBD::Mock. Couple months ago I’ve spoken with the author and asked to be the maintainer of that module since they were not releasing new versions.
Since then my focus was narrowing down the open bugs in the queue. Now I’ve only one bug sitting there waiting to be resolved. As a goal I’ve set a calendar of monthly releases - or at least every two months - so people don’t wait a lot for bug fixes or new features.
I haven’t made significant changes to the API yet and to be honest I’ll try maintain backwards compatibility as much as I can because I don’t want to make my users change their tests. At the same time I want to introduce changes to make the API more intuitive and easier to use and bring new functionality into.
This version includes:
- Segregated into different packages
- Removed code coverage from POD
- Fixed bug rt49537 Basic support for named parameters
- Fixed bug rt70421 Build.PL now contains Test::Exception
Enjoy!