RSSAmplifier

Blog

David R Hagen

Personal website of David R Hagen, scientific software engineer

drhagen.comRSS feed ↗20 posts

Latest posts

The Phase of the Year: Something the Gregorian Calendar Gets Very Wrong

In the first article of the series, we concluded that days and years are the appropriate periods of our calendar . In the second article, we determined the optimal phase of the day. Each day should begin and end on midnight because of its astronomical relevance and biological convenience. That leaves us with the phase of the year. The period of our year is already synchronized with the seasons. We…

The Phase of the Day: Something else the Gregorian Calendar Gets Right

In the last calendars post, we concluded that days and years were the proper periods for a calendar . But their underlying natural phenomena are cycles without beginning and without end. To be useful in a calendar, we need to be able to put particular events on particular days and years. We need to be able to count and label days and years. To do that, we need to pick a dividing line between one…

Excellent error messages

Error messages are pervasive throughout programming, yet little has been written on the design of error messages for languages, libraries, and APIs. Much good advice can be found via simple web search on good error messages as shown to end users in GUIs, but standards for error messages intended for an audience of programmers is hard to find. This is not due to a lack of attention to error…

The sort-within-groups problem

There is an interesting edge case in data grammars when a grouped data table is sorted by non-group columns. For example, what should the following dplyr code produce? ```r library(dplyr) df <- data.frame( group = c(2, 2, 1, 1, 2, 2), value = c(3, 4, 3, 1, 1, 3) ) df %>% group_by(group) %>% arrange(value) ```

Leap Years: Something the Gregorian Calendar Gets Right

Calendars coordinate people with people. It is better to be on vacation the same week your family is also. It is better for kids to be in school the same days as their teachers. It is better to be at work when everyone else is. (Though it is worse to be driving to said work when everyone else is.) In the modern world, it can be easy to think that coordinating people with people is all calendars…

Finally, a synthetic organism that worries me

It was recently in the news that researchers have genetically engineered tobacco with 40% more efficient photosynthesis. I had first seen this kind of research at a seminar during my graduate years at MIT. The presenter noted that the genetically engineered plants grew faster and showed memorable side-by-side pictures of scrawny-looking normal plants next to their larger and lusher engineered…

Multidimensional Pairing Functions

In the previous post , I compared ways to take two infinite streams and generate a new stream that is all possible combinations of the elements in those streams. This post takes it up another level and generalizes this procedure to an arbitrarily long list of infinite streams. This is a trickier task than the 2-dimensional case, utilizing recursion into each dimension to cleanly generate all…

Superior Pairing Function

Given two sequences of objects, it is often desirable to generate a sequence which is all possible pairwise combinations of those sequences—the Cartesian product. If the sequences are finite in length, then it is a trivial function to write in any programming language. The function even exists in many standard libraries and packages, such as itertools.product in Python. But if the sequences are…

Ready for a National ID

When Yahoo was hacked , we threw away our passwords and got new ones. When Target was hacked , we threw away our credit cards and got new ones. Now that Equifax has been hacked , we'll have to throw out our social security cards and get new ones. Alas, such a thing is not currently possible, and that's a big problem. It's not that we shouldn't have a national ID number. A robust credit system…

The Sanctification Button

I have a browser extension installed on my work laptop that blocks my access to Reddit, Facebook, and other news and social media sites. My employer didn't install it; I did. I have the same extension installed at home, albeit blocking a more limited set of time-wasting sites. On its face, setting up a system that does nothing but restrict my future options seems like a waste of time. Wouldn't it…

Marginal vs. Conditional Subtyping

In computer programming, a type is a just a set of objects—not a physical set of objects in memory, but a conceptual set of objects. The type Integer is the set {0, 1, -1, ...} . Types are used to reason about the correctness of programs. A function that accepts an argument of type Integer , will work for any value 0 , 1 , -1 , etc., for some definition of 'works'. Subtyping is used to define…

The Missing 23rd of the Month

Previously, I explained why the 11th of most months is mentioned far less than the other days in the Google Ngrams database of English literature from 1800-2008. This was to solve a long-standing question posed in an xkcd comic . While researching this, I encountered another mystery: the 2nd, 3rd, 22nd, and 23rd are unusually low as well—but only until the 1930s, at which point they become…

The Missing 11th of the Month

![In months other than September, the 11th is mentioned substantially less often than any other date. It's been that way since long before 9/11 and I have no idea why.](images/calendar_of_meaningful_dates_light.png#only-light) ![In months other than September, the 11th is mentioned substantially less often than any other date. It's been that way since long before 9/11 and I have no idea…

Sane Equality

Equality: every programming language has it, the == syntax is as universal as 1+1 , and it works almost the same in every language. When the left and right operands are the same type, equality is easy. No one questions that 1==1 evaluates to true or that 'a'=='b' evaluates to false . This post is about what to do when the operands are different types. What should 1=='1' be? Or what should…

When Sequences Go Bad

In my last post , I talked about the various kinds of syntax for getting and setting elements in sequences. This post will talk about semantics. What exactly should get and mutate do when invoked? What should happen when the index is valid is hopefully obvious. But because we have to handle the case of an invalid index—in particular, an index larger than the length of the sequence, the answer is…

One-Sided Debate over Sequence Syntax

Computers are famously stupid machines . You have to tell them in perfect detail not just what you want them to do but how to do it. A computer may be able to add 1 and 2 faster than I can, but it will take me longer to tell it to do that than for me to do it myself. The more complex the task, the more time it takes to code. Coding is still laborious and entirely not worth it unless such code will…

Difficulty of Pattern Matching Syntax

Pattern matching is compact syntax, originating in functional programming languages, that acts a super-charged switch statement, allowing one to concisely branch on the types and components of a value of interest. Like a traditional switch statement, a pattern match takes a single object and compares it to sequence of cases, running the code body associated with the matching case. There are many…

Free Star Wars for Everyone

You got a robotic vacuum cleaner for Christmas. It is the cutest little thing—circling around the room, diligently picking up confetti from the New Years Eve party the night before. You just can't let all that cuteness go to waste. So you record the whole cycle on your phone—the whole two hours and twenty minutes—and post it to your Youtube channel. You have 5 subscribers, all spam bots. Your…

Comparison of Iteration Styles in Programming

It is difficult to overstate the importance of iteration in programming—the process performing an operation on each element of a list. I would rank only variable assignment, functions calling, and branching as more important. Unlike the if statement, which is essentially the same in every language, the semantics of the for loop varies across languages. Mainly for my own future reference, this post…

The Electoral Jury

How much time to do you spend figuring out how you should vote? A few hours? A few minutes? Any time at all? I could not find a study that measured the average time that voters spend researching their candidates, but I did find that three quarters of Americans do not know how long a senator's term is . Perhaps an average voter reads the blurbs in the local newspaper, listens to some soundbites on…