class MyClass: def __init__(self): self._signature = None def get_signature(self): if self._signature is None: self._signature = self.peek_register(SIGNATURE_ADDR) return self._signature We’ve all seen this code before. You have some getter that you want to return a value, but it’s expensive/inconvenient to initialize, so you cache it. You don’t want to do it when you make the class, maybe because not every class ends up needing one, maybe because it’s difficult to initialize in the constructor.
Continue Reading
Okay, so first off, floating point numbers are the worst and you should never use them.
But if you are, they say programmers should be aware of coercion rules. “ints promote to floats”, they say. “And floats promote to doubles.”
You probably had to go to a school and pay money for somebody to put that on a slide so that you could forget it and look it up later. So look at this code:
Continue Reading
Okay, finally, we’re going to talk about something other than errors. This is the story of how I destroyed $25,000 of company property and got a pat on the back for my efforts.
Or at least, I haven’t been fired.
It’s not clear to me how to describe the code. Maybe this?
It’s hard to portray “I deleted 1,700 lines of code.” But that’s what I did: I deleted 1,700 lines of code.
Continue Reading
Last time we talked about errors. And though I’m loath to think about anything for longer than a week at a time, errors are so core to our existence as developers that I feel we must talk about them.
(obviously, they’re core to your existence, my code has no bugs and therefore never errors)
In particular, I want to tell you the story about this error:
Error Code: -1074114855 For context, these days at work I’m playing a bit of customer support for a customer using a beta product in Japan.
Continue Reading
The astute reader may have noticed, I pulled a fast one in the last blog post. Last week, we replaced this code:
if (regex_match(portIterator->second, boost::regex("0*([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]);"))) { ... } with this:
const int port_no = std::stoi(portIterator->second); if (port_no <= 65535) { ... } and we sort of left it at that, and moved on to other things.
But these code pieces actually aren’t equivalent, for two reasons. First, stoi will accept a negative number, so the condition should be: port_no >= 0 && port_no <= 65535.
Continue Reading
Dear Candace,
You have sent me three links.
The first, https://www.bitchute.com/video/nFMwCaApptoe/, is a link to an English conspiracy theorist.
The second, https://www.bitchute.com/video/xwSVyw5jbdzH/, is a link to an American antivaxxer.
And the third, https://rumble.com/vbortj-covid-vaccine-changes-dna-and-has-aborted-fetal-tissue.html, came with a condemnation that I’m not thoroughly watching your videos, I’m just dismissing them. You say I’m not researching, I’m just talking down the info you have posted.
But here’s the thing. I’ve already done my research.
Continue Reading
if (regex_match(portIterator->second, boost::regex("0*([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]);"))) { ... } if you look at it hard enough, you can tell what the regex does. But, if you’re not familiar, it comes with the comment:
// check the RPC port number which is an unsigned 16-bit integer. The value ranges from 0-65535 (also, I highly recommend the website regex101.com, if you don’t have it already bookmarked)
Obviously, regex isn’t anybody’s first choice to see if a number is an integer.
Continue Reading
It’s a point that I have, and will continue to, drive home on this blog: In professional software engineering, code readability is paramount. Its importance is second to none.
When you’re evaluating a language, especially, it’s important to consider more than just whether the programming language is turing complete (or, more generally, whether it can do all the things you need it to). You should also consider how conducive the language is to being read or reviewed.
Continue Reading
So I was working on some driver code for a device the other day, and came across this interesting bug. The device has a clock rate that a user can specify, they can choose from one of several options (call them 10MHz, 11MHz, 40MHz, and 44MHz). The user can also pre-configure a “multiplier” option on their device (by loading a different FPGA bitfile), which has two options: x1 and x4. As you might’ve guessed, the 10MHz and 11MHz selections only work when the multiplier is set to x1, and the 40MHz and 44MHz options only work when the multiplier is set to x4.
Continue Reading
I’m going to break from my usual style (again) and go for a more ranty style with more blatent product placement.
If you like this kind of content, remember to smash that like button and catch me live over on Twitch. (I’m just kidding, I don’t blog or program live on Twitch, although maybe I should?)
Anyway. C/C++ includes. Love them, hate them, but we’ve all seen (and written) code like this:
Continue Reading