Skip to main content

Software Engineering Tips & Tricks

information that may be helpful when working with Parsons or other progressive tools

Published onJul 28, 2022
Software Engineering Tips & Tricks
·

Using the Command Line

Command line interfaces let you do a lot of different things on your computer, including installing and running programs and navigating the directory structure of your computer.

On Macs/Linux the default command line interface is called a Terminal and on Windows it is called the Command Prompt. Command line interfaces are also sometimes called shells. Look for this program on your computer and open it up.

The commands you can use in the command line differ somewhat dependning on whether you’re using Mac/Linux or windows.

Mac/Linux:

  • You can use pwd (“print working directory”) to figure out where you currently are.

  • To move around, use cd (for example cd .. means “go up one directory” or cd my_folder which means “go into my_folder”).

  • Use ls to list all the files and folders in your current directory.

  • Mac/Linux command line cheat sheet can help you keep track of which commands are which.

Windows:

  • You can use cd to figure out where you currently are.

  • To move around, use cd (for example cd .. means “go up one directory” or cd my_folder which means “go into my_folder”).

  • Use dir to list all the files and folders in a directory.

  • Windows command line cheat sheet can help you keep track of which commands are which.

You do not have to type everything on the command line out by hand. You can auto-complete the names of files/folders in your current directory by tapping the tab key. On Mac/Linux you can also tab-complete installed programs. And you can access previous commands via the up and down arrows. Save your hands! Learn these tricks.

Distinguishing Between the Command Line and the Python Interpreter

If you’re programming with Python, you may find yourself wanting to use the Python interpreter. The Python interpreter lets you test out Python code directly. You can access it by typing python into the command line.

(Note: you may find yourself accidentally in the Python interpreter if you start trying to run a Python file with, say, python file.py and forget to put the file name!)

This image shows me opening the Python interpreter from the command line of a shell in Linux. (The Linux shell should look familiar to Mac users but might look a little off to Window users.)

The following steps are shown above:

  • On the command line, we write text using echo.

  • Then, we open the Python interpreter using python. We get a bit of information about the Python interpreter when we do this, like our version number.

  • In the interpreter, we write text using print. Python’s print and the shell’s echo are kind of equivalent.

  • We leave the Python interpreter and go back to the command line using quit().

Note that the Python interpreter prompt typically ends with >>> while the command line/shell prompt typically ends with $.

Understanding Pip

Pip is the Python package manager. Packages (also commonly known as “libraries”) are Python code that have been bundled up in a certain way (“packaged”) so they can be easily installed and used.

By default, pip installs from the Python Package Index or PyPI, but you can tell pip to install from a branch on Github or even from a folder on your machine. All you need is a package with the right files. The specifics of those files, and how to create your own package, is a much more advanced topic.

Essentially when you type pip install parsons[all] (or pip install anything!) you’re saying “Go find this project on PyPI and install it.” (Here’s Parsons on PyPI!)

PATHs vs paths

Paths are how we refer to a file or program’s location in the file system. For example, /home/janedoe/virtualenvs says that within the top-level directory home there is a directory named janedoe, and within janedoe there is a directory virtualenvs.

/home/janedoe/virtualenvs is an absolute path because it specifies exactly how to get there no matter where you are in the system. The path janedoe/virtualenvs is a relative path because it only works if you use it from the home directory. Trying to use a relative path from the wrong location is a common source of command line errors!

On Windows, absolute paths look a little different. They start with the letter of the hard drive they’re in, ie C:\Users\JaneDoe\Virtualenvs.

In these instructions we try to use absolute paths, even though they’re a little wordier, because it’s less likely to cause problems for you if you run them from an unexpected place.

In addition to paths, there’s an important environmental variable called $PATH. The $PATH is a list of absolute paths your computer will check when searching for installed libraries and scripts. You can check what’s currently in your $PATH by typing echo $PATH (Mac/Linux) or echo %PATH% (Windows).

When you activate your virtual environment, the path to the environment is placed as the first path. Paths are checked in order from first to last. You can check what packages have been installed in your virtualenv (and thus should be available on the path when the virtualenv is activated) by looking in lib/site-packages.

If you’re trying to run something you’ve installed, but your computer says it doesn’t exist, it may be because the computer doesn’t have the right information in its $PATH. This happens to me all the time when I forget to activate my virtual environment!

Software Versioning and Releases

Modern software is constantly changing and being updated. Periodically, project maintainers will make new versions of the software available to users. This is called making a “release”.

Releases are great, because they give you new functionality and fix old bugs, but they can also accidentally introduce new bugs. Even when they don’t introduce new bugs, they can introduce “breaking changes”. When they do, you may have to update the code which relies on them to fit the new changes. Because of this, bigger projects often pick specific releases that they provide long term support to.

Let’s use Python as an example. Python has one of the biggest user communities on the planet, and projects and libraries in the community (like Parsons!) will tend to build around those releases with long term support. So, when you’re picking a Python version to install, you’ll want to pick a supported version.

So how do you do that? Check out the downloads page on python.org, which has the list of releases at the top. Here’s what it looks like as of August 2022:

The most recent release of Python is 3.10, but it’s still in “bugfix” mode. That means developers are still fixing bugs in that release. Python 3.9, on the other hand, is in “security” mode, which means they’re only changing it to fix new security vulnerabilities they’ve discovered. Because of this, I would recommend choosing version 3.9, not 3.10.

Note also the columns that says “End of support”. As of August 2022, there are a little more than three years of support left for 3.9. This means that if you pick 3.9 you probably won’t need to update against for three years or so.

Comments
0
comment
No comments here
Why not start the discussion?