Goodbye Shared Dotfiles

A lot of people start programming with shared dotfiles, copied from a team or online. I did. Maybe you’re ready to move on; how would you do that? Recently after 6.5 years, I removed the Hashrocket Dotmatrix, a powerful set of tools, from my workstations. In this post, I’ll discuss these tools, and why and how I uninstalled them. What is the Dotmatrix? The Hashrocket Dotmatrix is a set of configurations built by generations of consultants at my previous employer, Hashrocket. ...

May 25, 2022

Organizing React Components

You’re creating a React app, and want to organize your components. Or maybe you’re working in a legacy codebase, with many components in one directory, and you want to better organize them. In this post, I’ll document an approach to this problem that has worked for me. Besides React, I’ve used this in Vue, Nuxt, and Gatbsy applications. Any JavaScript framework that’s loosely opinionated about directory structures could receive this structure. ...

May 23, 2022

On Starting Over

I used to have a bad habit when working alone: I’d start a feature, begin doubting my approach, throw away my work, and start over from scratch. Sometimes more than once. The result? Wasted energy, abandoned code, confusion about what I had and hadn’t implemented, and repetitive rework. This post is a collection of thoughts on this practice. They are: It’s okay to start over, for the right reasons Prioritize getting it working Save your work When getting help, don’t show up empty-handed It’s Okay to Start Over Code Retreats is a programming community that encourages throwing away first drafts. Starting over can be helpful when you’re learning a new technique or trying to improve. ...

May 18, 2022

How to Identify the Breaking Commit With Git Bisect

Some code is broken, and you can’t figure out why. Maybe there are a lot of changes, and identifying the breaking change seems impossible. Or, maybe you’re curious about how things break in your organization. The tool you need is git-bisect. Git bisect conducts a binary search through your Git history to find a commit of interest. In this post, I’ll show how it works. A Caveat: Atomic Commits Required For bisect to be useful, you must be committing atomically. If your practice is to squash-merge PRs, or commit swaths of unrelated code with each commit, a bisect may only tell you that something broke when you merged in a huge PR. That can be, isn’t always, useful information. ...

May 17, 2022

Commit Part of a File in Git

You’ve been working on a big set of changes, and haven’t committed to Git yet. Now, you want to commit some, but not all, changes to a file. Let’s look at adding patches. Here’s the command. $ git add --patch --patch lets you interactively choose which changes to apply to a commit. Applying Patches Run this command and you’ll see the following: $ git add --patch diff --git a/README.md b/README.md index 18d277a..b012031 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # [jakeworth][production-url] +A blog of awesome Git tricks. + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? ? This is a piece of our diff, or a ‘hunk’, with information telling us which one we are currently reviewing (one of two), and a menu of options. ...

May 6, 2022

You Have to Get Fast to Get Good at Programming

Great programmers aren’t fast because they’re great. They’re great because they’re fast. I’ve sunk a lot of time into being fast at Vim. I’ve used it as my text editor for eight years, co-organized a Vim Meetup, and I’ve written about Vim on this blog and Hashrocket TIL dozens of times. Why? Because I want to be a fast programmer. In this post, I’ll explain why I think being fast at programming is a worthy goal. ...

May 6, 2022

Only One Way Out of a Function

A programming style I try to practice could be described as: “there should be only one way out of a function.” Early returns can often cause more confusion than they’re worth. When possible, I avoid them in favor of a single return. Here’s a demonstration of this style. Common Code: Early Returns Imagine a function that takes as an argument an HTTP response object responding to .ok and returns a message string. Here’s an implementation, with an early return, when response.ok is truthy: ...

May 2, 2022

Am I Too Old to Become a Programmer?

“The best time to plant a tree was twenty years ago. The second best time is now.” – Chinese proverb I mentor adults who are learning to program after serving in the military. Some are in their late twenties, and some are twice that age. A common concern is that they are too old to be changing careers to programming. As a career-change programmer, I understand. I discovered programming around age thirty, with no experience and one introductory CS college credit to my name. I had the same concern. ...

April 28, 2022

It's Harder to Read Code Than Write It

In Things You Should Never Do, Part I, Joel Spolsky narrates Netscape’s ruinous decision to rewrite their browser from scratch. This introduced the following concept to me: “It’s harder to read code than to write it.” I believe this is true. Today I’d like to explain why. A Practical Example As an example, consider the “liking” feature of Today I Learned. This is an icon under each Today I Learned post that you can click to indicate: “I like this post.” ...

April 25, 2022

The Problems With Code Screenshots

Screenshots of code are common in developer communication, but they come with real drawbacks. Here’s why I try to avoid them. Screenshots happen. People are often under time pressure, on phones, or unfamiliar with best practices. Some people feel more confident communicating with images. I’m here to offer solutions, not shame. Problem Background Why does one post screenshots? To be helpful. You’re stuck and want to provide high-bandwidth information. What could be higher bandwidth than a picture? I appreciate that helpful spirit. ...

April 19, 2022