David King

full stack developer

All Blog Articles

Prev « How to write a blog post in a jiffy Next » designer tricks - test many fonts on your site

Psuedocode - How to rapidly plan your work

20 Jan 2012

At some point in my coding life I got into the habit of writing a sort of comment-soup-pseudocode as a way of planning the work ahead of me. Depending on the language and environment I often end up with a mix of basic programming structures (functions, objects etc) flooded with notes about the work I need to do.

For example I am (right now) writing a sites manager for a client, they need to be able to search for addresses on google, see what sites are nearby on their database and given that information they can then go on to use an existing site, or create a new one.

To plan the first part (finding sites) I wrote this psuedo-code:

NG.sites_manager = {};
NG.sites_manager.show = function(){
	// Check we have google
		// Activate the map
NG.sites_manager.geocode_address = function(address, site_id){
	// Geocode the address
		// If we have a site_id
			// NG.sites_manager.add_site(lat, lng, address, site_id, true)
		// Otherwise
			// NG.sites_manager.add_site(lat, lng, address)
NG.sites_manager.add_site = function(lat, lng, title, site_id, focal){
	// If it's focal
		// NG.sites_manager.clear_sites();
	// If we have a site_id
		// If the site exists in the nearby-sites list, exit the function
		// Add the link on the nearby-sites list
	// Add a marker to the map
	// Increment the counter
	// If it's focal
		// Centre the map
		// Request nearby sites
NG.sites_manager.clear_sites = function(){
	// Reset the counter
	// Empty the nearby-sites list
	// Remove the markers
NG.sites_manager.get_nearby_sites = function(lat, lng){
	// Request nearby sites
		// For each site
			// NG.sites_manager.add_site(lat, lng, title, site_id)

It serves many useful purposes

  1. As you write your psuedocode you can visualise the work ahead of you, and the code will already be written in your head by the time you start proper.
  2. Making changes at this stage is trivial.
  3. It is NOT a waste of time, the comments remain in your code.
  4. Something else that I've forgotten... err... damn brain.

Does anyone else work in a similar manner? I'd love to hear some tips and tricks in this area! Now to write my sites-manager...

Prev « How to write a blog post in a jiffy Next » designer tricks - test many fonts on your site