|
Are switch statements suddenly considered harmful?
|
# ? Jan 28, 2013 01:56 |
|
|
# ? Jun 5, 2024 07:13 |
|
Either -The programmer doesn't know about them. -They won't work for that situation (incompatible data type, ect) -Language doesn't support them or has a poor implementation (ie Perl) That thing is probably a terrifying combination of all three.
|
# ? Jan 28, 2013 02:10 |
|
Salvador Dalvik posted:Either I'm hoping its auto generated.
|
# ? Jan 28, 2013 03:32 |
|
Maybe that if else chain was generated somehow. If not I'm sure whoever wrote that immediately threw themselves off a bridge. I know that's what I would've done with myself.
|
# ? Jan 28, 2013 03:34 |
|
tef posted:http://nsaunders.wordpress.com/2012/10/22/gene-name-errors-and-excel-lessons-not-learned/ Somewhat topical: http://madhadron.com/?p=263 Do we have a bioinformatics thread in these here parts? We should.
|
# ? Jan 28, 2013 05:24 |
|
kitten smoothie posted:Do we have a bioinformatics thread in these here parts? We should.
|
# ? Jan 28, 2013 06:24 |
|
Pardot posted:look at this code https://github.com/sbrunner/mapserver-tests/blob/master/mapscript/php/layer.c#L269-L326 Wow. It's technically like a giant unrolled loop...but I feel like that wasn't the intention.
|
# ? Jan 28, 2013 08:03 |
|
Pardot posted:look at this code https://github.com/sbrunner/mapserver-tests/blob/master/mapscript/php/layer.c#L269-L326 It used to look like this: code:
|
# ? Jan 28, 2013 11:29 |
|
Given that it's already macro code, why not turn it intocode:
|
# ? Jan 28, 2013 11:38 |
|
C++ code:
|
# ? Jan 28, 2013 16:26 |
|
netcat posted:I'm sure whoever wrote this had a very good reason to not just increment a static variable for the ID, but I just can't see it.
|
# ? Jan 28, 2013 20:03 |
|
ChickenOfTomorrow posted:Are switch statements suddenly considered harmful? That would still be a horror with a switch statement
|
# ? Jan 28, 2013 20:09 |
|
1337JiveTurkey posted:This thread keeps things anonymous for the most part. I think that makes it significantly different from posting something that identifies the author in a public manner. Even if she does improve her coding style the comments will still be there which is unfair to her if potential employers google her in the future. Pardot posted:look at this code https://github.com/sbrunner/mapserver-tests/blob/master/mapscript/php/layer.c#L269-L326 teehee
|
# ? Jan 28, 2013 20:22 |
|
Steve French posted:That would still be a horror with a switch statement Yes, but it'd have fewer tabs.
|
# ? Jan 29, 2013 02:55 |
|
Yes, the macro could be shorter. You can't switch on a string in C.
|
# ? Jan 29, 2013 04:50 |
|
Scaevolus posted:Yes, the macro could be shorter. This is C, the a answer is always more macros.
|
# ? Jan 29, 2013 04:52 |
|
Scaevolus posted:Yes, the macro could be shorter.
|
# ? Jan 29, 2013 05:40 |
|
My god, it's beautiful.
|
# ? Jan 29, 2013 14:59 |
|
I linked that string hash example to a friend of mine and the conversation went something like this: him: "Actually, that's faster than a string comparison." me: "Does the term false positive mean anything to you?" him: "So what if it matches on some random characters too? In the real world that doesn't matter- nobody's gonna type garbage in."
|
# ? Jan 29, 2013 15:07 |
|
Ask him about premature optimization next. Specifically how much processing time is used for command line parsing and also how often it is repeated during the execution of the program
|
# ? Jan 29, 2013 15:14 |
|
I don't think it even makes sense to talk about speed or efficiency for operations on five bytes. If you're working in assembly maybe, but Java is almost certainly going to dump that much inefficiency somewhere.
|
# ? Jan 29, 2013 15:14 |
|
Don't forget that in that example they are hashing an input string, which means they have to walk over each character anyway. It's not even necessarily faster, because in an actual string comparison you can exit as soon as a pair of characters or the size differs.
|
# ? Jan 29, 2013 15:22 |
|
I find that pretty much all optimization is premature. Or maybe "If you think that some operation might be slow, you're optimizing prematurely" My favorite personal fuckup regarding this was long long time ago I was comparing some things, I want to say in Java. Anyway, the list was something like a million items long and I thought that you know, this might be a slow operation, so I'm going to this thing in batches of 10000 or something and then sleep for a hundred milliseconds or so. You know, to keep the system responsive during the huge load. So the program did its thing and it took maybe half a minute to complete. "Whew, good thing I used that sleep there" Then I tried it without the sleep, just process the whole list at once. It took maybe 2 seconds.
|
# ? Jan 29, 2013 15:39 |
|
It seems that worrying about legibility before premature optimisation nullifies the latter problem. Plus you can quote the legible version wholesale if you do require murky optimization code.Internet Janitor posted:I linked that string hash example to a friend of mine and the conversation went something like this: Aww, that's so cute.
|
# ? Jan 29, 2013 16:19 |
|
Internet Janitor posted:Don't forget that in that example they are hashing an input string, which means they have to walk over each character anyway. It's not even necessarily faster, because in an actual string comparison you can exit as soon as a pair of characters or the size differs. Mozilla Rhino (and maybe Spidermonkey as well) does an optimized fast path for builtins. Java code:
|
# ? Jan 29, 2013 16:51 |
|
1337JiveTurkey posted:Mozilla Rhino (and maybe Spidermonkey as well) does an optimized fast path for builtins.
|
# ? Jan 29, 2013 17:05 |
|
1337JiveTurkey posted:Mozilla Rhino (and maybe Spidermonkey as well) does an optimized fast path for builtins. I would hope that the generated code there was done after a thorough analysis of the problem and reduced execution time the most. I'm going to assume that I'm wrong, but I can still hope!
|
# ? Jan 29, 2013 17:05 |
|
See also: the HTTP verb parser in nginx.
|
# ? Jan 29, 2013 18:33 |
|
So how many times has Java changed the String hash function?
|
# ? Jan 29, 2013 18:37 |
kitten smoothie posted:See also: the HTTP verb parser in nginx. Reading that convinces me that it'd be pretty easy to detect nginx servers just by seeing their reaction to sending the first request line a single byte at a time (Insane TCP overhead go!), and making those requests invalid in some ways.
|
|
# ? Jan 29, 2013 19:35 |
|
pseudorandom name posted:So how many times has Java changed the String hash function?
|
# ? Jan 29, 2013 20:03 |
|
pseudorandom name posted:So how many times has Java changed the String hash function?
|
# ? Jan 29, 2013 21:19 |
|
it's a shame murmurhash3 has seed/key independent collisions
|
# ? Jan 29, 2013 21:22 |
|
kitten smoothie posted:See also: the HTTP verb parser in nginx. So what's happening here is it's pre-computing an int/some ints from a list of chars, and then comparing the int to a runtime list of chars, right? So basically you could potentially do a four char comparison in one instruction?
|
# ? Jan 29, 2013 21:28 |
|
ultramiraculous posted:So what's happening here is it's pre-computing an int/some ints from a list of chars, and then comparing the int to a runtime list of chars, right? So basically you could potentially do a four char comparison in one instruction? isn't this literally what comparing to a hash is?
|
# ? Jan 29, 2013 21:39 |
|
Deus Rex posted:isn't this literally what comparing to a hash is? No, they don't actually compute a hash. They just pack the bytes into a 32-bit int and directly compare them as such. The actual comparison probably optimizes into one instruction on most hardware. Edit: or two loads and one compare instead of three or four loads and one compare - something like that. I'm not an assembly master.
|
# ? Jan 29, 2013 21:54 |
|
It checks the length, and then uses macros to check the buffer against n characters by bit-shifting.
|
# ? Jan 29, 2013 21:54 |
|
hobbesmaster posted:I would hope that the generated code there was done after a thorough analysis of the problem and reduced execution time the most. Any browser code path that is traveled by SunSpider (and I'm guessing that one is hit quite a bit) has been profiled and thoroughly analyzed about 17,000 times.
|
# ? Jan 29, 2013 21:57 |
|
tef posted:it's a shame murmurhash3 has seed/key independent collisions But since it is randomized between vm restarts, no non-malicious software relies on specific hash values for things, right? So they could just replace it with SipHash?
|
# ? Jan 29, 2013 22:08 |
|
|
# ? Jun 5, 2024 07:13 |
|
I should have left "barring stupid hash shenanigans" in my post. Java 7 desugars switch(string) statements into that pattern, but it also adds a check to make sure the two strings match.
|
# ? Jan 29, 2013 23:16 |