- 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
now i challenge everyone to come up with a finite state automata that recognises only numbers less than or equal to 2147483647
bonus points if you manage it with less tan 30 states.
Admin
Admin
Well, I thought you were up for a rumble. Here are some references to help you understand what I was doing:
http://dictionary.reference.com/browse/humor http://dictionary.reference.com/browse/exaggeration http://dictionary.reference.com/browse/Meow_meow_Matt_Bruce_meow_meow_Henrietta_Pussycat_meow_meow_Presidents_of_the_United_States_of_America_meow_Kitty?
Both. FSAs are very widely used in real apps because they are deterministic, reliable, and more easily proven correct than custom code. You don't use these theoretical concepts every single day of the week in a real world job, but the situations that they were designed to address do crop up very often, and your ability to do your job will be enhanced by having a wide variety of both simple and advanced tools at your fingertips, and the knowledge of which one to reach for in what situation. So you can get by in a real job without having a great theoretical understanding, but you can do better if you do study these heavy CS topics, and if you don't know what they are you won't know when you've run into the situation where there's one that is just right for your needs.In that context, researching (or just playing with) these things in your spare time become part of being professional, like a carpenter sitting at home of an evening cleaning and polishing his tools so they'll perform better next time he's at work. Consider it revision, or homework; you don't have to stop just because you've graduated. It depends on how independently-motivated you are.
If only you had paid more attention in those classes you were talking about, maybe your intelligence wouldn't be so rude and pitiful! Heh, how wrong you were. Have you never heard of a painful joke? Oh, look, you've mis-corrected what you thought was a typo based on your assumption that the entire world is exactly like America. Well done! Yep, that's half the fun! Thanks, don't mind if I do. <puff puff puff>Oh, wait. You said class. My mistake!
Admin
No, that's way more screwed up. You have to pay attention to the quote markers to see who said what. The way I wrote it, I'm interrupting you midsentence and finishing it for you, but I'm still talking from my POV rather than yours. The way you've wrote it, it just doesn't make sense: I see what you've done with the quote marks there, but it still looks like the guy behind the counter is telling the customer to get back to work.
Admin
Admin
Terseness (and indeed re-usability, as in lemmas) is prized by mathematicians. See where this little gem fails?
Computer science (such as it is) leans towards abstraction and separation: in this case, understanding the underlying point of state machines, and the difference between the state machine and the tokenizer. I can't believe I'm about to do this, but, here goes:
I haven't tested it, and I know it won't work. Mens insana in corpore insana. This is, however, more or less the approved approach -- assuming you think the thing was worth doing in the first place, which it wasn't.
Please don't make me code in C again. My head hurts, mildly.
Admin
fsa[1]['w'] is 0, so the new current state would be 0. In state 0, all results are 0. It is therefore stuck in state 0 until the end of the string. Since 0 is not 3, it would return false.
Admin
Admin
Admin
This is another example of people going though University and not learning a single thing. It accomplishes the same as (with less memory):
[code] static bool isArgUnsignedInt(const char *arg){
} [/quote]
Admin
Flying Spaghetti Monster code..? Seriously, it's not that bad!
Admin
Yeah, right, and the empty string is an unsigned, too, while "+1" is not. Moreover, according to your function, unsigned ints do not exists.
University does not look so bad, after all :-)
Admin
I agree with you that empty string would be a problem, but not +1. this function is for Unsigned integers and as such +1 is signed and should be discarded. Also why should i write correct code for others to copy?
Admin
First year student with a question. For this code:
for(; *arg != '\0'; arg++)
Was the for loop used instead of a while loop to save a line of code? Is this okay to do, or would it be considered WTFey? Thanks.
Admin
IIRC, C89 guarantees static variables will be initialized to zero if not explicitly initialized. That's why the uninitialized values will be zero.
Admin
People will complain either way.
They'll complain even more if everything after that is totally and irretrievably broken. Control structures ain't everything. Use for-loops, while-loops, list comprehensions, even goto if you want. Just get the damn thing right.
The WTF is basically everything that happened before that. You do know how to use tokens and isdigit(), don't you?
Admin
Actually, it's worse: ZiggyFish's code never terminates*, except in the case that arg is NULL.
Admin
Its months late of course, but did anyone consider the possibility that the author of this code has a hardware background? Using FSA type models and state machines is of course standard in hardware design and that code looks very much like one converted from VHDL or similar. A decent VHDL compiler would make easy work of those sparse tables and produce a pretty minimal set of logic.
Admin
Yeah, yeah, yeah, how many times do we have to hear that "the compiler can format c:, the compiler can eject all PCI boards, the compiler can get up and tap-dance, etc." for this so-called undefined behavior?!?
Is it not reasonable to expect that the bit pattern used for the signed value will simply be interpreted as unsigned by most (if not all) compilers used?
Dang language lawyers!