I guess the MAC address guy is up next. 48 bits may not go so far if every light bulb is going to want its own.
I guess the MAC address guy is up next. 48 bits may not go so far if every light bulb is going to want its own.
Imagine if you were the guy who made the call on IPv4 addresses…
Falsehoods About Time
Having a background in astronomy, I knew going into programming that time would be an absolute bitch.
Most recently, I thought I could code a script that could project when Easter would land every year to mark it on office timesheets. After spending an embarrassing amount of…er…time on it, I gave up and downloaded a table of pre-calculated dates. I suppose at some point, assuming the code survives that long, it will have a Y2K-style moment, but I didn’t trust my own algorithm over the table. I do think it is healthy, if not essential, to not trust your own code.
Falsehoods About Text
I’d like to add “Splitting at code-point boundary is safe” to your list. Man, was I ever naive!
Fair, though I guess my interpretation was that void*
is kind of like a black hole in that anything can fall into it in an unsettling way that loses information about what it was?
I’m with you on this one. There are lyrics on almost every single track for crying out loud. Throw us instrumental lovers a bone won’t you? Songs that are lyrically driven but are otherwise super-repetitive instrumentally tend to put me to sleep.
What I love about concerts is when the band goes off script and just starts jamming. Even a 5-minute drum solo will have me grinning ear to ear, and that’s what I’ll be remembering on the way home.
The city where I live has a musical instrument lending library. I don’t know how common these are? Ours started when a cherished local musician passed away and his eclectic collection became the library. Over the years, more people have donated instruments and there is an annual festival to raise funds for their upkeep. (As a local musician, I’m actually playing at said festival today.)
Anyway, it works just like a regular library. You get your library card and check out an instrument and it doesn’t cost you a penny. And there are all kinds of videos online these days to give you pointers on how to play. I guess if you get really serious, you’ll probably want some one-on-one tutoring, but if you’re just doing it for kicks and don’t have any plans to join a band or whatever, you can just have some fun and see how far you can get on your own?
Actually, now that I think of it, there’s no reason you need to join the 2 names into a single str
. You could just leave it as a tuple
of last, first and Python will know what to do in comparing them.
>>> sorted(student_ids, key = lambda i: ((rec := student_recs[i])['last'], rec['first']))
[632453, 1261456, 532153]
So the lambda would be returning ('Potter', 'Harry')
rather than 'Potter, Harry'
. But whatever. The :=
part is still the same.
Can you use it to initialize vars outside the scope of the lambda?
No, that’s not what it’s for. It lets you define a temporary local variable within an expression. This is useful in situations where you might want to use the same value more than once within the expression. In a regular function, you would just define a variable first and then use it as many times as you want. But until the walrus operator came along, you couldn’t define a variable within a lambda expression.
Can you give an example?
Ok, I’m trying to think of a simple example. Let’s say you had a database that maps student IDs to records contain their names. To keep things simple, I’ll just make it plain old dict
. And then you have a list
of student IDs. You want to sort these IDs using the student names in the form “last, first” as the key. So you could go:
>>> student_recs = {1261456: {"first": "Harry", "last": "Potter"}, 532153: {"first": "Ron", "last": "Weasley"}, 632453: {"first": "Hermione", "last": "Granger"}}
>>> student_ids = [1261456, 532153, 632453]
>>> sorted(student_ids, key = lambda i: (rec := student_recs[i])['last'] + ', ' + rec['first'])
[632453, 1261456, 532153]
The problem here is that student_ids
doesn’t contain the student names. You need use the ID to look up the record that contains those. So let’s say the first ID i
is 1261456
. That would mean:
rec := student_recs[i]
evaluates to:
{"first": "Harry", "last": "Potter"}
Then we are effectively going:
rec['last'] + ', ' + rec['first']
which should give us:
'Potter, Harry'
Without the :=
you would either have to perform 2 student_recs[i]
look-ups to get each name which would be wasteful or replace the lambda with a regular function where you can write rec = student_recs[i]
on its own line and then use it.
Am I making any sense?
They’re somewhat more capable now that we have the walrus (:=
) operator.
I remember ads claiming it was cutting edge nanotechnology! And I thought oh cool, you mean like there are tiny robots running around in the shampoo? But no, it was microplastics.
This happens naturally in the form of meteors streaking through the sky. Each one of those is adding a tiny amount of mass to the planet.
But you’ve got me wondering about something now. When a large asteroid hits the planet, it obviously adds its own mass, but it also kicks up a lot of debris into space. Some percentage of that will reach orbital escape velocity and never come back. But I honestly don’t know if there is a net mass increase or decrease after such an event? We’re generally concerned about other more pressing matters in such a scenario!
From what other posters are saying, it may be the other way around? That is, most mammals cannot see green, so it doesn’t matter from a camouflage perspective among mammals. Humans (and primates in general) are an outlier in this repect.
Bird of prey can, though, so there’s that.
Wow, that is fascinating!
Makes me wonder about the other direction, going into the near infrared as opposed to UV. I remember from a class in remote sensing that many plants are actually most reflective in that band (more so than in green, even). NIR air photos are often used by biologists to get an indication of the health of a forest. But I have no idea whether animals also reflect NIR? It may be that most animals cannot see in that band in the first place, so it would not offer any camouflage advantage.
Great read! That explains a lot.
I’ve been deep diving a bit myself and found this article that explains another thing that’s puzzled me over the years. Some birds have crazy vibrant coloration that almost glistens, like peacock feathers. Outside of the zoo, I’ve noticed it a bit in common grackles. They look black on first glance, but when you study them closely, they have this kind of purple sheen around their heads. Apparently, it’s still melanin at work here, but it’s structured in a very special way.
Right? I guess that’s what puzzles me the most about it. It must be really hard for mammals to become green since you would think it would confer an advantage in many environments you find them in.
I guess there are a lot of mammal species that kind of make themselves scarce during the broad daylight hours, so maybe green camouflage is less relevant if you’re only out between dusk and dawn?
Yeah fair. I had painted glass fish in my aquarium at one point and discovered the “paint” came from feeding them dyed food and eventually faded away when I gave them normal food back at home. They are naturally transparent for the most part which, frankly, I thought was cooler. I did have a gourami that was legit green though, as far as I could tell.
Ha!! You really had to go down the “rabbit hole” for that one I bet! Awesome.
Yeah, I’m a big believer in shade trees! The one in our front yard has grown tall enough to provide blessed relief from a blazing afternoon sun. The only problem is the dude next door, who’s heavy into solar, is worried it’ll block his panels. And I’m a believer in solar too, so I don’t know what to say. Maybe we can come to some sort of compromise…
The Internet needs to be capitalized.
I started in C and switch to C++. It’s easy to think that the latter sort of picked up where the former left off, and that since the advent of C++11, it’s unfathomably further ahead. But C continues to develop and occasionally gets some new feature of its own. One example I can think of is the
restrict
key word that allows for certain optimizations. Afaik it’s not included in the C++ standard to date, though most compilers support it some non-standard way because of its usefulness. (With Rust, the language design itself obviates the need for such a key word, which is pretty cool.)Another feature added to C was the ability to initialize a
struct
with something likeFooBar fb = {.foo=1, .bar=2};
. I’ve seen modern C code that gives you something close to key word args like in Python using structs. As of C++20, they sort of added this but with the restriction that the named fields have to come in the same order as they were originally defined in the struct, which is a bit annoying.Over all though, C++ is way ahead of C in almost every respect.
If you want to see something really trippy, though, have a look at all the crazy stuff that’s happened to FORTRAN. Yes, it’s still around and had a major revision in 2018.