Go: Working effectively with database nulls

This post covers how to marshall null values from a database into a Go struct type and how to save nulls back to the database. I’ll cover the standard library’s sql.NullString, NullInt64, NullFloat64, etc types — which I’ll refer to as sql.NullXYZ when indicating the collection of types and not a specific Null type — important methods on those types, telltale errors, and some helpers for working with values coming from form posts. This code uses SQL and the standard library. Takeaways In structs, use sql.NullString, sql.NullInt64, and its ilk instead of string and int for fields that persist to … Continue reading Go: Working effectively with database nulls

Intellij IDEA: Running your own Go programs against editor text

In this post, I’ll describe one approach to running programs written in Go against text in the IDEA editor. This same approach applies to any Jetbrains IDE, such as PyCharm or WebStorm. Admittedly, this is niche. Tracking time at work Number 1: Every few weeks, I need to submit a virtual time card. If I work over 40 hours, I need to note that for comp time. If I work under 40 hours, I need to fill it in with PTO. Number 2: I work on several projects, and I need to track what percentage of my time I devote to … Continue reading Intellij IDEA: Running your own Go programs against editor text

Intellij IDEA: Run goimports on file save

goimports is a Go tool to remove unused and add missing imports. It also formats your code the same as go fmt. This is one solution for running goimports when saving *.go files in Intellij IDEA. If you have a better way (not involving snark about emacs), please comment. Assumptions You have goimports installed. If not, install with: go get code.google.com/p/go.tools/cmd/goimports You’re probably using the golang plugin. That plugin isn’t necessary for this goimports-on-save business, but if you’re using Intellij to write Go code then you might as well use the plugin, too. Big Picture Create a shell script to run goimports against … Continue reading Intellij IDEA: Run goimports on file save

Ice Ice Baby

In Defense of Silly Programs

To learn a  programming language, you must either Write a compiler for language Write programs in the language A handful of canonical first-programs have risen in the past few years. TODO lists and Blog Engines are popular because they’re easy enough to start and difficult enough to cover a non-trivial swath of a language’s ecosystem such as documentation, packages/modules, build systems, package manager, support network, and so forth. They also generally require integration with a database, which at least in most OO languages can lead to understanding at least one major framework and consequently that framework’s abstractions, typically ORM-y, for … Continue reading In Defense of Silly Programs