Sunday, 6 March 2016

Learning multiple programming languages

Our (or rather, my personal) recent rant about Arduino attracted a few comments - some people mistaking our lack of enthusiasm for the Arduino platform as another PIC vs AVR argument (an argument with less going for it since Microchip acquired AVR). The problem with Arduino is not the AVR hardware (although it still isn't as robust as PIC) but the actual language. Sometimes it compiles incorrectly. Or maybe its programmers (probably me included) not using the language correctly. Or not understanding how the language works.

My personal biggest gripe with Arduino is the reliance (and encouragement for developers to become reliant) on libraries - many of which are of variable quality; code submitted by programmers who have learned another programming language, rather than understood the device that they're writing code for.

There's a world of difference between learning a programming language and learning how to code. It's a question often seen on the interwebs - "which language should I learn". Then there's a 500-comment discussion about why one language is superior to another.

Having recently got to grips with a Raspberry Pi after it sitting in a box a few years, and wanting to use simple face recognition in an art installation project, it's time for us to learn (yet) another language, Python.

Python is weird.

It's a weird language.
It uses white space and indenting as part of the language structure. It's horrible to work with. But it's just another language. The fact that you indent and "outdent" instead of using opening and closing squirly brackets doesn't mean it's unworkable (it just means it's horrible to use!)

But that's only because most of the nerds at nerd club are used to working in languages that look different. Our criticism of Python is not really that different to some of the criticism we've attracted on this blog for posting PIC source code in BASIC. Hey, Basic's not C. We get it. It doesn't use exactly the same words as C, so you can't just copy and paste the code into your favourite C compiler, or put it into an Arduino IDE and expect it to work.

And Python's a bit like that.
I can't just use phrases like s = string.substr(2,4)
But that doesn't mean Python can't split strings.
To do that in Python, you use s = string[2:6]

There you go, same result, just different words to achieve it. And that's what makes a question like "which language should I learn" pretty meaningless. Especially now we've all got access to the interweb and Wikipedia at our fingertips. You don't need to know the exact syntax of a programming language to use it effectively. But you do need how to code to get the most out of it.

I probably know a dozen programming languages or more.
Some, I'm pretty proficient in. Some, I need to Google almost every other keyword. But that hasn't stopped me putting together a fairly comprehensive Python script in just a couple of hours, that can capture photos from a camera, parse them looking for faces, while responding to commands sent over the serial port, to adjust the brightness/contrast/shutter speed and so on.

It's not because I learned Python.
It's because I know how to code.

And that's a very different thing altogether.
So don't worry about which language you're working in. To get better, just code more. Code lots. And lots and lots. And sometimes you can have a go at recreating one project in another language. In fact, that's probably a great idea. Just for a laugh. So when you've done something, you can feel confident porting it to another language, even if the language is not that familiar to you. That way you know you understand what's going on, rather than blindly copying words off a website to achieve a result.

I started out writing simple programs in BASIC on a VIC 20 as a small child in the mid 80s. Then I moved onto a ZX Spectrum. It was very similar but not quite the same. Then, many years later, when I finally got my hands on a PC, full-colour graphics using QBasic. Some time after that, I was getting paid to program PLCs using ladder logic. And PCs in Visual Basic 3 (long before .vbx eventually became Activex). That lead to coding in C, and later C++.

I've written games for the Gameboy in C and assembly and interfaced with banking databases in Cobol. I loved working in VB and ASP, but slowly had to give way to jquery, javascript and php. I've built entire engineering projects in BASIC on a variety of PIC microcontrollers, and rapid-prototyped designs in C++ in Arduino. I've built apps in java, J2ME, Objective-C and Actionscript. I loved using Flash's Actionscript to write simple online games and adding interactivity to websites, but have now moved over to C# on Unity (at least for games and app development).

Languages are not important.
It's what you're trying to say that matters.

All too often we train students (our next generation of engineers) to learn which words to use (and which keyphrases to find using Google) instead of how to actually write code - how to understand a problem, break it down, and solve each little step along the way.

But it's not always down to the failings of a tutor: too often people expect a complete copy-and-paste-friendly answer, instead of learning how to understand what it is they are trying to achieve. Rather than understand how to solve a problem, most people seem happy with "how do I make this problem go away".

One language is never really "better" than another. It's just something you get comfortable with. English, as a language, has a massive selection of words; it has subtly and nuance not available with other languages. In french, I can ask my neighbours a question, and I'm always "demanding" - je demande. In English, I can ask, I can inquire, I can probe or query. But french also has words that we don't have and since hijacked - for example, there's no real English word for the spooky feeling so beautifully described as deja vu.

If you grew up speaking French, you don't miss the words that have been taken away (the french language is regularly "cleansed" by removing duplicates and tautology - and a lot of anglicisms!). English, by comparison, is a jumbled mess of unnnecessary words, rules and complexities. Which is "best"? Neither. Which are you more comfortable with? Probably the one you grew up learning.

Same goes with programming.
Don't waste time learning a language.
Learn how to code.
Learn how to understand and how to code well.
And the entire world could be better off for it ;-)


No comments:

Post a Comment