Homepage
Open in app
Sign inGet started

Extreme Programming

Go to the profile of Clay Shentrup
Clay Shentrup
Mar 31

Stimulus.js Lifecycle Callbacks

One common mistake I see in Stimulus controllers is that people use the connect() callback to set up…

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Dec 6, 2020

My RuboCop config

By far my favorite is Style/MethodCallWithArgsParentheses, which forces parentheses everywhere. Optional parens are one of my least…

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Sep 5, 2020

Enumerable in Go Using Generics

The latest iteration of generics is amazing. Here’s a short proof of concept for a Ruby-like enumerable construct.

package main
import (
"fmt"
"strings"
)
func newSliceEnum[T comparable](s []T)…
Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Jul 27, 2020

Avoid []

It’s a Risky Tool with No Benefit

What

Avoid calling hash[key]. Instead use hash.fetch(key) if the key is expected to always be present, or hash.fetch(key, nil) if it’s valid/expected for the key to be absent.

Why

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
May 17, 2020

Avoid #each_with_object (generally)

In my experience, Ruby’s each_with_object (docs here) can almost always be replaced with a simpler more specific/semantic construct.

Example 1

all_points = routes.each_with_object([]) do |route, result|…
Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
May 16, 2020

Use buildpacks not Dockerfiles

Don’t take my word for it, let these people make the case.

https://www.youtube.com/watch?v=spW9ZlJpobM

https://blog.heroku.com/docker-images-with-buildpacks

https://www.youtube.com/watch?v=2Xorbt3TaP4

https://buildpacks.io/

Go to the profile of Clay Shentrup
Clay Shentrup
May 15, 2020

Don’t use version constraints in Gemfile

The “~>” is not a “min version specifier”. It is the pessimistic operator. For example:

Don’t use version constraints outside of lock files

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Jan 15, 2020

The coin change probem in Go

How many ways can we pick a set of coins of allowed denomination to equal a specified amount?

package main
import (
"fmt"
)
func numWays(amount int, coins []int) (result int) {
if amount == 0 {…
Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Dec 31, 2019

Details Matter

When you’re a disciplined software engineer, particularly one working in the XP (Extreme Programming) school, it can be a bit challenging when people don’t readily see the importance of minute details. But I find that people tend to care once they’ve been burned. This is one of my experiences sharing…

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Nov 28, 2019

Avoiding Type Assertions in Go

Prefer Polymorphism to Conditionals

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Jul 11, 2019

OOP vs. FP

I’ve come across countless articles debating the merits of object oriented programming (OOP) vs. functional programming (FP). I want to put a stop to this madness by simply noting that OOP and FP are only different in terms of minor semantics. For example, compare these two ways of writing the same code.

Read more…
1 response
Go to the profile of Clay Shentrup
Clay Shentrup
Jul 5, 2019

OAuth and TDD in Go

I recently set up some Go code to communicate with the Nielsen API using OAuth 2. In addition I wanted to use the VCR…

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Feb 6, 2019

Exceptional Go

You’ll often hear Go developers claiming that it’s incorrect (not idiomatic) to panic in Go; instead we should return errors. After…

Read more…
2 responses
Go to the profile of Clay Shentrup
Clay Shentrup
Nov 16, 2018

Tests & Dependencies

You’re probably mocking too much.

Read more…
1 response
Go to the profile of Clay Shentrup
Clay Shentrup
Jul 30, 2018

What Goes In Active Records

In October 2011, Gary Bernhardt did a two-part screencast titled “What Goes In Active Records” (1, 2). Starting with general principles, Gary states his goals for an ActiveRecord class’s design.

The things I want in this class are things that wrap the…
Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Jul 30, 2018

Unnecessary Conditionals

Imagine we have the following methods:

def book_content(indifferent)
if indifferent
book_json_blob_content_with_indifferent_access
else
book_json_blob_content
end
end
def book_json_blob_content_with_indifferent_access…
Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Jan 6, 2018

Notes & Thoughts on Exceptional Ruby

Buy it here.

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Dec 10, 2017

Bi-directional use of class_name in ActiveRecord associations

Labels: rails, ruby, software

I recently wanted to use ActiveRecord’s association syntax on two models, called Proposal and Period. To add clarity, I wanted the Proposals to be called…

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Nov 28, 2017

What goes in Rails lib/

A common question teams run into while building a Rails app is “What code should go in the lib/ directory?”. The generated Rails README proclaims:

lib — Application specific libraries. Basically, any kind of custom code that doesn’t belong under controllers…
Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Oct 22, 2017

Ruby/Rails FYI

Interpolation

Interpolation automatically calls to_s, so the to_s calls in this sample text are unnecessary.

def s3_filename(record)
name = record.name || 'Empty '
date = Date.today.to_s
guid = UUIDTools::UUID.random_create.to_s…
Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Jul 16, 2017

The Twelve-Factor App, Abridged

Use declarative formats.

  • API (“clean contract”) with the OS for portability
  • Cloud deployable
  • Minimize divergence between dev and prod, facilitate continuous integration (CI).
Read more…
1 response
Go to the profile of Clay Shentrup
Clay Shentrup
Feb 13, 2017

The Hierarchy of Complexity for Conditionals

When the Ruby on Rails framework was first released, one of its biggest selling points was convention over configuration. Name your ActiveRecord model User, and it would use the users table in its generated SQL. This preempted the need for verbose…

Read more…
Go to the profile of Clay Shentrup
Clay Shentrup
Jan 20, 2017

Notes from 99 Bottles of OOP

Link to book.

The net cost of caching can be calculated only by comparing the benefit of increases in speed to the cost of creating and maintaining the cache. If you require this speed increase, any cost is cheap. If you don’t, every cost is too much.

Read more…
1 response
Go to the profile of Clay Shentrup
Clay Shentrup
Nov 27, 2016

On Comments

Documentation in code. Programmers are taught to comment their code: good code has lots of comments. Unfortunately, they are never taught why code needs comments: bad code requires lots of comments. The DRY principle tells us to keep the low-level knowledge in the code, where it belongs, and reserve the…

Read more…
1 response
Go to the profile of Clay Shentrup
Clay Shentrup
Feb 1, 2016

Interesting Excerpts From “Extreme Programming Explained”

I just finished up Extreme Programming Explained, by Kent Beck and Cynthia Andres. Here are some excerpts I found interesting.

Read more…
About Extreme ProgrammingLatest StoriesArchiveAbout MediumTermsPrivacy