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/perlLooking 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.
use strict; use warnings; use Mojolicious::Lite; get '/' => 'index';
shagadelic;
__DATA__
@@ index.html.ep Hello World!
C:\cpan\trunk\Top100-Mojo>perl helloworld.pl usage: helloworld.pl COMMAND [OPTIONS]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.
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.
#!/usr/bin/perlThe 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".
use strict; use warnings; use Dancer;
get '/' => sub { return <<'END_PAGE' }; Hello World! END_PAGE dance;
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/'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.
# 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
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.
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.:)
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
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.
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.
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.
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 commentsBy 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: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.