Why learn Python over JavaScript

Python logo

TL;DR: We’ll learn why Python makes us happy, and why JavaScript makes us cry.

In the geospatial community, there’s a big push to learn coding.¬† With a little programming skill, you can collect data, transform it, analyze it, and publish the results. Popular GIS software platforms make it easy to run scripts and publish webpages with interactive maps. And if you listen when money talks, it says GIS Developers make twice as much as GIS Technicians in the United States, according to Glassdoor.com.

Many aspiring coders in the GIS community are asking what programming language they should learn first. They’re not asking me, probably because I don’t network enough or something, but that’s another story. Most of the general “top 5” first programming language blog posts I read list both Python and JavaScript. Both are widely used in the geospatial professions. But which one should a GIS person learn first?

Why Python

Many people know me as a GIS Web Developer, so they would be shocked if I didn’t pick JavaScript for a first language. Not this time, however. I like JavaScript for a lot of things, but a beginner language isn’t one of them. There’s too much… well, you’ll see. Here’s my top five reasons why a GIS person should pick Python over JavaScript as their first language.

It’s So Easy

People who pick up Python find it a breeze to write simple programs. It takes away the structural pickiness and visual clutter of semicolons and brackets found in many languages. Instead, it focuses on simplicity, controlling flow through indentations to define the path of functions and operations. Python makes it easy to write something practical. I think this XKCD comic describes it best.

On the other hand, JavaScript is a language Python tries hard not to be. As the story goes, it was written in about a month by Brandon Eich. Since then, JavaScript is patched every few years with new and exciting features that will never be adopted by your grandmother’s PC without you going to visit. Spacing doesn’t matter, but it’s super picky about semicolons and brackets. Plus It can be frustrating to write, debug, and support.

IDEs and Typos

In Python, you have trusted places to write code, known as IDE (short for Integrated Development Environment). Python developers would recognize them by the names of IDLE, PythonWin, or maybe the Python command line in ArcCatalog. These tools know you’re writing Python, and help you while you write your code. Intellisense let you type out a few letters, and the IDE suggests what you might want to type. This cuts down on a lot of the errors caused by typos.

JavaScript, on the other hand, is notoriously prone to typo errors. On many servers, your best IDE may be Notepad (or Notepad++ if you wash the car, walk the dog, and offer enough donuts to the server guy). JavaScript lets you hack object properties in on the fly, call them almost anything you want and doesn’t warn you until it’s too late. Unless you special flags like “use strict”; in your code, you can assign unknown variable aA something you meant to assign to variable aa. You can also change variable types on a whim, which can be very dangerous.

Version support

In the wild, there are two major versions of Python: 2.x and 3.x. Technically, there 32bit and 64bit versions as well. So there are at most four versions of Python out there you may have to support. And the biggest difference between 2.x and 3.x? Putting parentheses around the stuff you want to print(). But typically, you know the Python version you’re writing code for.

The latest version of JavaScript, on the other hand, is already at EcmaScript version 6; far more than Python. It would be easier if it were just 6, though. It turns out, each EcmaScript version is a recommendation, and the browsers that run JavaScript can implement them whenever they get around to it. That means, you have to account for multiple browsers, which may or may not support parts the code you’re writing. And depending on the browser and when it was last patched or upgraded, your code may fail in any number of places.

Number of languages you need to know

Python programmers can go all day writing nothing but Python. Oh, they might generate a little HTML, a SQL syntax string, or write a little RexExp statement, but then they go back to writing Python.

To program well in JavaScript, however, you need to know three or more languages (JavaScript, HTML, CSS, and whatever optional server side code your server lets¬† you use). These different languages increase the difficulty of troubleshooting problems. Is JavaScript really to blame when I can’t get the text from a textbox, or is it because I misspelled the tag id in the HTML or covered it with a picture in the CSS? And if it’s not enough, there are many libraries and frameworks that augment JavaScript. It’s like learning new dialects on top of the existing language.

Asynchronicity

Python is a very procedural language. You start from the top and work your way down. The logic flow is very predictable, and can be traced out on paper for small projects. It’s like a guided tour through a museum. You always know you’re going to walk by the neanderthals hunting the mastodon before you get to the Spanish Conquistadors.

JavaScript, on the other hand, thrives on its asynchronicity. While it is a scripting language, flowing from top to bottom, it can assign event handlers to DOM objects that get triggered, say, when a user clicks a button, or when a section finishes loading. JavaScript is more like a carnival than a museum. Kids are running around everywhere, running to the Ferris wheel or the crazy spinning rides in no particular order. This lack of predictability is hard for a new programmer.

Conclusion

If you’re new to the geospatial industry, or you’ve been in for a long time, and you feel the pressure to learn to program, maybe Python should be the language you start with. The reasons above only scratch the surface of how useful Python is. I didn’t even cover all the useful libraries that are built to extend the language.

Next week, we’ll learn why all these points are useless, and you should learn JavaScript over Python, first.

2 Responses to “Why learn Python over JavaScript

  • Hey Ken, Are you saying you can create websites using Python alone and some HTML? How does Python handle styling?

  • Hey Tony,
    With Python, you can do anything from hosting a simple HTML server, to using a python web framework like Django or Flask. Django’s an established CMS, while I’ve been hearing a lot lately about Flask being a lighter weight, but powerful alternative. They work great if you have other python tools and connections to your data.
    As for HTML styling, you would still use CSS for styles and JavaScript for user controls, animations, and other libraries. Python would be more of a server-side language, like ASP.Net, PHP, or Ruby on Rails.

Leave a Reply

Your email address will not be published.