- 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
Uhh, I was commenting on whether I can use String vs string as a type name in C#. I'm not ignorant about C# although I will say I give a rats ass about Java and it can go to hell. Double that sentiment once Oracle took over.
Admin
Honestly, I can see code like this being used in certain edge cases. Sure, you'll never be able to go beyond 12, but some cases might require this kind of code.
I'd use this code if I wanted to sacrifice memory usage and cpu usage for readability. (The overhead involved in the strcat within the loop is bad.)
This is the sort of algorithm I'd use if I wanted to sacrifice readability for memory and cpu usage. This is probably the type of algorithm that comes to mind when you see a WTF like this.
You normally think that this type of code is a joke. However, in a production environment where cpu and memory usage is a serious concern, you can sacrifice adaptability, maintainability, and space on disk for that little bit of cpu gain that you get from using a jump table instead of a for loop. This also doesn't have the overhead of the strcat function, making it a better option, cpu-wise, than the first one.
Even so, I've never been in an environment so performance-intense that the first or second option wouldn't be better. I'll take readable code over code that's a few nanoseconds faster any day.
Admin
@antiquarian, can we get a rating on this one?
Admin
I imagine the gains would be so inconceivably small when padding to 12 that there's no point in using an algorithm like this, but if we were padding to, say, 600, it might be significant.
Admin
The biggest (and probably dominant) loss in that scenario would be from the code itself being larger…
Admin
What are you talking about? I thought jump tables = magic!
Admin
Admin
PHP TO THE RESCUE!
There. Best language ever. We can all go home now.
Admin
Notice that “!” there? Jump tables aren't just magic, they're magic factorial and so need quite a bit of room to store.
Admin
Note that he doesn't actually say there could be a better way to do this, but that there is a better way to do this. He (or maybe she) knows full well what they are doing and that it is terrible. Perhaps management told them something like "Do this that way or else" or "We need more lines of code, that way is too short"?
Admin
Fuck, Remy, learn to spell "led." It's only three fucking letters.