One common mistake I see in Stimulus controllers is that people use the connect() callback to set up event handlers when they really should be using the initialize() callback. Let’s look at the descriptions of these callbacks.

It’s useful to note here that connect() and disconnect() can be called an arbitrary number of times as a controller is connected and disconnected from the DOM. As such, it doesn’t make sense to do initial one-time setup, such as adding a custom calendar library to a date input, in the connect() method. Use initialize().

One might suggest that you use connect() but…


An Epidemic in Economics

If you search the internet for the phrase “hypothecation is a fallacy”, you get essentially two results. First is this Twitter post.

Another is an article titled “Why treasurers should go back to economics school”, by Geoff Harcourt, Visiting Professorial Fellow, University of New South Wales. Key excerpts:

Obsessed with the relationship of government expenditure and taxation, many treasurers suffer from deficit size fetishism, and fall victim to the “balancing the budget over the cycle” fallacy. Many also get caught up with hypothecation — matching specific government expenditures with particular tax sources. …


Proportional Representation Without All the Hassle

Photo by Tom Radetzki on Unsplash

In 1949, Germany adopted a voting method called mixed member proportional voting, or MMP.

After the use of the absolute-majority Two Round System (TRS), see Two-Round System, in the German Empire, and the use of a pure proportional representation system in the Weimar Republic, see Mixed Member Proportional, a new electoral system was established by the Parliamentary Council in 1949.
Source

With MMP, you vote for both a candidate, to represent your local district, as well as a party. Whoever gets the most votes represents your district. …


Lee Drutman recently wrote a post called “Approval voting vs ranked-choice voting: A hypothetical election”, aimed at demonstrating the superiority of his favored instant runoff voting (IRV) voting method over approval voting. (IRV has been marketed in recent years as “ranked choice voting”, but there are actually a multitude of ranked voting methods.)

By the time we reach the title, Drutman is already off to a bad start. Probably the most common novice fallacy in voting theory is to fixate on a specific cherry-picked anecdotal electoral scenario (“a hypothetical election”) rather than average results over a statistically significant sample of…


require: rubocop-rails AllCops: # TODO EnabledByDefault: true NewCops: enable SuggestExtensions: rubocop-rspec: false # Disagree with 90% of it. Style/MethodCallWithArgsParentheses: AllowParenthesesInMultilineCall: true Enabled: true IgnoreMacros: false Style/Documentation: Exclude: - app/controllers/**/* - app/policies/**/* - db/**/* # Worry about complexity, not length. Metrics/BlockLength: Enabled: false Metrics/ClassLength: Enabled: false Metrics/MethodLength: Enabled: false Metrics/ModuleLength: Enabled: false # Unqualified constant names are unclear perhaps, but NOT ambiguous. Lint/ConstantResolution: Enabled: false # Cyclomatic complexity is useful; assignments aren't problematic. Metrics/AbcSize: Enabled: false # Trailing commas make for clearer diffs because the last line won't appear # to have been changed, as it would if it lacked a…


Here’s a proof sketch of Goldbach’s conjecture, which states that any even number can be formed as the sum of two prime numbers.

We start by envisioning any even number as the sum of any column within two rows. E.g. 14 is:

 2  3  4 5 6 7
12 11 10 9 7 7

The bolded “columns” are those ones that satisfy the conjecture, i.e. are composed of two primes.

Conceptually, the conjecture merely says that it’s impossible to “eliminate” every number below the primes in the top row via division by one of the primes in the top row…


Trump cheated on his third wife with a porn star, and used illegal campaign funds to cover it up.

Trump’s sister Maryanne, a former federal judge, said of Trump, “He has no principles. None. None.”

Trump was recorded openly bragging of sexually assaulting women.

Trump has been accused of sexual assault by over 26 women.

In December 2019, Trump was forced to pay more than $2 million in court-ordered damages to eight different charities for illegally misusing charitable funds at the Trump Foundation for political purposes. As part of a resolution of the lawsuit announced on November 7th, Trump was…


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

package mainimport (
"fmt"
"strings"
)
func newSliceEnum[T comparable](s []T) enumerable[T] {
return newEnum[T](sliceEnum[T](s))
}
type sliceEnum[T comparable] []Tfunc (se sliceEnum[T]) Each(f func(T)) {
for _, v := range se {
f(v)
}
}
func newEnum[T comparable](e eacher[T]) enumerable[T] {
return enumerable[T]{eacher: e}
}
type eacher[T comparable] interface {
Each(func(T))
}
type enumerable[T comparable] struct {
eacher eacher[T]
}
func (e enumerable[T]) Select(f func(T) bool) enumerable[T] {
result := sliceEnum[T]{}
e.eacher.Each(func(v T) {
if !f(v) {
return
}
result = append(result, v)
})
return enumerable[T]{eacher: result}
}
func main() {
ints := newSliceEnum([]int{3, 5, 1})
fmt.Println(ints.Select(func(e int) bool { return e < 5 }))
strs := newSliceEnum([]string{"foo", "bar", "baz"})
fmt.Println(strs.Select(func(s string) bool { return strings.HasPrefix(s, "b") }))
}

This prints out:

{[3 1]}
{[bar baz]}


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

The only benefit of using hash[key] is that it’s six characters shorter to type than hash.fetch(key), or ten characters shorter than hash.fetch(key, nil). But the costs are significant.

  1. Unclear hard-to-diagnose exception stack traces.
  2. Less clear code that makes more work for future developers reading your code.

As Gary Bernhardt, an influential Rubyist and creator of the Destroy All Software screencasts and DeconstructConf once tweeted:

Ruby’s `[]`…


Spooky Action at a Distance, Explained

Quantum entanglement and the resulting “spooky action at a distance” is weirder than most people ever realize. In my view, it’s extremely poorly explained in popular media. So here’s a simplified analogy.

Imagine you have two tiny handheld computers, one labeled “Even” and the other “Odd”, and each having two buttons, labeled “0” and “1”. You each grab one of the computers and press a sequence of 0’s and 1’s, and find that that you see a corresponding series of apparently random pictures of either ROCK, SCISSORS, or PAPER. But when you align the sequences, you see something like this.

Clay Shentrup

Advocate of Score Voting and Approval Voting. Software engineer. Father. Husband. American.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store