Matt Thompson is a Solution Design Architect for brightsolid. In this post he shares his advice for IT professionals who’d like to learn to code. 

This is part 2 of a three part series. 

 

Editors

So you want to start following examples you’ve found online or in a book to learn more about your chosen language from part 1?. Which editors should you consider to start knocking up some super useful scripts? Part 2 looks at three broad categories, giving some suggestions along the way.

Keep it simple

Start with the tools built in to your OS. With Windows, that would be Notepad. With Linux, Vim. Vim comes with syntax highlighting so can make your scripts far more readable. Notepad on Windows is extremely basic and offers only the most basic features (cursor location, find/replace) and so is not really recommended. If you like Vim (yes, they do exist), then fair play. Otherwise, time to consider something with more power under the hood.

Text editor on steroids

There are loads of options to consider here. However, the theme of this series is ‘quick start’ so I’ll get straight down to two great options.

Notepad++ is my preferred Windows editor. It offers language syntax highlighting, tabbed windows, various encoding options and host of plugins that can make your life easier e.g. Compare, that lets you see different scripts side by side and highlights any differences.

Sublime Text is another superb editor that I’ve played with and am considering making the switch to. It’s cross platform (Windows, Linux, Mac), has an API and works well with larger projects where you will have multiple files all related to each other.

Want more?

If the two editors in the previous section leave you wanting more, then firstly good for you! Beyond, you have the option of an IDE, or Integrated Development Environment. In addition to the tools mentioned above, you get additional tools such as debuggers, version control tools (e.g. working directly with Git, SVN, Github), syntax checking and completion (in addition to just highlighting). Once you start getting in to more complex projects beyond single file scripts, you will find an IDE invaluable for managing your workflow.

The best example for Python I can recommend is Pycharm from Jet Brains. There is a commercial professional edition but also two free editions, community and education. I’ve used both and, having gone through all of the lessons included in the educational version, prefer to use the community edition.

Don’t get bogged down…

Having an editing tool you feel comfortable with to create and tweak your scripts and larger projects is very important but don’t get bogged down in the wide array of choices. Work your way ‘up’ the options above until you get something that meets your needs.

Tools

Now, we look at some additional tools that you might find useful to round out your coding experience.

Build a platform

There is nothing to stop you installing Python on your Windows machine and start coding immediately. However, to keep things clean, I tend to set up a virtual environment to play around with. You basically have two options here, which can be combined for further flexibility.

  1. Run code in a VM. Install VMware Player/Workstation or VirtualBox, get a Ubuntu server ISO downloaded and create a VM you can play about with. Unbuntu also comes with Python pre-installed
  2. Run code in a virtual environment. Pyvenv and Virtualenv are tools that allow you to create virtual Python environments, different from your core installation. You can install additional modules, discussed below, without interfering with your core installation. Once you have finished, simply delete the directory and its done, meaning you can always build a fresh environment very quickly. Very useful for trying out new modules and projects multiple times without having to build a new VM to clean things up

You can of course do both of the above i.e. run virtual environments within your VM. As an extension of option two, there are tools out there that allow you to install a core installation of Python and from there you can install virtual environments not just for modules but also for different versions of Python. An example of this is Anaconda. The main advantage of this for me is that, despite me working predominantly with Python3, I can create a Python2 environment and test code I find online to my hearts content straight away, rather than having to change the code to Python3 before I can start testing it.

I have Anaconda installed on my Windows machine and have various Linux VMs with both virtual and core only installations to play about with. Give them a try and see what works for you. They are all surprisingly easy to get up and running.

Extending the core functionality

Modules are a great way or extending the functionality of your chosen language (note different languages may call them something different, but it applies to both PowerShell and Python). Eventually, you might even get around to writing your own so you can create functionality that you can copy and paste in different scenarios. This is one of the key benefits of coding i.e. not reinventing the wheel each time you tackle a problem.

An example would be how to use Python to interact with a web server. Perhaps the most popular way of doing this is using a module called Requests. This very useful module abstracts a lot of the under the hood code and provides an easy to use interface to build request types, add authentication and headers without pain and work with returned results. There are many modules that come with the Python standard library and 100s of 1000s more available online.

Google

When you are wondering ‘how do I achieve x using y?’, Google will often have a good answer because chances are, somebody else has already thought about it. For example, if you end up trying to write a script that interacts with an API, you might run in to a problem that your script is not being too helpful about. Postman (plugin, requires Chrome) to the rescue. It allows you to test API functionality in a more user friendly GUI and quickly change parameters. It’s saved me a couple of times, without me having to butcher my script on the fly and I can see what I’ve done wrong then apply the required changes to my script.

Also, Google doesn’t judge so ask as stupid a question as you want. Chances are somebody has actually had the cheek to ask this on a forum such as StackExchange without having done any real investigation themselves. Try not to be that person though. Do your own exploring before asking for ‘live’ help, because people are much more inclined to help those who can demonstrate that they have tried to help themselves first.

Summary

This has hopefully opened your eyes to the fact that there are lots of tools available to you to make your coding journey easier and more enjoyable. The above list doesn’t even begin to scratch the surface but should give you a poke in right direction.

In the next post, we discuss version control and in particular Github to help make your coding more collaborative and to keep track of your growing collection of scripts.

Till the next time.

If you’d like to read more articles from Matt, check out his blog.