← Thomas Lackemann

Creating Efficient Development Environments

Posted on Jun 11, 2016 in

Not all applications are created equal. Some require special attention when setting up, some may not work properly unless they are running on the right infrastructure. In either situation, chances are there is sufficient documentation surrounding the pitfalls of the application so that any developer can get up and running in a sane way. This process is both tedious and time-consuming for any team that looks to expand.

Over the years of encountering this problem, I’ve settled on my own standard that I’d like to share for when I decide to work on a legacy project or even start a new project. The concept is nothing new, but applying the rule to my projects I find to be insanely helpful over time.

Automate Everything

Let’s say you’re handed a Go/Node project that one of your co-workers wrote a year or two ago. To setup your development environment, let’s suppose you execute some commands such as:

# Clone the repo
$ git clone git@lacke.mn:test/test.git

# Install dependencies
$ cd test && npm install

# Start postgres
$ sudo systemctl start postgres

# Run the Go server
$ PGHOST=localhost PGUSER=test PGPASS=test PGDATABASE=test gin run main.go

# React frontend: bundle/watch
$ watchify src/index.js -o public/js/bundle.js -t [ babelify --presets [ es2015 react ] ] -v -d

# Launch a tmux (because real developers use tmux)
$ tmux

# Spin up vim (reasons above)
$ vim

The above workflow is almost exactly how I start working on one of my side-projects; however, instead of starting Postgres and running the Go server each time we want to work on this project, we can simply automate the entire process. Here’s how.

Utilize Scripts

Any command you execute with environment variables or flags should be written and executed in a script.

I think that’s worth repeating.

Any command you execute with environment variables or flags should be written and executed in a script.

Let’s take an example from our workflow above. In our project root folder, we’ll create the script ./bin/dev to run the Go server.

#!/bin/bash
PGHOST=localhost PGUSER=test PGPASS=test PGDATABASE=test gin run main.go

Now instead of writing out that command each time, we can simply execute ./bin/dev. Much simpler!

Automating Your IDE

Writing scripts for all of our commands definitely makes our lives easier, but we can do better. Can we get a full working application up and running AND start developing with a single command? You bet.

Let’s create another script called ./bin/ide in our project folder. This script will contain all the necessary commands to launch and develop our application.

#!/bin/sh

cd $GOPATH/src/github.com/tlackemann/test
tmux new-session -d 'vim'
tmux new-window -d './bin/dev'
tmux new-window -d 'npm install && ./bin/watch'
tmux new-window -d 'sudo systemctl start postgres && sudo -u postgres psql -d test'
tmux new-window -d
tmux -2 attach-session -d

This simple script will start a new tmux session and execute your application’s commands in separate panes. You can also choose to split-window if you’d rather do that (man tmux is super helpful.)

Best of all, the script drops you in a vim window, ready for development.

Conclusion

Scripting is a useful way to automate your development environments. Switching between projects written in PHP, Perl, Python, Go, etc. can all be uniquely different but the way you program for them can be simplified to just a ./bin/ide command to ensure you never forget how to run a development application again.

Try applying this to your current project and let me know how it works out!


Have you implemented a similar system for your projects? Let me know at tommylackemann [at] gmail [dot] com

About

Tom is the CEO (Customer Experience Overlord) of Unicorn Heart Club where he leads development for Astral Virtual TableTop. He's a homebrewer, hiker, and has an about page.

Read More

← Let's Write A Video Game: Introduction

Comments