Weeknotes 168
15th September, 2024
“Early return”
-
I signed up for a BrickEconomy account this week. I am cool.
-
TIL about private properties in JavaScript.
class ClassWithPrivate { #privateField; #privateFieldWithInitializer = 42; #privateMethod() { //... } }
Leading with a
#
makes it private. -
What’s New in Neovim 0.10 [via Harry]
Neovim content, which was once the nexus of this publication, has dwindled in recent months. No longer, we’re back baby.
This summary of what’s new in 0.10 was an interesting read, in particular, the built-in commenting support which means I can remove a plugin.
-
We attended a “A Night at the Movies” this weekend. Classical renditions of famous movie scores. It was a relaxing way to spend a couple of hours in beautiful surroundings.
-
BLADE RUNNER 2049 - “2048: Nowhere to Run” Short
If you liked Blade Runner 2049, you might also like this short focussing on the character Sapper Morton.
-
Neither Elon Musk Nor Anybody Else Will Ever Colonize Mars
Mars does not have a magnetosphere. Any discussion of humans ever settling the red planet can stop right there, but of course it never does. Do you have a low-cost plan for, uh, creating a gigantic active dynamo at Mars’s dead core? No? Well.
I guess we’re not going to Mars.
-
The Canadian passport has arrived! Whilst I am relieved to now have it in my possession I bet that no one even checks it when I travel.
-
The early return. What is it about it that is so appealing?
I think that in Ruby it is loved because partly because it has a knack of making it read so damned nicely.
def foo return unless something? # do more stuff... end
Look at it. It’s so pretty. (Incidentally, this is one of the few places I think
unless
is acceptable).The thing is, people are going around early returning everything and it makes code hard to read in many cases. In my view, early returns should be used for guard checks. Can this method run if this condition is false sort of stuff.
I often see the humble
if
/else
shunned in favour of the disjointed early return. If your whole method is a decision between two branches, don’t do this:def foo return :bar unless something? :baz end
Do this:
def foo if something? :baz else :bar end end
Future readers will thank you.
-
Conditionally Disabling Code with Comptime in Zig
Zig is interesting.
-
Like every other week, this week I discovered another Ruby/Rails method which I sort of knew about, but haven’t really used. This one is simple:
Object.in?
for checking if something exists in an Enumerable.The traditional way would be something like this:
PRODUCT_CATEGORIES.include?(category)
But the expression is a bit backwards in terms of how we think about what we’re trying to achieve.
Object.in?
let’s you do this instead.category.in?(PRODUCT_CATEGORIES)
-
Will they exercise discretion and nuance? Will they have the ability to prioritize based on that information? Will they make appropriate tradeoffs? [No.]
This is the problem with linters. Rules will be followed without thinking about whether they are appropriate.