This page looks plain and unstyled because you're using a non-standard compliant browser. To see it in its best form, please upgrade to a browser that supports web standards. It's free and painless.

Python WebDev Challenge: The Three Hour App

As my life picks up and I find myself spending more time working on management and PowerPoint rather than code, I occasionally need a detox session. It's good to stay connected with where you came from.

So something I've started doing, just for fun, is trying to develop small but usable applications from scratch in short time window. The idea of a one hour application sounds fun but building a non-trivial project in that time window usually requires a lot of pre-planning. So to keep things honest and not too much like work, I bumped the window out to three hours and set the following three rules:

1 - Use of frameworks and basic templates is allowed, particularly for things such as JavaScript and responsive design (CSS is the bane of my existence (as a perfectionist), that portion of the easily consumes a couple of hours once things get going).

2 - Planning is limited to my lunchtime walk

3 - A second at the project on a subsequent evening is acceptable if you're building completely separate portions of the site

The three hour time limit was dictated by the practical realities of fatherhood. The kids aren't asleep until 8 or 9, I need to head to bed by 11 to midnight. So that gives me a very finite block of time to get stuff done.

One of my first three projects was a quick and dirty hack on a word list generator. This actually turned into three separate projects, two Python and one PHP, but I was able to keep true to principle #3 (each must be separate, each must be done in an evening). The first portion of this loaded a large dictionary into a SQLite database and set up a bottle.py server with some wildcard routes for searching it. For example, to find words beginning with a string of letters, the syntax was: /begin-with/<letters>. For a sample output, I present a list of the words beginning with python (/begin-with/python). But the project was set up so that any string could be fed into the database (if you don't have a problem with getting no results or obscure results).  The front end was stock JQuery Mobile - responsive design right out the box and you can get B+ appearance work by cutting and pasting their demo's - highly recommend looking at this as a first front end framework if you haven't done web design before. Elapsed time: three hours (I was out of town in a hotel room travelling for work that night). I actually wound up recycling most of the code into the starting point for a work-related CRUD app a few months later - JQuery Mobile / SQLite / bottle.py is a very teachable toolset for new developers.

Second challenge, was to extend the pattern matching lookup into a tool to unscramble words (link to main page, which is where this piece of the project got bolted onto the site). This turned out to be even easier than expected. I was able to find a simple way to tweak the database to support the different search - the trick came down to splitting the string of letters into parts and running an efficient search. Itertools to the rescue. Elapsed time - two hours (was able to recycle the database load script). These projects also had my favorite feature of using Bottle.py with 100% standard library modules - the "drag and drop" ftp deploy. Laugh if you will, but being able to dump a project onto a webhost in 3 minutes and just start a process (with Webfaction, it really is that easy; your mileage may vary elsewhere) is a huge advantage.

At this point, the building blocks from a front end and database perspective were getting pretty familiar. So...I had a spare PHP hosting account lying around and an extra domain. Now that I understood the problem, how hard would it be to replicate it using PHP? Turns out.... pretty dang easy... SQLITE3 is an integral module in core PHP so the project came down to writing a twenty line PHP loop to replicate the itertools module functionality we needed to split up the original string and dropping the SQL from our original Python database manager module into a PHP cousin. Boom, a cross-platform solution (demo is here). Completed in about three hours since my PHP was very rusty.

I noticed a couple of other interesting things along the way:

1) Modern web development isn't a one tool skill; note the need for front end (JQuery) and database proficiency, along with Python

2) Once you fully understand a problem in one language, it's not very hard to replicate it in another. This matters when hiring or deciding to re-platform an application.

From a professional / job perspective: a) learn all the pieces and b) when hiring, don't get locked down into one language if you see someone has done non-trivial work in a similar space, and c) the best time to replatform something in a new language or system is when the original architect is still with you, even if they don't know the new technology. Many tools are starting to converge.

Posted by numbercruncher, 07 February 2016 15:25 | Python, word games | Comment (0) | Permalink | Trackbacks (0)

Add comment

authimage

Powered by LT
Valid XHTML 1.0 Strict - Valid CSS