log.nikhil.io

November 2019 (8 posts)

State, Coupling, Complexity, & Code

Dependencies (coupling) is an important concern to address, but it’s only 1 of 4 criteria that I consider and it’s not the most important one. I try to optimize my code around reducing state, coupling, complexity and code, in that order.

I’m willing to add increased coupling if it makes my code more stateless.

I’m willing to make it more complex if it reduces coupling.

And I’m willing to duplicate code if it makes the code less complex.

Only if it doesn’t increase state, coupling or complexity do I dedup code.

The reason I put stateless code as the highest priority is it’s the easiest to reason about. Stateless logic functions the same whether run normally, in parallel or distributed. It’s the easiest to test, since it requires very little setup code. And it’s the easiest to scale up, since you just run another copy of it. Once you introduce state, your life gets significantly harder.

I think the reason that novice programmers optimize around code reduction is that it’s the easiest of the 4 to spot. The other 3 are much more subtle and subjective and so will require greater experience to spot. But learning those priorities, in that order, has made me a significantly better developer.

crun1r on HackerNews (emphasis and formatting mine.)

❣️


Jan 12 On “incidental duplication”:

I’ve usually heard this phenomenon called “incidental duplication,” and it’s something I find myself teaching junior engineers about quite often. There are a lot of situations where 3-5 lines of many methods follow basically the same pattern, and it can be aggravating to look at. “Don’t repeat yourself!” Right?

So you try to extract that boilerplate into a method, and it’s fine until the very next change. Then you need to start passing options and configuration into your helper method… and before long your helper method is extremely difficult to reason about, because it’s actually handling a dozen cases that are superficially similar but full of important differences in the details.

I encourage my devs to follow a rule of thumb: don’t extract repetitive code right away, try and build the feature you’re working on with the duplication in place first. Let the code go through a few evolutions and waves of change. Then one of two things are likely to happen:

  1. you find that the code doesn’t look so repetitive anymore, or,
  2. you hit a bug where you needed to make the same change to the boilerplate in six places and you missed one.

In scenario 1, you can sigh and say “yeah it turned out to be incidental duplication, it’s not bothering me anymore.” In scenario 2, it’s probably time for a careful refactoring to pull out the bits that have proven to be identical (and, importantly, must be identical across all of the instances of the code).

burlesona on HackerNews (emphasis and formatting mine.)

Hubble Ultra-Deep Field

One of my favorite things in the world.

Located southwest of Orion in the southern-hemisphere constellation Fornax, the rectangular image is 2.4 arcminutes to an edge, or 3.4 arcminutes diagonally. This is approximately one tenth of the angular diameter of a full moon viewed from Earth (which is less than 34 arcminutes), smaller than 1 sq. mm piece of paper held at 1 meter away, and equal to roughly one twenty-six-millionth of the total area of the sky. The image is oriented so that the upper left corner points toward north (−46.4°) on the celestial sphere.

Wikipedia (emphasis mine)

Here’s all that in video form

The best screensaver in the world using red-shift data

And a very high-resolution image (> 60MB). Wallpapers are available.

Our shit is so, so, so tiny.

There are over 100 billion galaxies in the universe. Simply saying that number doesn’t really mean much to us because it doesn’t provide any context. Our brains have no way to accurately put that in any meaningful perspective. When we look at this image, however, and think about the context of how it was made and really understand what it means, we instantly gain the perspective and cannot help, but be forever changed by it.

We pointed the most powerful telescope ever built by human beings at absolutely nothing for no other reason than because we were curious, and discovered that we occupy a very tiny place in the heavens.

Deep Astronomy

Not so sure about “instantly” gaining perspective but the rest about wonder and curiosity and our insignificant place the heavens still stand.

Comrade Hoff

Loving these Moebius-like works by Ali Hoff (prints are available.) Imagined it being a short animated series like Aeon Flux 😍

AppleTV, AppleTV, AppleTV

I absolutely love Dustin Curtis’ splendid explanation of “AppleTV” branding that’s making making the rounds on HN. For posterity, I stole this handy color-coded transcription off Michael Tsai’s blog.

See also: The intractably stupid AppleTV Remote.

A Vickrey Auction

When you end up paying the price you bid (“first price”), you have a strong incentive to lie about how much you’re willing to pay. Suppose there’s an item for sale that you’d be happy paying up to $1,000 for if necessary, but of course you’d rather pay less. In a first-price auction, if you bid $1,000 and you lose. Well, someone else was willing to pay more than you were willing to, so that’s OK, but if you win, you know that nobody else offered that price and you’d be slapping yourself for not going for $950 and saving a little. Or, who knows, maybe there are really few buyers and you later discover that the second person was only valuing the item at $600? Damn, you could have walked away with it for $610!

[. . .]

In a second-price auction, there’s no reason for you to do that. You can simply say exactly the maximum price you are willing to pay, and there’s never any advantage for you in saying anything else:

  • You don’t want to post a higher bid since you might be forced to pay it, and you don’t want to do that.
  • You don’t want to post a lower bid since you might lose the item for no good reason at all.
  • You’ll end up paying exactly what it takes to win the item: one dollar or one cent more than the next person’s maximum bid.

So, a second-price mechanism encourages everyone to bid truthfully, and the item ships to the person who really values it at the highest price. It’s the best outcome for the seller and as good an outcome for everyone else as they could wish for.

Incidentally, note that this is exactly what happens in ordinary public auctions (“going once, going twice… sold!!”) Everyone walks in with an idea of how much they’re willing to pay, and they keep bidding one dollar more than the current price until they hit their max—but they’re never forced to reveal their max and what they end up paying is just one dollar (or penny, or whatever) more than the second-highest bidder.

– Alon Amit on Quora (emphasis mine.)

Quite a bit of Game Theory stuff on Wikipedia as well.

Midsommar · 2019 · IMDb · B+

Moody and plenty gruesome. Got tired of the commune’s many ‘rituals’. Florence Pugh is 💯, as is the creepy-ass soundtrack. Learned about senicide. First half is a bit of a slow burn like “Hereditary”.

Dawid Planeta’s Illustrations

I could just stare at his work all day. This one’s called “The River of Life

and this one “Deep Forest

Data, Data, Data

Linus Torvalds on git

I’d also like to point out that unlike every single horror I’ve ever witnessed when looking closer at SCM products, git actually has a simple design, with stable and reasonably well-documented data structures. In fact, I’m a huge proponent of designing your code around the data, rather than the other way around, and I think it’s one of the reasons git has been fairly successful

[. . .]

I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important. Bad programmers worry about the code. Good programmers worry about data structures and their relationships.