Mojo vs Dancer Week 1 - Installer, Support and Hello World

Alias on 2010-04-03T17:17:59

Lets Get Ready To Ruuuumblllleeee*cough*splutter* ahem. Sorry about that.

Welcome to the Mojo vs Dancer Top 100 Competition.

Over the next month or so I'll be building a replacement for my prototype CPAN Top 100 website simultaneously using the Dancer and Mojolicious micro-web frameworks.

The Competition Rules

While I do have a fair bit of experience with Perl coding, I will be trying wherever possible to behave in naively and newbie'ish fashion when it comes to community, support and tools.

I hope that during this process we can get some idea of the typical end user who won't know the right people to talk to or the right places to go for help.

One round will occur each weekend. I shall address one area each round, progressing until I have a working application (hopefully two).

While each weekend you will be subjected to my newbie code, during the rest of the week I will be inviting the development teams of both web frameworks to "improve" my code. They do so, however, at risk of LOSING existing points, should they try to hard to show off and create something I don't understand.

The week gap also gives plenty of time for each team to respond to my comments, to deny problems, to clarifying mistakes, and to fix, upgrade and do new releases.

For each issue I stumble across on my journey, I shall appoint only one winner. Each week may address more than one issue.

However, while I'll be recording the scores issue by issue, ultimate victory will be based entirely on my subjective personal preference for the one I think will be quickest and easiest for me to maintain.

If you'd like to follow along at home you can checkout the code for each project at the following locations.

Mojolicious - http://svn.ali.as/cpan/trunk/Top100-Mojo

Dancer - http://svn.ali.as/cpan/trunk/Top100-Dancer

Mojo - Getting to Hello World

I have some history with Mojo, being present at (and in a small way contributing too) its birth when Sebastian Riedel left the Catalyst project.

I've even attempted to build a Mojo application before, but was told at the time they weren't quite ready for actual users yet.

Their website is clean, efficient, but practically unchanged since I looked at it the first time.

It's also somewhat broken or at least unmaintained. The "Blog" link just points back to the same page, the "Reference" link points at what looks like a search.cpan.org failed search, and the "Development" link just throws me out to Github (which doesn't seem to really help much if I wanted to write a plugin or something other than hacking the core).

The "Book" link points to another search.cpan error page, and the most recent version at time of writing is 0.999924 which seems weird and makes me wonder how well they run the project.

Although the website doesn't fill me with confidence, the installation process is an entirely different story. One of Mojo's core design principles is to be pure perl and have zero non-core dependencies.

Installation via the CPAN client is fast, simple, and effortless. And I have full confidence that (if I needed to) I could just drop the contents of lib into my project and upload it to shared hosting somewhere.

I hear some rumors that to achieve this they've done rewrites of some very common APIs that work slightly differently, but I won't be looking into this right now. It will be a matter for another week.

To create my initial Hello World I've taken the most obvious approach and just cut-and-paste the code off the front page of the Mojolicious website, then stripped out the param-handling stuff, and modified the rest to something obvious looking. I've also added in strict and warnings, which the sample doesn't have.

Before attempting to run it, I have the following.

#!/usr/bin/perl

use strict; use warnings; use Mojolicious::Lite; get '/' => 'index';

shagadelic;

__DATA__

@@ index.html.ep Hello World!
Looking at this code, it seems that everything is template based. This should be a good thing in general, as I'm a heavy Dreamweaver user and don't much like generating pages from raw code.

So far, it seems fairly simple. My main problem is that I have no idea what the hell "shagadelic" does, although I suspect it's some kind of way of saying "done". Whatever it is for, it annoys me enormously and dates the framework to (I assume) the release date of one of the Austin Powers movies. I get the feeling it is going to make Mojo feel more and more dated over time.

And they don't use strict or warnings, which seems a bit iffy.

When I run this helloworld.pl script, I get a handy little block of quite informative help text for my application for free.
C:\cpan\trunk\Top100-Mojo>perl helloworld.pl
usage: helloworld.pl COMMAND [OPTIONS]

Tip: CGI, FastCGI and PSGI environments can be automatically detected very often and work without commands.

These commands are currently available: generate Generate files and directories from templates. inflate Inflate embedded files to real files. routes Show available routes. cgi Start application with CGI backend. daemon Start application with HTTP 1.1 backend. daemon_prefork Start application with preforking HTTP 1.1 backend. fastcgi Start application with FastCGI backend. get Get file from URL. psgi Start application with PSGI backend. test Run unit tests. version Show versions of installed modules.

See 'helloworld.pl help COMMAND' for more information on a specific command.
Running the obvious "perl helloworld.pl daemon" like it says on the website and connecting to http://localhost:3000/ I get a simple working "Hello World!" response first time.

So far so good then, except for the rather dead website. And no need to try any of the support channels yet either.

Dancer - Getting to Hello World

The Dancer website seems quite a bit more enticing than the Mojo website, at least superficially. There's evidence of more attention to some of the visual details, with more design elegance and things like source code syntax highlighting.

Clicking through the links, however, it's clear information is still a bit thin on the ground. And the "latest release" version on the download page is behind the version on CPAN, but not by much.

The website generally has more of a "new and undeveloped" feel to it, compared to Mojo's "mild neglect" feel.

One nice thing about the website, is that they've dropped a Hello World example directly on the front page for me to copy and paste.

After some small tweaks for my personal take on Perl "correctness" and legibility (the Dancer guys also don't use strict or warnings...) I have the following.
#!/usr/bin/perl

use strict; use warnings; use Dancer;

get '/' => sub { return <<'END_PAGE' }; Hello World! END_PAGE dance;
The Dancer example is smaller and simpler than Mojo example, and doesn't make template use compulsory. Again, I can't stand this use of non-descriptive functions to end these programs. But at least "dance" is cleaner, is an actual verb, and is a bit less tragic than "shagadelic".

Instead, tragedy strikes for Dancer when I try to install it.

Because it doesn't install. Or at least, it doesn't install on Windows. Or perhaps it's just my Vista machine.

A redirect test is failing with this...
t/03_route_handler/11_redirect.t ............. 1/?
#   Failed test 'location is set to http://localhost/'
#   at t/03_route_handler/11_redirect.t line 36.
#          got: '//localhost/'
#     expected: 'http://localhost/'

# Failed test 'location is set to /login?failed=1' # at t/03_route_handler/11_redirect.t line 44. # got: '//localhost/login?failed=1' # expected: 'http://localhost/login?failed=1' # Looks like you failed 2 tests of 9. t/03_route_handler/11_redirect.t ............. Dubious, test returned 2 (wstat 512, 0x200) Failed 2/9 subtests
As a non-expert, that looks pretty serious. Maybe I'd force the install if it wasn't something as essential as redirecting that fails. But this is a pretty ordinary feature, and it's not working, and forcing in general scares me.

The one saving grace is at least it failed quickly. While not keeping dependencies to zero, they've done a fairly decent job of keeping the dependency list down to a minimum.

But the most damning factor here is a not that it failed once, but when I follow up by taking a look at their CPAN Testers results. These show failure rates all over the place, up and down, with some big regressions.

This kind of pattern usually suggests that Dancer is seriously lacking in their QA procedures, or have a complete disregard for platforms or Perl versions other than newer Perls on operating systems they personally have. This makes Dancer a risky choice for me to bet on, because it means it could all go wrong down the line unexpectedly.

So at this point, I'm going to stop with Dancer for this week, having failed to get Hello World working. We'll see if the Dancer guys can address this before next weekend.

Week 1 Results

Best Website - Dancer

While this isn't a massive victory, Mojo's many broken links hurt it, while Dancer shows at least some desire to be pretty, which I take as a hint that it might be easier for me in the future to make on my website pretty too.

Best Installation - Mojo

Zero dependencies and a fast installation that Just Worked, contrasts enormously with the failed installation of Dancer, and its unreliability over time (according to CPAN Testers at least).

If left to my own devices, I would probably already have committed to Mojo at this point, although reluctantly given Dancer's more desirable prettiness.

Best Hello World - Dancer

This one was quite close. Mojo suffered a bit because it forced its templating syntax onto me during Hello World, while Dancer suffered a bit because I had to resort to a Heredoc in the hello world.

In the end I'm awarding this to Dancer because of the pain in my brain that the function name "shagadelic" causes. I might have been cool for the first day or two, but long term I just know this is going to become an eyesore in my code.

Overall Leader after Week 1 - Mojo

Despite Dancer beating Mojo two to one on the individual factors, when the time came to do what I needed to do, Mojo installed quickly, gave me some help in the right place, and ran my Hello World without error or argument.

And Dancer did not these things.

Clearly, there's some QA work for the Dancer guys to do before next week, and the Mojo guys should probably dust some of the cobwebs off their website at the same time.

Next week, the competition will continue with database and ORM integration.

Until then, hopefully the respective teams will be blogging their responses and hopefully dealing with any issues raised.


Correctness

Hansen on 2010-04-03T18:30:40

I'm looking forward to you in-depth review of the actual codebases and not just syntextual suger, as you are probably aware some of the some competitors has re-implemented a lot of existing mature codebases on CPAN, such as RFC: 2109, 2388, 2616, 4627, etc.

And simple thing like I/O and syscalls (logging error reporting) etc...

-- chansen

Re:Correctness

sri on 2010-04-03T19:06:28

See comment below please.

Re:Correctness

Alias on 2010-04-04T02:06:11

I won't be reviewing their code unless, for some reason, some failure takes me chasing down into it in the debugger.

However, I may end up commenting on their APIs and naming if it sticks out as unusual

Re:Correctness

Ovid on 2010-04-04T06:18:30

A code review may not be as useful. What users almost always want to know is:

  • Does it do what I need?
  • Is it easy to learn?
  • Can I trust it? (less so on this one, unless they'll be using it for the long haul)

One issue with code reviews is that reviews are terribly subjective. If I have a different take on how to approach a problem, I might very well ding someone on a review because I didn't understand/appreciate their code.

Yes!

sri on 2010-04-03T18:51:58

Such an in depth review would be amazing and very helpful, but i think it might be a bit too much for this competition.
Maybe we can find a GSOC student to give it a try! :)
Btw. "use Mojolicious::Lite" activates strict and warnings.

P.S: Website should be fixed and all examples have been updated to use "app->start" instead of "shagadelic". (Lets face it, inside jokes are not fun for new users)

Re:Yes!

sri on 2010-04-03T19:15:02

This was meant as a reply to chansens comment above.

Re:Yes!

jeremiah on 2010-04-17T13:59:16

Excellent - looks like Mojolicious is responsive. :)

Excellent Start

Ovid on 2010-04-03T19:03:28

Thanks for this excellent start to the competition. I really appreciate that you're focusing on the viewpoint of a new user rather than an experienced developer.

This is particularly evident in the fact that some of your HTML is showing through rather than being rendered properly :) (e.g., <a href="http://svn.ali.as/cpan/trunk/Top100-Mojo">http://svn.ali.as/cpan/trunk/Top 100-Mojo</a> instead of http://svn.ali.as/cpan/trunk/Top 100-Mojo).

Re:Excellent Start

Alias on 2010-04-04T02:07:21

It was very very late, and I wasn't paying enough attention obviously :)

Layout and spelling/grammar/etc nigglies fixed hopefully.

Dancer on MS Windows

jnareb on 2010-04-03T19:07:56

Savyer X in blog post Stepping up to the plate wrote:

Adam Kennedy has declared a contest between Dancer and Mojolicious. Seems to me like a great idea. We'll both get a chance to learn from each other, show our strengths and try to work on our exposed weaknesses.

[...]

Right now, Dancer cannot participate in the challenge. The reason is since Adam uses Windows and Dancer doesn't install on Windows. It isn't that Dancer is not Windows-compatible, it's just that it uses HTTP::Server::Simple::PSGI, which uses HTTP::Server::Simple which fails a test on Windows. Thus, Dancer cannot be installed on Windows (at least with StrawberryPerl, which is what Adam - and many others - use).

P.S. You have formatting errors, like visible HTML codes instead of formatting.

Re:Dancer on MS Windows

Alias on 2010-04-04T02:11:10

I gave them a chance to fix that particular issue, and I even used the patched version of HTTP::Server::Simple they gave me.

The installation failed for another completely different reason.

Pair 'v' Pear

Ron Savage on 2010-04-03T23:22:59

Hi Adam

I'll let other discuss the code.

As for 'pair shaped', it should be 'pear-shaped', since it really describes a woman with too much bulk on her hips and thighs.

Cheers

Re:Pair 'v' Pear

Alias on 2010-04-04T02:08:01

Typo, fixed.

It's not just you...

DiamondInTheRough on 2010-04-04T05:56:51

My Win7 machine gives the same errors.

use strict/warnings and Windows

reezer on 2010-04-04T09:22:56

From Dancer::Cookbook

"Note that you don't need to use the strict and warnings pragma, they are already loaded by Dancer."

So it saves space, like Modern::Perl, which would be a bonus for me.

To all users of Perl on Windows. Maybe it works with the latest (beta/RC) version of strawberry perl. At least here it works. http://strawberryperl.com/beta/

This competition is a great idea! I've never ever used one of these before I read about the competition. The reason is that nearly nobody was talking about this, so it's great someone does.

Re:use strict/warnings and Windows

draven on 2010-04-04T13:20:05

This is actually the case for Mojolicious as well.

Re:use strict/warnings and Windows

reezer on 2010-04-04T13:44:39

I guess it would be better, if every module used Modern::Perl, so it is more visible. I also had to find this statement first.

Will create some Dancer and Modern::Perl packages for linux distros and pkgsrc.

Re:use strict/warnings and Windows

ruz on 2010-04-05T09:48:56

Then both can win from either of the following:
1) a comment in hello world example, for example: "no need in use strict or use warnings as above does that for you"
2) every line in the example with comments
3) example without comments and with comments

By the way Alias doesn't sound like a newbie :) Who knows about CPAN testers during his first month programming in perl.

Re:use strict/warnings

snarkyboojum on 2010-04-05T01:51:40

use'ing Modern::Perl also means I have to be running Perl 5.10 or later. It'd be a shame to prevent people on older Perls from using Dancer.

I'd suggest keeping it as it is.

I don't see the big deal; either spend 2 minutes reading the documentation and work out that 'use Dancer;' loads the strict and warnings pragmas for you, or do it in your code (redundantly) as Alias has done.

Please don't force me to use a particular version of Perl for some kind of bogus "consistency" argument.

Re:use strict/warnings

snarkyboojum on 2010-04-05T01:53:18

apologies - that was supposed to be in reply to 'Re:use strict/warnings and Windows' by reezer.

Re:use strict/warnings

chromatic on 2010-04-08T18:51:19

M::P doesn't prevent people from running on earlier versions of Perl. It only means they have to know how to do so.