- 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
Edit 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.
Edit 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.Edit 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.
Edit 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.
Edit 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!! ;)
Edit 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
Edit 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.