Learn to Code

Learn to Code
Code for a Recent Project
"I hate doing things twice!"

I was in Okinawa, Japan on a US military installation. At the time I was a software instructor, and I was watching another contractor doing some maintenance on one of the computers literally writing a batch script faster than I could type. It looked similar to the text flowing up the screen on The Matrix. I was amazed. When I asked who taught him, how he learned to do that, without even so much as pausing or looking away from the screen, his response was, "I hate doing things twice!"

Don't Do It Twice - Script It

It was not until that night at dinner when I pressed him for a more thorough explanation that I got the full story. Admittedly, I already had a pretty good idea, but I wanted the full story. It turns out, there was not much to it.

The statement, "I hate doing things twice," really summed it up. He was an Army veteran, and while in the Army, there was a huge amount of redundant and exceedingly boring things he had to do on the computers he was responsible for. He just decided if anything had to be done twice, he was going to figure out how to script it. Since all these computers were Windows machines, batch scripting made sense. It was available on all the machines no matter what with no special requirements. So, for anything he had to do more than once, he figured out how to write a batch script to do the task.

Applying the Mantra

As an instructor with Esri, I had plenty of redundant tasks. For instance, every few days I taught a new class and had to copy all the class data into a new directory for demonstrations. Typically I also grabbed a few datasets I personally liked for demonstrations, and copied these into this working directory as well.

Since Python is the scripting language for ArcGIS Desktop (ArcMap and ArcCatalog at the time and now ArcGIS Pro), I started by learning how to write Python. Following the advice of simply figuring out how to script anything I had to do twice - stubbornly refusing to do things twice, this is how I got started learning how to write Python. I was willing to work hard to be lazy, at least this is how I describe it.

During this initial learning curve, there was vastly more inefficiency than efficiency gained. It did not help I did not have a mentor, somebody to ask for advice and assistance when I got stuck. It took about a year, but there was a definite turning point I still recall when, at least for simple tasks, I could fairly quickly toss together a script to take care of automating tasks. Granted, I was not writing scripts every day. Following the mantra of not doing things twice, scripting is something I tackled in between teaching classes when I needed to automate a task so I did not have to do it a second time.

The Language of Computers

Learning to write, understand and debug code, is learning a language. I speak American English and Python fluently. I arguably speak two primary dialects of Python, ArcPy, and Pandas. Similar to a spoken language, while I can understand what somebody from Ireland is saying, there are definite differences and even times when I have to ask for clarification. Especially with Python, such a staggeringly versatile language, there is an astounding variety of uses, and each has nuanced differences. Typically these differences can easily be figured out, but they are not always apparent at first glance.

ArcPy is how Python is used directly in conjunction with ArcGIS Pro, and Pandas is the set of tools most commonly used for data science. I describe it as Excel for Python. It is for working with tabular data, data in tables comprised of columns and rows, except it is much more versatile than Excel.

Python is among the easiest and most versatile languages to learn. It is designed for readability and ease of use. Python, as I also alluded to earlier, is used for just about anything you can conceive. This means the solution to what you are trying to do very frequently is little more than a web search away, and more often than not, there is an installable package to make the task even easier. Consequently, I frequently recommend Python as a very good place to start.

There is always disagreement over which language to learn first. My advice is not to worry about it. Just learn one. Teach your brain to learn how to read and debug code. You can transfer to another language fairly easily. It is not altogether different than jumping between Portuguese and Spanish.

The important thing, though, is to start. Start with whatever works for you, and never do a task twice that can be scripted. Make the computer do the boring stuff!