An increasingly-frequently asked question in the Go subreddit is some variant of: “I have this code but it isn’t doing what I expect it to do.”
type MyStruct struct { // definition } type OtherStruct struct { // definition } type MySumType interface { MyStruct | OtherStruct } func main() { myStruct := MyStruct{...} printVal(myStruct) } func printVal[T MySumType](in T) { switch val := in.(type) { case MyStruct: fmt.Println("It's a MyStruct") case OtherStruct: fmt.
Pure Python is generally a slow language. Written for performance, it will often be around 40-50 times slower than C, and Python “written for performance” is Python that is very straightforward and does not use many of its features. Python code that has a couple of methods on inherited classes, maybe a non-trivial decorator, and some __getattr__ or similar features can slow down multiplicative factors beyond the 40-50 slower very quickly.
In This Post Is Not About Python, I make a comment towards the beginning about how Python “written for performance” is “Python that is very straightforward and does not use many of its features”. It may seem odd to post an addendum prior to the post it is an addendum too, but, let’s just say, I’ve learned a bit about how the Internet reads things over the years, and I both want this out of the main flow of that post, yet, available immediately when I post it.
The term “magic” is commonly thrown about in the programming world without a definition. This post gives a definition for it.
Not the definition, just a definition. As a long-standing fuzzy term, I can’t necessarily capture all uses of it in the wild, but I believe this captures a lot of the practical value.
Magic Definition A piece of code is magic in proportion to:
How many other places in the code must be consulted for a human to understand what it does.
In 1968, Edsger Dijkstra published a classic letter which was titled “Go To Statement Considered Harmful”. I think the headline buries the lede, because it’s actually an exhortation to structured programming in general, but it is not incorrect. goto is indeed considered harmful in the letter.
Dijkstra’s letter was completely correct. History has bourne him out. He won.
He won.
Past tense.
The winning is over. It has been accomplished.
The Strong Law of Small Numbers states:
There aren’t enough small numbers to meet the many demands made of them.
What this means is that there are so many more mathematical patterns in the world that involve small numbers than there are small numbers that there will inevitably be coincidences where two completely distinct will share some terms together, but that sharing is essentially false and meaningless.
3Blue1Brown goes over one of the Wikipedia page’s examples of a sequence of terms that reads 1, 2, 4, 8, and 16.
Snorbla the Obviously-Named Science Fiction Alien Maintainer lifted ximir’s snorp away from today’s chemically-encoded daily news dispatch. It was no time to be doom-sniffing ximir’s feed… today was an Auspicious Day. As the Master of the Large Gravitational Array Transmitter, it was ximir’s duty and privilege to press The Button.
For the last several lifetimes of the Snorbla family, the two main black holes of the array, spinning just on the cusp of where they would go out of control from loss of energy for maximum amplitude, had been spinning in a direction inline with the plane of the communication array’s target.
In the 21st century, Wall Street went gaga for subscription
revenue.
There are many good reasons for this. Software releases turn out to
be a clean example of this, so I’m going to talk about that for
simplicity, but it applies to a greater or lesser extent to many other
business transactions as well.
Here is something you can try to understand ChatGPT and similar systems
better, by looking in to your own brain.
I’m going to write three statements here. I want to you to introspectively
examine your own reaction to them. These will not be trick statements; I am
not trying to fool you or embarass you, even in your own mind. I am simply
going to present these statements to you and I want you to observe your own
internal reactions.
A point touched upon in my Interfaces and Nil in Go, or, Don’t Lie to
Computers that deserves full
expansion is, what exactly does it mean for a value to be valid?
It is something that I think many would consider obvious at first, but
if you dig into it… and programming generally does make us dig
into things like this… it becomes less obvious.
But if you are one who thinks it’s obvious, riddle me this. I have a
string containing the six characters “here's
”.
Is it valid?