Sunday, February 28, 2021

Learning Rust: Some Thoughts

Back in September I wrote a post about some utilities written in the Rust language, and mentioned I was toying with the idea of trying to learn a bit of it. With two weeks of vacation around Christmas, I decided to take the plunge and have been reading and working through the examples in the Rust Book off and on as I get a chance.

I was a bit tentative going in, but I find I'm really enjoying it. Prior to this, for reference, I taught myself Python a decade ago while working as an undergraduate research assistant and have dabbled a tiny bit in JavaScript and Lua, but that's the extent of my programming language coverage: I'm still essentially monolingual. I managed to get through my undergraduate time without ever taking any sort of computer science class, and it's left me a little self-conscious of my self-taught status when it comes to Python. Rust is a very different language to Python, and I was worried that perhaps I wouldn't be able to pick up a new language as easily as I could ten years ago if I've unconsciously generalized Python-specific quirks to programming languages as a whole.

However, contrary to my worries I've been finding it an interesting and fun experience. I suspect my experience in studying various far-flung human languages may be helping, as it may be helping me to generalize better between different programming languages. And Python and Rust are opposites in some rather key ways: Python is an interpreted language, which means that programs are (and need to be) compiled and interpreted by an interpreter program at run-time. Rust on the other hand is a compiled language, which means it needs to be compiled before running (but can be run afterwards without needing any external program). Python is a dynamically-typed language where variables can be created with ease as needed and converted to different types without oversight by the language. Rust is statically-typed, with a very strict enforcement of variable types all working at compile time. These are not minor differences, but almost diametrically opposed paradigms, like the difference between a case-based language and one which relies on word order.

One of the major unique features of Rust is its concept of ownership. In essence, this is a requirement (checked and enforced at compile time) that only one “part” of a program can change a variable's value at a given time. A value can be “borrowed” any number of times for use as long as it is not changed, and the system responsible for enforcing this is known as the borrow checker. Colloquially people joke about spending much of their time learning Rust “fighting the borrow checker,” as the concept of ownership is a novel one and wrapping one's head around it takes some time.

Thankfully, Rust has some really good error messages. I've managed to write a few small programs on my own so far, and the error message output usually contains both an explanation of what I've done wrong, and a suggestion for how to fix it. In fact it's generally gone so well so far that I'm a bit suspicious; when is the other shoe going to drop? I've had errors, sure, but I've been able to figure them out quickly and get what I want to happen (within my still-limited understanding of the language as a whole). Granted, I'm not exactly writing complicated programs, just simple ones to find prime numbers or convert temperatures between scales, but still; it's been a pretty pleasant learning experience so far. I've most certainly got a lot to learn left, but it's fun to be seriously learning a new programming language again with no stress about the outcome.

I don't know if this will ever be useful in a job down the line (although a number of large companies are starting to use Rust for its ability to remove even the possibility of whole classes of costly memory errors found in languages like C or C++ due to ownership), but even if not I'm sure the experience of learning a new—and very different—language will have benefits for my Python knowledge, in the same way learning other languages has helped me reason about English*. And you never know, it just might come in handy down the line somehow. A hui hou!

*Interestingly, the upcoming Python 3.10 is getting a “match” system for comparing multiple cases which is extremely similar to the one found in Rust, so it might prove to be more useful than I'd initially thought!

Saturday, February 27, 2021

Keeping drinks cool with the Peltier effect!

This past week—in the height of southern hemisphere summer—I put on my jacket to go take a walk outside, while shivering in the frigid summer air.

It's been an odd summer here in Melbourne this year. Apparently it's a La Niña year in the Pacific ocean, which means a colder, wetter, summer. And it definitely has been; I think two weeks ago—in the middle of February, typically the hottest month of the year—was the first time this summer it was warm enough to go an entire week without wearing socks. Then a cold front came through and I've been shivering while dressed in warm clothes this entire past week. Imagine it being cold enough in central California in August to need to put on a jacket to go out for a walk, and you'll get an idea of what it's like here.

I mention this because, back in November, when we had our first signs of winter relinquishing its fell grasp and an occasional day where it was actually warm, I started thinking about working from home over the summer. At that point I didn't know it was going to be a cooler summer; in past summers since I've been here I've seen days where it hit over 43 °C/110 °F. (This summer I think the highest I've seen is 32 °C/90 °F, though that's still plenty hot enough when it barely cools down more than a few degrees overnight.) Thinking that the expected upcoming heat would be more tolerable if I just had something cool to drink during it, I started thinking about ways to keep a drink cool. The obvious first choice was ice cubes, but ice always waters down your drink over time, and I prefer to sip on something cold over time rather than guzzle it to avoid it getting watery. I started wondering if there were anything more modern than simple ice cubes, and did a little digging.

I first discovered whiskey stones, which are basically re-usable ice cubes made of stone or metal: you put them in the freezer to cool down, then put them in your drink. Not bad, but then I had a thought: wouldn't it be neat to use a thermoelectric Peltier cooler to directly cool down a drink on your desk? If you haven't heard the term before, a Peltier cooler is a device where, by putting two different metals together and running an electric current through where they join, one side cools down by giving up its internal heat to the other side. (It's not a new discovery, having been discovered by Jean Peltier back in 1834, but Peltier coolers are still not something most people will ever likely have come in contact with.)

I wasn't sure such a device for home use existed (and had no idea what to call it even if it did), so it took some stumbling around with Google and Amazon to find one, but find one I did! In fact, I found several different takes on the idea by several brands, though all following more-or-less the same pattern.

Now, while it looks like these devices have been on sale for at least a few years or so, they're still new enough (and niche enough) that I don't think they really have a settled name yet. The one I bought had the word-salad title “HSTYAIG Portable Mini Refrigerator Electric Summer Drink Cooler Kettle Drink Instant Quick Cooling Cup Home Office Cold Drink Machine Small Appliance Kettle (Traditional),” but let's just call it a “cooling cup” for short.

But what is it, exactly? Well, it's an electric device comprised of a plastic base holding the electronics with an aluminum plate in a depression on top in which sits an aluminum cup, and it looks like this:

Device on the right, cup on the left. You can see the cooling plate in the depression.

It's got a single capacitive on/off button on the front, and that's it as far as interactivity goes. The aluminum plate is the cold side of a Peltier cooler, and when you turn it on, the plate cools down (and draws heat from the cup) and a fan blows out heat from the hot side of the Peltier cooler (inside the device).

And does it ever cool down fast! Literally a few seconds after turning it on the aluminum plate is cool to the touch. After a minute or so it becomes painfully cold, and when I let it run for 20 minutes as a test the first time I tried it I saw tiny ice crystals forming on the plate, despite it being 20 °C/68 °F in my room at the time. I'm used to refrigeration, but heat-pump refrigeration takes a while to cool things down. In comparison, a Peltier cooler feels downright magical with how fast it works. Now, despite the impressive cooling performance of the plate by itself, in practice it'll struggle to cool a room-temperature drink down. Water has a surprisingly high thermal inertia, so if any water-based drink isn't already cold it'll take a long time to get cold. If it is cold, though this thing does a phenomenal job of keeping it cold. (In fact, the last few sips can be even colder than when it came out of the fridge!)

Although I got my cooling cup at the end of the November, I've been holding off on reviewing it here while waiting for it to really warm up for the summer (when it would make sense to talk about something meant for cooling drinks). As that appears not to be happening this summer, however, I might as well post about it now. I've had several months to try it out, and it works like a charm. Pour something cold into the cup, press the button, and it'll keep it nice and frosty for as long as you like. It feels like a very modern solution to the problem of keeping a drink cool, even if the technology to do it is approaching 200 years old at this point. Admittedly it's hardly the biggest problem out there, but as a solution to it I can heartily recommend a “cooling cup.” (Although, if these ever catch on, let's come up with a better collective name for them.) A hui hou!

Sunday, February 21, 2021

Sculpting Moon Craters: Tsiolkovskiy Crater

With all the end-of-year busyness last year, I never got around to posting about an artwork I finished back around December. (Then I decided it wasn't quite finished and did a little more work on it a few weeks ago, so go figure.) After my first foray into more three-dimensional sculpture back in 2019, I wanted to try something in a similar vein.

Back around December 2019 I was inspired by the crater Tsiolkovskiy (located on the far side of the Moon) to sculpt a crater out of clay and paint it. While much of the Moon's near side is covered with darker lava (as you can see by looking when the Moon is mostly full), most of the Moon's far side is lacking this, instead being the same color as the lighter areas of the near side (the “lunar highlands”). Tsiolkovskiy crater, named for Konstantin Tsiolkovskiy, one of the founding fathers of rocketry (with an important equation named after him too) is one of the rare exceptions, a crater with a floor flooded with dark lava. It's quite a large crater, too, with a diameter of some 300 km/185 miles; like many large craters it has a central “rebound” peak which towers an imposing 3200 m/10,500 ft above the smooth lava plains around it, around the height of Haleakalā above sea level.

Anyway, inspired by this fairly unique crater, I picked up a circular piece of artist's board about a year ago, painted it with an undercoat, and then left it on my desk for nine months during the lockdowns last year. When I was finally able to get back in to Swinburne and retrieve it, I picked up some modeling clay and started sculpting the crater's form, which proved to be quite fun!

The underlying topography of Tsiolkovskiy crater.

After letting the clay dry I painted it all a nice light gray, then got to the step which had originally inspired me: pouring a dark gray ‘lava’ into the crater to fill in the central plains. The paint turned out to be a little more viscous than I'd been imagining (even though it's called “self-leveling gel” for this sort of work!), but it worked out in the end.

With the dark lava plains filled in. North is roughly up in all of these photos, by the way.

I ended up painting it a little more gray after a few weeks—I'd been trying to give it a little tinge of color originally, but I felt it just wasn't working so I went back to a more neutral shade in the end.

“Tsiolkonskiy Crater,” 30 cm in diameter, modeling clay and acrylic.

Overall it's been a really interesting and fun project, and I might do more pieces in this vein in the future. It'd be cool to do a sculpture of Olympus Mons, for instance, or other famous craters, mountains, or valleys in the solar system. Given my love of experimenting with 3D effects on canvas, I suppose sculpture is simply a natural extension of that. With finishing my PhD on the horizon and the associated job-hunting and possibly-moving I don't know when I'll be able to make another one of these, but hopefully it won't be too long. A hui hou!

Sunday, February 7, 2021

Birds of Melbourne: Australian magpie


I'm back with another bird-feeding video, this time starring an inquisitive Australian magpie. Unlike their Eurasian counterparts, which are corvids (birds like crows and ravens), Australian magpies are passerine birds (perching birds, or songbirds). They also have a reputation as one of the most feared birds in Australia, due to a tiny fraction getting territorial around mating season and dive-bombing people traveling past their nests. (Especially bikers, for some reason; if you see an Australian biker with zip-ties or pipe-cleaners poking out of their helmet, that's an anti-magpie strategy.)

I've never had a magpie swoop me (just noisy miners), but they're undoubtedly quite confident birds that will often betray no concern as you walk by mere feet away. I've seen them come over to almost within arm's reach when I've offered food. They've also got some amazing vocalizations; my favorite (and their most famous) is a sort of warbling call with some fascinating harmonics, though apparently they can also imitate dozens of other bird species and even natural sounds or human speech!

For the video below, I found a magpie outside and put out a cluster of seeds for it, then set up my camera a few feet away on a short tripod to get a ground-level view. (Magpies spend quite a lot of time walking around on the ground looking for food.) I took a seat just behind the camera, so I was quite surprised when, after about a minutes of pecking at the seeds, the magpie came over and starting checking out the camera! It was pretty neat, and I got some great footage out of it.

Despite their fearsome reputation and visage, magpies can be surprisingly playful. I've seen one rolling over on its back in the grass (and heard of such behavior from other people), and apparently they've been seen doing things like having one magpie hang on to a hanging towel upside down, and get swung back and forth by other individuals. Pretty fun-loving birds, all things considered! A hui hou!

Edit (2/16/21): I've just come across the following video of Australian magpies playing (from the YouTube channel "The Magpie Whisperer"), and had to share—it's really funny to watch them doing summersaults and just clearly having a grand old time. You can also hear some of their wonderful warbling song.

And here's another clip of some juvenile magpies hanging upside from towels on the line. Such funny birds!