Software Development

From The Thinkulum
Revision as of 05:56, 20 March 2017 by Andy Culbertson (talk | contribs) (Added the article.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

For most of my coding life, I have been the only user of my programs. I wrote them to aid my work or personal life, and only rarely did anyone else even see my code or watch it run. This wasn't on purpose. It just turned out that way. In my current job I do belong to a small development team, but our programs are still only for in-house use, so the only needs we have to consider are our own.

This situation is starting to change. My programming projects are becoming more relevant to the outside world, and I want to share some of them as open source. This means I'm needing to reshape some of my programming practices and learn some areas of software development I've had the luxury of ignoring all these years.

I haven't completely ignored these areas, though. I pick up on them here and there as I read about how other people code or see them in the software I use. Knowing that I'll probably need to know about them someday, I've kept a list. And now the time has come for me to fill in the details.

I'm filling in the details here in this guide for two reasons. First, as I learn, writing helps me clarify my thoughts and keep them flowing. And second, posting my writing might help other people. So if you're like me and you've programmed mainly for yourself--what I call private coding--and you're starting to share your work with others--public coding--then maybe what I've learned so far can grease some of your own planning.

This project consists of my reading other developers' advice, examining their code, deciding what to adopt and how to adapt it to my needs and preferences, and creating templates, procedures, reference materials, and anything else that might help me code well for a public user base.

To give you an idea of my background, I've worked for the past 15 or so years in the publishing industry doing mostly text processing and some web development. The languages I'm most familiar with are Perl, Python, XSLT, and some JavaScript, with a smattering of PHP and VBA. I've spent almost all my time in Windows. I hope to branch out into at least Linux in the future, if only to expand my mind.

This guide will be oriented toward Python for now, but I imagine a lot of its suggestions apply to other languages too.

Since this guide is a place for me to learn, I welcome feedback, and I'm always open to arguments that my choices could be improved or suggestions for things I've missed.

This is an early iteration of the guide, so it's incomplete, and a lot of it is only sketched out.

General coding guides

These are resources with advice on many aspects of writing good code. The ones I haven't read are on my to-read list. I'll probably be adding others.

Another resource that overlaps with this guide but covers more on the project management end of OSS is Producing Open Source Software.

Code examples

To show how I'm implementing these ideas in my own code, I'll refer to my GitHub repositories throughout the guide, mainly my Code Console project, which lets me create and manage projects using templates.

Here are projects that show up in lists of high quality code, so I'll examine some of them and include any relevant discoveries in the guide. All the projects I'm listing for now are in Python.

In addition to these, I keep a mental list of software with features I might want to emulate, even if I don't plan to study their code very thoroughly:

  • Firefox - automatic updating; possibly its add-on architecture, if it ever settles down
  • WordPress - plugin hooks

Software development methodology

I'll start with some general principles that direct my thinking about software development in general. These are the ideas behind agile development practices. Agile software development is a paradigm that was created to answer waterfall development, the approach of planning all the features of a piece of software in advance, an effort that often ends up wasted because the customer's needs change in the middle of the project, so the software has to be redesigned.

So agile development was intended to prevent overplanning. But using any development methodology will help prevent the opposite problem, which is a complete lack of structure and discipline. This results in a code organization scheme called a big ball of mud. I don't think my programs were complete mud, but the fact that I was the only one seeing or using my code let me get by with a lot of slacking. Slacking does keep you from working too hard, but it fails to prevent other kinds of problems. Agile software development seems like a good middle ground.

Agile development encompasses a lot of principles and practices, and it has a lot of varieties, but for me at this point, its most important practices are incremental development, test-driven development, and refactoring.

Incremental development

Incremental development is the approach of adding a few features per release rather than developing the whole program at once. It lets users begin using the software earlier, and it lets the feature roadmap change without wasting much development effort on the original design. It's different from iterative development, but they normally go together, so I'm use incremental as shorthand for both.

If you're a developer working on your own, the habit of small, frequent releases also can add accountability to the development process. It'll at least hold you accountable to work on the project, since other people will notice when the releases stop coming. It might even encourage you to code each feature well. A short release cycle does mean there's less time to get the code right, but there's also less time to procrastinate on getting it to work, and if you implement good programming practices, you'll waste less of that time debugging.

Small, frequent releases can also help the developer avoid procrastination, since the tasks for a small release feel more achievable, similar to writing a zeroth draft of a manuscript. There's little concern for polish, so a zeroth draft has fewer requirements to worry about, and therefore it's more likely to get written.

A related practice is to deliberately trim your feature list for each release, captured in the Extreme Programming practice You Aren't Gonna Need It.

One practice that's helping me think in terms of incremental development is using GitHub flow as my version control workflow. In GitHub flow the master branch is reserved for deployable code, so anything I'm actively developing goes into a topically named branch off of master. Once the code related to that branch is ready for deployment, I merge that branch back into master. This procedure gets me to plan in terms of small clusters of features. I'll talk more about version control in the next main section.

Test-driven development

To get myself into the habit of writing tests first, I'm including it as a subtask for each function I note in my task manager (I use Nirvana, an app designed with GTD in mind). I have a template for these subtasks, which I copy into the description of the tasks. At the moment the template looks like this:

- Document
- Test
- Code
- Commit

Really I'll move back and forth between documenting, testing, and coding, but I'll check them off when I've completed the first instance of each of those subtasks for that function.

Refactoring

I don't have a specific refactoring procedure in place. I just do it when I notice the need. I'm hoping to study Fowler's book and learn to think in terms of the structures that refactoring creates. That way I can create them as I code and reduce the need to refactor.

Version control

I'm hosting my projects on GitHub (see the Distribution section), which means I'm using Git as my version control system. (Before that I was using Subversion via TortoiseSVN, which I still use for some non-GitHub projects.) I learned how to use Git from Git Essentials by Ferdinando Santacroce, and I try to follow its advice. For a reference I use Git Pocket Guide by Richard Silverman. Rather than typing all the Git commands myself, I'm lazy and use the GUI tool GitKraken. As I said above, I use the GitHub flow workflow to organize my commits. GitHub has as guide for it.

Coding style

I've picked up my coding style from various sources, including Perl Best Practices, but PEP 8 is a good starting point that's specifically geared toward Python.

Project structure

I make a directory on my local machine named whatever I'm using for the GitHub URL (e.g., math-student-sim), and I create this structure inside it:

docs/
<package>/
tests/
app.py
LICENSE.md
MANIFEST.in
README.md
setup.py

My package name is usually the project name without the hyphens (e.g., mathstudentsim).

I'll fill in more of the details in later sections.

Distribution

To distribute your code you need somewhere to host it, and I've chosen GitHub, since it's the one I hear the most about.

Installation

I haven't completely wrapped my mind around Python code distribution and installation, but for now I'm relying on people downloading the source from GitHub and running the setup script. Here are some more details on some of the issues that came up for me in the project structure guides above.

Metadata

Users of your project will need certain information about it, and you'll need to keep this information somewhere. For Python modules this is in the setup script.

Version numbers

I'm just following the guidelines in those articles.

License

I've picked MIT as my default to give people freedom to use the code however they want and because I don't expect to have patents to license.

Tests

Based on the advice in Learn Python the Hard Way, I've chosen nose as a test management tool, but since the future of nose is uncertain, I'm using nose2.

User interface

Command line

To make my projects usable quickly, I'm starting most of them with a command line interface.

I'm placing the commands in cli.py within the package.

[More sections to come]

<disqus/>