Python

Python

When I have some free time at work, I’ve been logging on to Codecademy and providing myself with some CPD[ref]Continuing Professional Development, in case you were wondering[/ref] by working through the tutorials on programming languages.

Now, I’m not a fantastic coder, not by a long shot, but I have created programs in all sorts of languages over the years – starting with Sinclair and BBC Basic, up through AMOS, a bit of C and C++, Perl, Pascal and most frequently, Visual Basic and PHP. I’ve dabbled with Processing (mainly for Arduino related stuff) and a bit of Javascript (primarily making use of jQuery). Through work I’ve used Scratch and similar “visual block” languages like the environment for coding Microbits.

I would say that even if I can’t code in a particular language, I can usually understand something written in one: After all, most modern programming languages are very similar, easily readable and differ mainly in just syntax and convention.

pythoncompleteSince Python seems to be the language of choice these days for people learning to program, I decided to pursue the Python course on Codacademy, and in the last week finished it up. I have used Python before, mainly for writing stuff on the Raspberry Pi, but I’d not actually learned it.

I have a few thoughts on the language itself. Perhaps unsurprisingly, it’s very much like PHP so once I’d learned the different conventions it was quite quick to become fluent in the basics. One thing that I found difficult, and unusual for languages I’ve used before, is indentation.

Good Programming Practice dictates that as well as annotating your code (haha! We all do that, right?) you make use of whitespace and indentation to make your code readable. When you have a subroutine, function, loop, or whatever, you indent the code within it. As an example (in no specific language):

function double(number) {
   number = number + number
   return number
   }

This is especially useful if you have nested elements:

function factorial(number) {
   total = 1
   for count = 1 to number {
      total = total * count
      }
   return total
   }

Of course, I try to stick to this but inevitably while editing, re-editing, moving and reusing code things often end up with the wrong levels of indentation. I recently changed the template for part of my website (news on that in another post, hopefully) and the mess of divs in the HTML almost drove me to kill a kitten. Horrible.

Anyway, my point is that we coders[ref]Ha! Hark at me calling myself a coder.[/ref] aspire to have neat and tidy code. Python, however, enforces it: Loops and so on come to an end not with a closing keyword or brace of some sort, rather they come to an end when you stop indenting them. That was a struggle, especially so when debugging. Have I used the wrong code, or have I forgotten to press tab? Error messages in Python are helpfully quite verbose and direct, thankfully, but it was still a hurdle. I suppose that’s the point though, forcing you into good practice rather than just expecting it.

The Codacademy course itself was pretty good. I did find that some sections overlapped with others, sometimes not exactly contradicting each other but using slightly different (but equally valid) convention, presumably due to a range of people writing each section. A couple of exercises had horrible bugs in them which caused problems. One of them required you to read and print three lines from a file, but even if your code was 100% correct, it would fail unless (as I found from the help forum) you edited the file you’re supposed to read from first.

Minor quibbles like that aside, I enjoyed the course and learned a lot. In particular, I finally got my head around objects, which I’ve struggled with several times in the past. Codacademy itself is also great, and I’m now going to go back and finish my unfinished Javascript course and then move onto something else. SQL maybe?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.