Here it is.

Coding, Humans and where it all goes wrong.

Disable jQuery autocompleter cache

For anyone wondering how to disable the autocompleter cache in jQuery(meaning you always poll the server each time a letter is entered).

Simply set cacheLength: 0, in the autocompleter’s settings. Seems obvious but my googling told me never set this value below 1 or the whole thing would explode. Tried matchSubset etc and nothing else worked.

Simple solutions eh?

Php Beautifier

php code

Why?

When you’re faced with an ugly PHP file(or files) with little to do but trawl through it, there is a solution.

Php beautifier is a pear package that will process PHP files and reformat them in a (hopefully) nicer format.

Installation

You can install it using pear with a very simple

pear install PHP_Beautifier

Usage

Usage is pretty dependent on your needs. What’s nice is, it takes formatting rules as arguments, so if you pass in Pear() as an argument your code will be formatted to the pear standard.

Here’s a bash alias I used to fire an entire folder(and recursively through all sub-folders) through the beautifier with the Pear standard coding conventions and outputted to a src2 folder.

alias beautify="php_beautifier -l \"Pear()\" -r \"*.php\" ./src2/"

Or if your using vim here is a mapping to call the beautifier on the current file when Ctrl-F2 is pressed(all my function keys are currently mapped to vim’s xdebug plugin).

map <C-F2> :% ! php_beautifier<CR>

Results

The results are pretty nice actually. The author of it notes that on 40,000 lines of PHP it hasn’t broken a single file. I have noted that it can make certain files look like crap however. An example would be our locales file, that has large array mappings of terms to languages. Unless you’re totally certain your whole project is going to look awesome I would suggest using this on a file by file basis, as I have with vim.

The Pomodoro Technique

Pomdoro PicThe Pomodoro Technique promises to get things done.

I bought a book , basically because it was a GTD technique that came off the pragmatic bookshelf so I figured I’d give it a shot.

Explanation:
To give a very brief explanation of the technique.
You have a sheet with Today’s Todos, each time you do 25 minutes of work towards your todos you mark a ‘pomodoro’ and take a 5 minute break. You then clock up pomodoros everyday.

Then every morning you pick from your activity inventory(an unsorted list of todos), and pick the highest priority tasks, beside each task should be an estimate of how many pomodoros it should take. For example I had estimated 2 pomdoros for this blog post. So when selecting your pomodoros for the day you take your pomodoro average (sum of all the pomodoros you’ve ever done divided by the number of days), and don’t add more estimated pomodoros than your averages. So for example my average could be 11 and I could have 3 high priority tasks each estimated to take 5 pomodoros each, well clearly I would have to add 2 and find a third that only took 1 pomodoro.

Now clearly there’s more to it(they have managed to get several books out of it). What you log all metrics on is called a report sheet, so things I log are completed pomodoros, how far off my estimates were, how many tasks did I fail to do today etc.

How I used it

I fully commited to the technique both at home and at work. So in work I have a large diary and some extra sheets, for my ‘personal’ stuff I use a small moleskine diary to do the job. There have been dramatic results on both accounts. In work I noticed a better structure coming around my day. When people asked me for things I now always delay till I’ve finished my pomodoro(the book explains how to handle interruptions), then weight how important the new task was over what I’m currently working on. I also find myself looking back very satisfied with the work I’ve done for the day, a personal sense of accomplishment. On top of that I like the fact if anyone did ask ‘what did you do all last week?’, I could very easily give a breakdown on what tasks I was working on.

Like everything else discipline is key. I’ve even noticed myself slipping the odd time. Say I finish a task in 20 minutes, the technique calls for 25 minutes of focused work, so you should now focus on how you could do the task better or just improve on the task in some way. This is fine depending on some tasks but some just can’t be done any better. Going to the bathroom also becomes an interesting game as if you need to go to the bathroom you should cancel the pomodoro, very annoying when your bursting to go 22 minutes in. But you do begin to relish maintaining an average of sorts. It’s something you work towards and try increase.

It’s flexible!

Now however a problem has become apparent and this is where the flexibility of the technique comes in. As a programmer I noticed a ‘flow’ that stops as soon as the timer does(that’s the point), I’ve noticed 25 minutes is not nearly enough time so, as a compromise I can now alter how my pomodoro works. For this week I’m going to try 2*25 minute programming pomodoros followed by a ten minute break. I could increase the time of the pomodoro itself (say 25 to 50 minutes) but I’d rather keep it 25 (busy work such as replying to emails etc doesn’t take 50 minutes).

Kaizen

In essence the point of the technique is not the 25 minute burst is actually something called Kaizen, meaning make small improvements everyday. The constant reviewing of priorities and the daily review of work done is the real value in this technique. I find measuring metrics on your own productivity very powerful. If I find I’m doing more with 2*25 minute pomodoros, maybe I’ll try 4 and take a 20 minute break.

To be honest I’ve actually found more use for this technique at home than at work. With work there is structure to your day and deadlines looming that will always motivate you. At home that project or that programming language that you’ve wanted to do for months has no deadlines and just doesn’t magically get done. With my moleskine(and calendar reminders) I’ve got a constant motivator to get things done and do them better next time.

I can only recommend this technique for anyone. To get started all it takes is 3 sheets of paper(the activity inventory, the report sheet and today’s todos) and some willpower. The book itself is great and would highly recommend a purchase.

Resources

A decentĀ Online Cheatsheet.

A free book written by the inventor of pomodoro(not the prag prog one I’ve read)

A mindmap I’ve done.

This one may read very strangely and how I do the technique may not work for you, but the hats represent a different ‘focus’ and when my productivity starts to wane imagining the hats works well. I would suggest using the mindmap after reading the prag programmer book.

Enjoy!

Crayon Deluxe 1c or over till 15 of Jan

Crayon Physics Deluxe from Petri Purho on Vimeo.

Basically it’s pay what you want to get your hands on this innovative little game till Jan 15th. It’s a lot of fun for a short while. Though their servers are getting pretty hammered at the moment.

http://www.crayonphysics.com/

Vim!

vim-editor_logo

For a while now vim has been my editor of choice and only up until recently have I began to unearth it’s potential. My reasoning before was that it was so cross-compatible(even working in ssh terminals) that this would always be my go-to editor. Now it’s become so much more! Running regexes across all working files with bufdo, crazy window manipulation and crazy editing tricks have made this editor truly fantastic. I’ve started using wherever possible, even trying out the vimperator firefox plugin.

3 reasons to learn Vim are

  1. Edit text far more efficiently(I as a programmer do this more than a little)
  2. Not look like an idiot by saying you “know” vim then head straight for the arrow keys
  3. The ladies

I felt if I was ever going to learn it I would have to see someone use it. Luckily I found a guy who clearly only has love for VIM. Before I watched the videos I basically knew a couple of shortcuts but still used the arrows key and ‘i’ to do 95% of my work. Things have changed drastically since then.

So I would suggest:

  • Play with vim
  • Watch all of these vim tutorials, a guy who has likely changed me forever!
  • Feel free to use the mindmap I made, I find it easier to traverse quickly over the flat cheatsheet(but that’s just me)

You’ll find yourself working at a slow pace(even slower than normal) but fight through this as the productivity rewards are worth it!

Also it may be a little annoying but add these to your .vimrc to disable the arrow keys, this helped me a lot in using the editor correctly.

You’ll find yourself working at a slow pace(even slower than normal) but fight true this as the productivity rewards are worth it!
Also if may be a little annoying but add these to your .vimrc to disable the arrow keys, this helped me a lot in using the editor correctly.
noremap “”
noremap!
noremap “”
noremap!
noremap “”
noremap!
noremap “”
norema!

noremap “”

noremap!

noremap “”

noremap!

noremap “”

noremap!

noremap “”

norema!

Google Wave Server Admin

Download here.

What it does

Execute commands from google wave on your remote server.

How to set it up

Server End: Simply download and run the python server script, on the server obviously. Note: You need python2.6 or greater, which sucks for a lot of debian users but I need it to be able to kill processes nicely.

Wave End: You have 2 options

Easy option: Create a new wave and add waveserveradmin@appspot.com, then fill in the details required.

Hard option: Download the source from here. Deploy it to your own google app engine deployment and continue on the easy option.

How it works

Using google wave’s api and google’s datastore, when a blip is submitted anĀ xmlrpc request is sent to your server, along with your hashed password for authentication. The python code running on the server is then executed as a sub process and the output is returned. If the server subprocess lasts more than 3 seconds it is killed and that output is returned, I can’t seem to be able to wait any longer before the request times out.

As I mentioned the data is stored on google datastore. All passwords are hashed as soon as they’re entered.

If you need any further details, check the source.

Why

Generating ideas with what you can do with wave mostly. Obviously this script needs locking down to be useful, I’m doubting very many want to run ls -alh from google wave a lot. But if you start extending the code you can write some cool things into waves.

Example: On my server I use a tool called o2sms it allows me to send text messages from the command line for free using my mobile phone operator’s web-account(this tool only works in Ireland however). So for me to send a text message I would type. o2sms sender_in_phonebook -M ‘a message’

o2sms mum -M ‘Hi I am sending you a message’

So with a few changes to my script I can create a new wave add the robot participant and type

mum Hi I am sending you a message

And presto I’m sending texts from my google wave, for free.

Happys Days!

And I’m sure there is a truck load of ideas that can be done around this, the project itself is purely a proof of concept that I hope will generate some cool stuff.

Note:I did this project to learn both python and google wave’s api, so apologies if the code sucks/is very PHPish.

Pseudocode Programming Process

So for the last while I’ve been experimenting with PPP as described in Code Complete. Jeff Atwood has a great description of it on coding horror. You should read the blog post the metaphor of pseudocode as tang is a good one. I’ve been using PPP for a number of weeks now and so far it’s really been working. There have been several reasons why I found it works but for me the most important and useful part is purely that it slows me down.

One of Jeff’s arguments against PPP is that he ‘thinks in code’, and before I tried PPP I would have said the same. The problem is when I ‘think in code’, it sometimes results in poorly written code that clearly I haven’t spent nearly enough time thinking about. I’m moving straight into worrying about implementation details.

Now, because I’m abstracting the thinking away from the code it’s effectively created a new step in programming for me. Now Jeff is undoubtedly a better and more experienced programmer than I, so this is where he bases his argument, however we don’t all have this immediate ability to make the optimum choices as we start writing out code. When I say it slows me down, on a routine level, I start to think more about naming, is the function parameters in keeping with the abstraction of the overall class, the boundaries on parameters and other implementation details I may miss. And although most of those points are not at all related to what PPP wants me to think about it’s because I’m forcing myself to slow down I begin to become more thoughtful in the part where I fill out the tang. For now at least, I find it difficult to conceptualise all of this on top of worrying about all of the implementation details of the language. I really have shifted my thinking process to a new ‘thinking about thinking’ stage, that has significantly improved the quality of my code. I do sometimes feel like slipping into old habits, but I know the quality of my code will slip too so for the last while I’ve been good.

For example when I’ve had to really think about certain functions it may become obvious that it needs to be split, something I may not have noticed worrying about implementation details, or more likely I’ll noticed it needs to be split half-way through coding it. I also know there have been times when I ’should’ have split a routine but because I mid programming it I ‘leave it for now’. Never a good idea but when deadlines loom….. However when I’m writing pseudocode, if what I’m writing need some serious explaining, it become’s pretty obvious that I need to start a new routine. Typically this has resulted in small tight functions that truly adhere to the ‘do one thing well’ ideal. There are many other examples but it all boils down to a procedure that focuses my thoughts.

One tip I would suggest is to write your pseudocode for any language to implement, so I always re-read the pseudocode with an eye to writing it in a totally different language for me it’s C(I typically code in PHP). This ensures there’s no language details in there.

Another good way to think about it is a GTD to-do list. Basically, ‘a person needs to move tasks out of the mind by recording them externally. That way, the mind is freed from the job of remembering everything that needs to be done, and can concentrate on actually performing those tasks.’ I feel this step is becoming more and more vital for me and on top of that free well written comments are a terrific bonus for the lazy programmer!

Code Complete

Code Complete Front Page

I’ve been reading through Steve McConnell’s Code Complete for the last few months, in fact I’m working through mindmaps of each section to traverse through this dense book in a fairly easy manner. Basically, instead of saying “Hey I need to create a new class what should I be thinking about again, which pages are they on?”, I search the appropriate mindmap and all the headings are there, with page number for a deeper reference(which is rarely needed). I would highly recommend this system to anyone who wants to read any book and also use it for a future reference.

Since I began my current software engineering job, my code quality has improved significantly purely because of this book(I have little technical expertise to rely on, low availability of experienced programmers has effectively forced me to punch about my own experience weight). For me the real impact of this book has been having my own expert to back my decisions, instead of my typical response of ‘Eh, I like doing it that way’, it’s moved to ‘Steve McConnell a widely regarded software engineer in a book that epitomises software engineering tells me to do it this way’.

It’s basically a handbook on how to be a software engineer, so for me truly at the start of this process, this book has been invaluable. It’s forced me to start thinking about things I would have never bothered putting thought into. An example would be variable names, which before I put barely any thought into(I know what it does…..) I’ve now got a large section of my mindmap dedicated to picking a decent name, in a consistent way. Another example would be creating a class. Before, I would ponder whether it ‘feels’ right to do so, then probably do it anyway. Now, I have a checklist to say whether making this section of code and variable does justify a class. I find myself thinking more about thinking. The most important part being I’m making decisions in a consistent manner and as I’ve put a lot more thought into them I tend to remember and repeat those decisions. Honestly I’ve already refactored a bunch of code as I realised just how unpleasant it was in the scheme of things.

I’d say at this stage I’m hitting Code Complete more than the php.net manual, which is a big feat(considering how often I forget how to do things). Honestly I have no idea if this would have any impact on an experienced programmer, I would hazard a guess that most large ongoing projects incorporate a look of the ideas this book puts forward. But as a beginner it’s influence on me has been more then significant and I’ve already started to look at other inexperienced programmers who haven’t read this book with slightly less confidence. The book is in itself probably the most important book the programmer in me will ever read and is the first book I would recommend to any developer. Now I just have to finish it.

Oh there’s some awesome resources on Steve’s page Code Complete page.

Me

I’m Shane Dowling. I work as a Software Engineer and have done so for the last year. I graduated from Trinity College in Dublin, Ireland in 2008.

In 2008 I was handed the technical lead role of a web-based SAAS help-desk tool. As such it has forced me to move from a crappy out of college coder to a fully fledged software engineer at a pretty fast rate.

I don’t know if I’m experienced enough to say I’m reasonably experienced in anything software related, but if I am reasonably experienced in anything it’s web development.

Why blog?

Same as everyone else, mostly for selfish reasons. As I said, I’m progressing out of the “hack it till it works” mindset. I have no qualms about this, in fact in terms of time why would anyone write code any other way in college? College isn’t challenging you to write robust readable quality code(it’s likely no-one will read it), it challenges you in the tasks you undertake to solve with the code. So my current goal with this blog is to catalogue random insights into a range of topics around that subject. It may extend to other fields but this is the initial plan.

For my own sanity I will probably disable all hit counters etc. If no-one ever reads this, I’d be last that wants to know.