Java
fromInfoWorld
1 week agoBasic and advanced Java serialization
Order in custom serialization must match exactly to avoid data corruption or deserialization failure.
With pthread's rwlock (reader-writer lock) implementation, I got 23.4 million reads in five seconds. With read-copy-update (RCU), I had 49.2 million reads, a one hundred ten percent improvement with zero changes to the workload.
If there's one universal experience with AI-powered code development tools, it's how they feel like magic until they don't. One moment, you're watching an AI agent slurp up your codebase and deliver a remarkably sharp analysis of its architecture and design choices. And the next, it's spamming the console with "CoreCoreCoreCore" until the scroll-back buffer fills up and you've run out of tokens.
Ever since writing about them, the generator in JavaScript has become my favorite hammer. I'll wield it nearly any chance I can get it. Usually, that looks like rolling through a finite batch of items over time. For example, doing something with a bunch of leap years: ...or lazily processing some files: In both examples, the pool of items is exhausted once and never replenished. The for loop stops, and the final item returned by the iterator contains done: true. C'est fini.
Reference counting is the primary memory management technique used in CPython. In short, every Python object (the actual value behind a variable) has a reference counter field that tracks how many references point to it. When an object's reference count drops to zero, the memory occupied by that object is immediately deallocated.
Imagine you're working with a third-party library that provides a User class. You need to add JSON serialization to it, but you can't modify the source code. Of course you can create a wrapper class or extend it, but that feels clunky and breaks existing code that expects the original type. This is where type classes shine. They're one of Scala's most powerful patterns, and they're the secret ingredient in popular libraries like Cats, Scalaz, and Circe.
Which Algorithm Is This? If you step back, this maps almost perfectly to the Top K Frequent Elements problem.We usually solve it for integers in a list. Here, the "elements" are audience profiles age and body-type combinations. First, define what an audience profile looks like: case class Profile(age: Int, height: Int, weight: Int) What we want is a function like this:
Kacper Borucki blogged about parameterizing exception testing, and linked to pytest docs and a StackOverflow answer with similar approaches. The common way to test exceptions is to use pytest.raises as a context manager, and have separate tests for the cases that succeed and those that fail. Instead, this approach lets you unify them. I tweaked it to this, which I think reads nicely: One parameterized test that covers both good and bad outcomes. Nice.
In 1983 I asked my parents for an Atari for Christmas, instead I got a Commodore 64... Needless to say, I was very disappointed until I discovered how much cooler Wizard of Wor was than Combat. To their credit, my parents thought a computer was a better investment than a video game. I used that C64 through my sophomore year of college until I replaced it with a 486; my first real investment.