- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Well, frist of all, if you're looking for a string representation of a contiguous netmask(1) based on a prefix length, it probably is faster to just look it up in an array of pre-formatted strings...
(1) No, the strings in the array are not subnets. ("Subnets" as a general thing arguably became obsolete with the introduction of CIDR way back in the way back.) They are dot.te.dqu.ads that represent the masks you can use to extract the network number from a complete IP address, i.e. netmasks.
Admin
I smell a different WTF here.
$var = @("list");
isn't valid Perl- at least not in the last 15 years that I've been using it. The '@' sigil is used to dereference a name as an array. That won't work for anonymous lists/arrays.Admin
Yea, but who cares? That's the whole point, implementing this in a way that no one can see if this is some list of network id's that follow a pattern, or if it has been manipulated in some way. Readability and maintainability are far more important than execution speed in almost all network management scenarios.
Admin
Ever hear of
new line
characters to
make your comments
readable?!?
Addendum 2025-06-18 09:55: Whoops! I was trying to use hash characters at the beginning of each line... and I made a rather different point than I intended.
Admin
# Ever hear of RTFM for the formatting system used on many messageboards?
Now let's see if I got this right the frist time. 3 ... 2 ... 1 ... {wince} [Submit]
Addendum 2025-06-18 10:26: Yaay!! ;)
Admin
Fixed that for them:
Looking up a value in an array was faster to code than any mathematical solution.
Admin
As one currently on the job hunt, I gripe all the time about the prevalence of "DSA" interviews and Leetcode, because they focus on exactly the wrong things. Who cares about the big-O of your function if it's an unreadable mess of cleverness with all kinds of nasty side effects?
I can just see this guy bragging "Yeah, I reduced this function from O(n) to O(1). Aren't I awesome?"
Admin
Not you, obviously, and not me either, to be honest. I'd take the hit on the time necessary to calculate an appropriate-valued integer type and then format it.
In C/C++, I'd calculate the not-yet-formatted uint-ish value as
(uint32_t)((~(0xFFFFFFFFULL << prefixlen)) & 0xFFFFFFFF)
, which admittedly isn't exactly clear, but does the work necessary. And yes, it would be ffffffffull of unreadibility. The primary sin of the code in the article is calling the values for netmasks by the name "subnets".Admin
if this was a better language i would just generate the list with consteval/comptime dont need to worry about trading readability for speed
Admin
Ever heard of Disqus? If your forum system needs a manual (yes this system NEEDS a manual) for people to be able to use it... that's a WTF right there... It's a FORUM system!
Addendum 2025-06-18 14:23: no, I will never reply to any replies. I don't even know where to find any updates... I don't even know where the G-D manual is.
Admin
People are being quite #### in this thread.
Admin
Can people stop listing things on the same line like this? Newlines are free
Admin
After 15 years coding in Perl it's a wonder you're still able to smell anything.
Admin
I wonder if the comments were directed towards colleagues, or their own internal voice?
Admin
What M? :-)
Admin
We have two possible failure modes here:
Something in the list is wrong.
The code to generate the list is wrong.
Which is easier to spot?
I generally favor pre-calculating small, fixed lists. Generate anything too big to easily eyeball.
Admin
I think Kenn is right. The coder probably meant that it was faster to copy/paste the IPs from somewhere where they were already in this format an make a manual list than to write code to generate the list.
Admin
It's a far better language than some people give it credit for. But the fact of the matter here is that this is invalid code and won't run at all.
is a syntax error, plain and simple. It's one thing to post bad code, it's another to post something that won't even compile/run.
Admin
OTOH, this would be the exact kind of person to use the formula for "is this integer of the form
1*0*
" they found in Knuth so they could lord it over anybody who raises a question about it.Admin
What really gets me about leetcode is that the optimal solution for the trickier problems is usually incredibly fragile: if the question changes just a little, that optimal solution needs to be thrown out and practically rewritten from scratch. Leetcode teaches you to write fragile code.