Top five things to improve your coding (in no particular order):
Version control isn’t coding as such, but it is pretty much an essential skill once you move past the beginner stage for a few very good reasons:
1. Writing code is never a one time job. There’s always updates, adding features, fixing bugs. You need some way to track the changes to your code so you know what version of the code you are running. Using multiple folders with version labels quickly becomes totally unmanageble in my experience! There are tools built to do this job for you – so why not use them?
2. If you work in any way with others you’re going to need to share your code, and for the vast majority of projects that means sharing a version controlled code repository.
3. I’ve found even for simple personal projects using a Raspberry Pi, it’s much quicker for me to write the project on my laptop, put it in a online code repository, and then download the project from the repository on the Pi. It’s actually more convenient than copying the files across when you are doing a headless project.
The most popular distributed version control software at the moment is Git, and github and bitbucket are two online services which allow you to push your code repository from your local machine into the cloud. If you’ve read my other posts you’ll see I use github to share my code – but these online service are not the software itself, but the code repositories. You can even host your own if you like. There are other version control systems but the only other one I’ve come across a need to use is SVN for the WordPress repository – which was easy to pick up as it is quite similar to git.
In my experience being able to use git has helped me to maintain and organise my code in a much better manner – and you can also roll back code to any stage you commit (that’s like saving a checkpoint). It’s been essential for the projects I’ve done for clients where I had to collaborate with them in writing projects. Having said that, I found it had a steep learning curve. Git is not at all intuitive and requires some effort in understanding the difference between local repos and remote repos, what a branch is, how to make a commit and how to use branches and pull requests when collaborating with others. There’s quite a few steps to learn, and I still keep coming back to my git crib sheet any time I want to do something out of the ordinary. It is totally worth the effort of learning though – the pay off later is huge. I started off reading the documentation on bitbucket which confused me even more, until I found codecademy’s online tutorial for git. That was good to get some real practice using it and got me up to speed. Another good resource is the ‘Using Git’ tutorial series in MagPi issues 27 to 29. I now use Git for all my projects and so I’ve had lots of practice on making commits and pushing to github, so those things feel quite familiar now.
That concludes my five part series on improving your coding when moving on from the beginner stage. I’ve been through all these steps and I think they are the most relevant in my journey from playing with Python for fun on the Raspberry Pi through to getting my first clients as a freelance developer.