Ten journalpoints and a cookie to whoever can come up with the best justification for the following code:
TEAM LEAD: Jones, you keep forgetting to malloc() your arrays and we end up with segfaults all over the place.
DEVELOPER: Not this time! I malloc()ed those sons-of-bitches twice!
(
cipherpunk, I am reminded of the infamous "if (j == 17) j = 17;" from the early days of Djinni.)
ETA: Oh, nevermind, it's frickin' 1:30 in the morning and I failed to notice the declaration of Kd as double **Kd[2] earlier in the source, not to mention the subscript in the first line of the for loop. Good thing I hadn't fired it off to the Daily WTF, though really, it wouldn't have hurt anyone to put in an explanatory comment. Subscripts are easy to gloss over sometimes.
for( i=0; i<2; i++ )
{
Kd[i] = (double **)mxCalloc(str1len+1,sizeof(double *));
for( j=0; j<str1len+1; j++ )
{
Kd[i][j] = (double*)mxCalloc(str2len+1, sizeof(double));
}
}I can just see the office conversation now:TEAM LEAD: Jones, you keep forgetting to malloc() your arrays and we end up with segfaults all over the place.
DEVELOPER: Not this time! I malloc()ed those sons-of-bitches twice!
(
ETA: Oh, nevermind, it's frickin' 1:30 in the morning and I failed to notice the declaration of Kd as double **Kd[2] earlier in the source, not to mention the subscript in the first line of the for loop. Good thing I hadn't fired it off to the Daily WTF, though really, it wouldn't have hurt anyone to put in an explanatory comment. Subscripts are easy to gloss over sometimes.
- Mood:
amused


Comments
Problem is, some functions absolutely insist on an array of arrays instead of a normal multi-dimensional. So I can actually see creating a set of 3 a-of-as, calloced. I just can't see making them doubles, unless... badly implemented unicode? No, too obscure...
Graphics! There's a place where you can have excruciating pain... Hardcoding the 3 but not the other two dimensions... Well, them calling the things strings goes back to the unicode theory, but .. it's something that inherently always has 3 attributes. I say it's an array of polygons for rendering, the 3 attributes are dimensions, and the reason for the arse-wise format is underlying graphics library calls.
It's late. I should be asleep. But of course I'm not.
Remember "The Llama Song"? Okay, now did you ever see "The Dalek Song"?
I always wanted to make "The Dalloc Song"...
"Malloc, malloc, FUCK!"
Which was a really long way to go to explain why your code fits so nicely with it... Hope you enjoyed the ride.
A Type I error is a false positive. "Oh, this code is just fine!" the coder says, even while there's God knows how many stack smashes present in the code.
A Type II error is a false negative. "Aaaah! You've malloced those blocks twice!"
A Category error is born from misunderstanding the dimensions of the problem so fundamentally that you are incapable of making real Type I or Type II errors. "Sure, C is a perfectly good language for systems programming..."
The older I get, the more I realize C is an albatross around the neck of systems programming... and such an albatross that not even C++ is much of an improvement. (C++ with an explicit "do not ever use the C subset without a damn good reason" is a major improvement. Unfortunately, most self-styled C++ programmers are really C programmers who are padding their résumes.)
Seriously. C is a language that makes the wrong details clear and obscures the right details. That's why you got dinged there--not because you made a Type II error so much as the fact that C is a Category error.
It took me maybe 3-4 hours, total, writing code that read PCAP files, decoded from Ethernet down to TCP, UDP or specific ICMP, though I cheat and don't check the cheksum, I probably should, but...). Likewise, writing CL code that decoded the data files emitted by cflowd, at a speed that was within a factor of 1.5 of C, took me "a few hours" (I definitely spent more time testing the code, speed-testing and packaging than I did on coding).
I prefer definitions of "fine" that mean "I can worry about the parts of the problem space that need human intelligence and insight, and let the environment worry about all the other crap."
For me, my two preferred languages today are Python and Common LISP. (I started out in the pre-CL days, so forgive me my anachronistic capitalization.) CL has some major problems when it comes to creating distributable images, which means I mostly work in Python.
I used to do Python at work, since it was (in general) faster to get working code than C and (most important) easier for co-workers to maintain Python than CL. The flowd-decoder was in CL, but that was because Python wasn't fast enough (neither on decoding the data nor stuffing ito databases nor doing analysis on the data afterwards). I guess a decent Python-compiler could've done the trick.
Hm. I think I started coding lisp before CL, too (XLisp 1.7, back in 1988-or-so, onoy started coding C in 1990-or-so, but I had pre-existing Pascal-damage).
Hell of a long, strange trip. :)