Google app engine

I’m trying some proper grown-up programming today!  I’m working through the udacity CS253 Web Application Engineering course, to try to write real live web applications in python that are hosted through google.  I’m finding the course probably a little tougher than I should because I haven’t yet completed the CS101 Introduction to programming course, which teaches Python, so while I know the theory of programming I don’t necessarily know the Python-specific version of things.

birthday validator web application

birthday validator app

However, I’ve managed to complete unit 1, which was a recap of HTML forms, and then homework 1, which was to get a real live application up and running.  During unit 2, this application was developed into the project in the link, to provide a simple form, then check the values entered in the form and either ask the user to check and resubmit or confirm that the date entered is valid (not full validation: it only checks the month is valid, the date is between 1 and 31 and the year is within certain dates).

Now my task for homework 2 is to write an application similar to the Udacity version of a ROT 13 encoder.

This is where I find that what I’ve understood in previous sessions I don’t necessarily know enough yet to apply!  It really goes to show that working on your own project strengthens your learning so much more than merely reading about it and copying someone else’s project.

app engine launcher

app engine launcher, showing current apps running locally

First I had to create a new application, which proved a little tricky – I think I was trying to go too fast and went wrong somewhere so tried again, following step by step with the video, and this time checked that the dummy application that’s created was accessible before moving on.  The google app engine provides a way to run the applications on your local machine, so that all testing and building can take place offline first.

Once I had a dummy application, I could then start to amend the code, taking pieces of code from the birthday validation code to adapt where necessary.

First step was to copy the udacity html source code for the page itself.  Then I managed to find a rot13 function in python that would do the encoding I needed, to save myself having to write my own function.

So the challenge that was left was to use string substitution to rerender the submitted form with the encoded version of the text.  This would then continue to apply every time the form is submitted, so that the encoded version would roll back to the unencoded version (rot13 is a very simple substitution cypher: it moves each character on 13 places in the alphabet, rolling round.  Applying it twice puts the letter back to the correct one).

At this point I once again had reinforced to me that you have to understand what you’re doing in computer languages, unlike in French or German where as long as you have something similar the person on the other end will try to meet you halfway!

The basic algorithm is:

  1. Display the page and form with nothing in the text area to start.
  2. When submit is pressed, encode the text from the text area using ROT13
  3. Then redisplay the page and form with the encoded text.
  4. When the submit button is pressed again return to step 2 and continue.

A good couple of hours later I had most of the code working but couldn’t display the encoded text within the text area.  Getting frustrated, I took a look at the solution provided on Udacity, only to discover that it contained a lot that hadn’t been covered at all!  In fact I found a thread on the accompanying forums complaining that the solution given was not given very clearly, and contained several aspects that hadn’t been covered in the sessions.  While it is fair at this stage to expect students of the course (who are adult students studying for their own interest) to do a little research by themselves, it’s a little unfair to disregard what’s been covered in the course so far and to introduce in a homework solution topics that are completely new!

project to encode text using ROT13

ROT13 encoding project

It was while poking around in the forums that I managed to discover what my problem was: we’d been introduced to a new html form element, the textarea, which takes values slightly differently from the elements we’d used so far.  Altering my code to take that into account produced the solution, which I was then quickly able to finish off, before uploading the finished project.

So what have I learned by doing this?  I’ve gained experience in using the app engine, and using Python generally, but I’ve also learned some valuable lessons for learning: when you set a task, there’s an amazing amount of learning to be done by adapting previous projects to fit a new brief, but it’s very important to make sure that you don’t expect too much too soon in the way of independent learning.  There’s enough to learn, especially in the early stages, by recycling current knowledge, without the time wasting effort needed to investigate extra material that’s not been shown.  Indeed, a missing comma wasted plenty of my time as it was, let alone the problems with the text area display!  It’s also important that a good solution/explanation is available if someone does get stuck, as the Udacity solution was so far from what we’ve learned that it added to my confusion rather than helping it.

The other thing that I’ve learned is that as simple as the finished project is, I get a lot of satisfaction from battling with the computer and winning, and if I can get some of that sense of achievement over to my students I’ll be very happy.

 

Advertisements