Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Course notes for Unit 7 of the Udacity course CS253 Web Application Engineering

Course notes for Unit 7 of the Udacity course CS253 Web Application Engineering

Ratings: (0)|Views: 936 |Likes:
Published by Iain McCulloch
Course notes for Unit 7 of the Udacity course CS253 Web Application Engineering
Course notes for Unit 7 of the Udacity course CS253 Web Application Engineering

More info:

Published by: Iain McCulloch on Jun 02, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF or read online from Scribd
See more
See less



Introduction and Overview 
This unit is basically a wrap-up unit, but it will contain some fun stuff. It is all aboutreal-world issues. Things like what to look for in a web framework, how to get hostedand some of the decision making that should underpin these choices.We will talk about how Reddit began on a single machine and how they grew andscaled, learning as they developed. This will include fascinating insights from guestspeakers from Reddit and Udacity who can provide further real-life insights into someof the issues that we have discussed on this course.There are no quizzes in this unit.
Code Organisation 
Steve Huffman
A question that comes up a lot is “How do I organise code?”. You don’t want to keepall your code in one Python file, so what is the correct way to organise things?Well, the first thing to point out is that there is no, one,
answer. Whether youare writing web apps, or any other kind of software, how you organise your code issomething that is personal to you, and will come from your own experience. Stevegoes on to explain his approach:When he starts out, Steve tends to begin with everything in a single file. The file willprobably have sections for:
handlers, which define what to do when a particular URL is hit
URL mappings, which map URLs to the correct handlers
db ModelsAlongside these, Steve will have a number of separate files for static content,including things like css, JavaScript, images, and so forth. Another thing that Stevewill almost always keep separate from the beginning are his template files.Steve’s main Python file is often called simply main.py.The first thing that he does with main.py is to pull out the db models into a separatefile. If you are not using Google App Engine, you may need to write an additionalpiece of code called the ORM (Object Relational Mapping), which maps your Pythonobjects to the relational database. We haven’t had to deal with that in this classbecause App Engine provides this functionality. Steve will generally have a separatefile for each type of data, e.g. posts, art, users, etc. Class specific functions would gointo the appropriate file, so, for example password hashing functions would go in theusers file, and functions to get the top posts etc. would go into the posts file.
The next thing that Steve almost always has is a file called utils.py (which mightactually be a series of files in a directory). This holds all the ‘random stuff’ and handy‘things’. Things like make_secure_val() or make_salt() or random_string(). In general,Steve likes to put as much into utils as he can, so it will include a lot of date-manipulation and string-manipulation functions and also escaping functions. Thisshould be just a list of ‘flat’ functions – functions that have no dependencies on anyother part of the project. It is really important that it is only a one-way inheritance.Handlers can import from utils. Database can import from utils. Anything can importfrom utils, but functions in utils never import from other parts of the project. In theReddit source code there are about 100 functions that are used all over the rest of thecode.The final thing that Steve does (and this might be quite time-consuming) is to take thehandlers out of main.py. There may be separate files for each type of handler.So by now, main.py is just the URL mappings and a bunch of imports.

Activity (4)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Man Netrider liked this
Dharav Solanki liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->