| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
What's so bad abouth this? Oh... SelMA is copyright infringement, I get it.
|
|
At least he doesn't face the same problems as in http://thedailywtf.com/forums/37391/ShowPost.aspx ! |
|
Clearly the WTF is that he should have used a big 50-level nested IF/ELSE to set the various "sel" variables !
|
|
Should it not have been <%=SelAL%>instead of <=SelAL%> or is that just an error in transcription? [ED: my bad ... I was having difficulties syntax hilighting it and those got chopped off. It's fixed now] |
|
I don't see the problem, he's just separating the application logic from the presentation. I'm assuming that he was planning to move the select into a separate template file.
|
Obviously he had to write the code this way because "DC" is different from "D.C."! |
|
I can't believe they hard coded these. If they change the abbreviations you're screwed. ;^)
|
|
The problem is that this is a horribly inefficient way of going about
it. Let's look at a more efficient way (JScript syntax, because I can't do VBScript): <% I hope you can appreciate the difference in length. |
you missed DC = D.C. |
and the quotes around the state of "..." |
You could make the function dynamic further and use two arrays (display, values) and the selected value, allowing the display names to differ from the values. |
|
This is nothing. I had to deal with code like this that was used to parse XML. There wre a couple dozen booleans: one for each element type. When the beginning of the element was reached, it's corresponding boolean was marked true. When the next text element was processed, the boolean was used to determine where the went in the Object model using is long if-else statement and the boolean was set back to false. Now, consider the case where you have an empty element... The worst part was that this was an API I written by another group in the company. Finally I just said, 'give me the code' and started maintaining it. It was the only way we could get it to work. |
when america splits off into the two nations, "the united states of canada" and "jesusland", this code will be difficult to maintain. especially if the libertarians end up taking over alaska or maine and secede from the union [0]. sorry to bring that up again, btw - couldn't resist. |
|
There are definitely more elegant solutions for this task, but I've seen far worse than that.
|
If Alaska seceded, who will build their billion dollar bridges to nowhere? |
|
ugh. nasty.
Even given the lack of elegance, If session("State") |
I never thought I would say this, but a Select Case would almost be useful here. |
true, but I doubt you would notice the difference on a Pentium 133 or faster. |
On a busy site where this page is hit heavily...I bet you would notice. Why execute 50 session variable retrievals & string (actually variant) comparisons when 1 will do? |
If this busy web site is so heavily hit that you notice the difference, how is it going to do the processing in the next steps? After State selection, there is likely something like: order entry, order processing etc. which will definitely cause much more work than 50 hashtable lookups and string comparisons. |
|
State of the art brillance [:)]
|
|
Oh, I've seen way better code than this. Applying the paradigm from the code I have to maintain, the above sample would look like this: <select class="f" name="State"> .. snip... <option value="WI">WI</option> <script> document.f.value = <%=Session("State")%> </script>
|
|
Actually that should say "document.State.value", but you get the idea.
|
It's not 50. It's 50 x [number of hits]/sec. Anyway, are you actually defending this code? With almost no effort, this could be 50 times more efficient. Are you saying "don't bother"? |
Much more pretty, but (in contrast to the WTF) depends on JavaScript. Some people turn it off for security (and other) reasons. Putting work from the server to the client is convenient but dangerous. |
Actually, I don't think this would work. You'd still have to do the comparison in JS, to find out which option matched, then set the selectedIndex to that one. |
It's 50 for each hit. But for each hit, there will be a lot of additional work. Processing a lot of other input, database lookups, writing something to the database etc. I'm not defending it in a "don't bother" fashion, but compared to the "random generator" of the previous WTF its a minor annoyance. |
How exactly do you think "else if" or select/case would reduce the comparisons to 1? If the cases were evenly distributed, you'd get 25 comparisons on average, by moving more populous states to the front you might get it down to 5 or so. Given the small size of the strings, that might even be faster than the hash-based solution. But speed isn't the issue here, code bloat is. The hash-based solution is the the right way to do it, because it doesn't duplicate code. |
You're right, of course; it won't be reduced to 1, but it certainly would be better. My point is not to fully rewrite it, but to point out that simply by using basic language features, it could be optimzed greatly. There's no question the whole thing should be chucked and redesigned. |
Using the >= operator and nested IFs, you could get it down to 6 comparisons in every case; though it would not reduce code bloat and be less readable. |
|
Oh. My. Dawg.
I now have to go wash my eyes with soap. Damn you! dZ. |
|
They even dedicated the name of CSS class referenced in the select list after their grade on this assignment - "f". |
You forgot the 3rd half: The Unidos States de Mexico. |
LOL, I think it should be called JeebusLand. |
divertido, pero nosotros hay ya |
|
I have seen that exact same code but only JSP.
Of course when we pointed out all the ifs, our JSP 'developer' circumvented the if's by adding.. <select class="f" name="State"> Of course earlier in the code this was put in... String stateValue = session("state") == null ? "" : session("state"); |
He, he, he. FYI: Yo hablo español, pero pensé que sería más divertido para la mayoría de los anglo-parlantes mezclar las lenguas en el nombre. :) dZ. |
por favor, deja de abusar mi idioma. gracias! |
¿A le se permite estar aquí? ¿puedo ver su tarjeta verde? |
ah, muy bien. ayudame entender: porque es que a los latinos le gusta agregar ASCII a los nombres de AIM, ICQ, etc. (fig 12)? todos mis primos en venezuela tienen nombres asi. fig 12: ·#·$2(¯`•._.•·$PENDEJO·$2•._.•´¯)·$1Q |
|
The FreeStateProject already chose New Hampshire. |
dude, are you from brazil? or is this a case of SASL? |
|
Oh, posh. Next you'll be telling me that it's a mistake to hard code every zip code?
It was a lot of work, but by god, it was worth it. |
|
I have seen that exact same code but only JSP.
Of course when we pointed out all the ifs, our JSP 'developer' circumvented the if's by adding.. <select class="f" name="State"> <% if (!session("state").equals("")) { %> <option value="<%=session("state")%>" selected><%=session("state")%> <% } %> <option value>Stateoption> <option value="AL">ALoption> ... Of course earlier in the code this was put in... String stateValue = session("state") == null ? "" : session("state"); |
wtf? El Babelfisho? dZ. |
En mi experiencia, esas mariconadas cruzan fronteras culturales. -dZ. |
Lo hablo como segunda lengua. Puedo mecanografiarla cuando pienso de ella pero no soy muy bueno cuando la hablo. |
USA, I learned some in school but most from a book. I suck don't I? haha |
Hard coding every zip code is not a mistake if you keep a hard coded list of the particular city to which they belong. dZ. |
You're under the impression that a switch/select statement gets reduced to a linear set of "else if" cases. Luckily, you're not the one implementing our compilers, or we would all be screwed. A good compiler usually generates a branch or jump table. Implemented as a binary tree, this would mean O(log n) comparisons. That's 3.9 average comparisons in our 50 states (4 comparisons in the worst case). |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |