- 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
[quote] ...whereas the two latter have been lost to the ages. [quote] Can you lose something you never wanted?
Admin
[quote user="bstorer"][quote] ...whereas the two latter have been lost to the ages. [quote] Can you lose something you never wanted?[/quote]
Yes. " 14. To cause to be destroyed. Usually used in the passive: Both planes were lost in the crash."
Admin
Interestingly enough, similar excavations turned up a rather special end result to all this, expressed best through the use of code.
Function replaceEmp( name )Dim employee employee = replace(employee, "old guy", "new guy")
End Function
Even if you hate VBScript, how can one not giggle at "Dim employee"?
Admin
I think what scares me is how much this natural progression resembles my first attempt at coding an isometric RPG game.
Admin
Forgive my lack of coffee. I meant to type this:
Function replaceEmp( name )Dim employee employee = replace(name, "old guy", "new guy")
End Function
Admin
A Refactoring Conundrum
...but if you lose:
If Session("Reprint") = "" Then Session("Reprint") = "" End If
then how will Session("Reprint") ever get set to "" if Session("Reprint") is equal to ""?
Admin
One might not be giggling because they're too busy trying to figure out why a parameter was included and never used. ;-)
Admin
WOW..... just..... WOW.
When I write programs, I allways tell myself.. "There isn't any other easy way?"...
seems that the programer at the snippet didn't question himself very often.
What the hell is Gygax?
Admin
Gary Gygax is the inventor of D&D, and many other roleplaying games.
Or, it could be refering to Daniel Gygax, a Swiss football player....
Admin
Admin
yeah, basic string manipulation should have been tested before this joker was hired...
If you hire someone who's LEARNING the skill set(s) required for the job, you should know beforehand (well, if you expect to make any money)!
Admin
But you make your money on the fact that you're paying the guy far less. Of course, if you're a company dumb enough to overpay for an employee with no experience, you get what you deserved.
Admin
I hate single letter varibles! Everytime I have to search code for a varible named 'a' I want to scream!
Admin
The dumb employee gets to train on the job and gets a paycheck.
The company hopefully gets to pay him what he's worth (very little). They presumably get code that still works. The manager doesn't care how crappy and inefficient it is. It's not like he has to maintain it.
We get to see more stupid code.
It's a win-win-win situation!
Admin
I love my single letter vars, they go on little single letter dates and have single letter sex creating nice multi letter vars. Where do you think well named vars come from?
Admin
Thank god they replaced those inscrutable single-letter variable names with longer, self-explanatory var names like "vlu"!
Admin
Is that where two-letter commands come from? Are well-named variables several generations down?
Admin
I'm not quite sure whether you're serious, but I hope you are.
The trouble with refactoring is the hidden landmines (i.e. people don't document the invariants their code relies on). In this case, a string can compare equal to "" without actually being the same as "", for instance, when it's a null reference (Nothing in VB.NET), and then be passed to a piece of code that depends on such strings actually being the same as "". Try this at home:
Admin
I'm pretty sure you need a return value for a function
Function replaceEmp( name )
Dim employee employee = replace(name, "old guy", "new guy")
End Function
should be
Function replaceEmp( name )
replaceEmp = replace(name, "old guy", "new guy")
End Function
Admin
I dunno, the OP is using the word "refactor" in strange ways I've never heard before.
Refactoring, as I understand it, is a developer tool used to keep code from getting to exactly the place this example arrived at. What do managers have to do with refactoring?
Admin
man does this forum software suck!
Admin
Hmmm... perhaps we need a genetic algorithm to generate good variable names...
Admin
ASP/VB is in major need of just one little thing...
BRACES!!!!
Wend?
End Function?
End If?
OMG! That kind of coding structure is sooooo 1980!
the real WTF is the VB syntax
Admin
Depends on your context. To a programmer, refactor means to fix the code, which in the end of the article it was refactored in this fashion. To a manager, refactor means to upgrade or add functionality. It is a danger of us techies using our language to explain something to non-techies.
Admin
Admin
Am I the only one who thinks that escaping quotes with a pair of quotes in quote-delimited strings is a bit stupid? I don't usually bash languages I don't know, but jeez.
Admin
That actually is the best way to escape anything unless you want to build all kinds of rule exceptions. Even C does this with the \ character; if you actually want it, then escape it with itself.
For a real WTF, just take a look at the CSV format and find out how it wants you to escape things and decide how easy it would have been if they had just allowed ,, to escape the ,. The problem is this: You want a comma in your data, encase your data in quotes. Now you created a new problem, what if you want quotes in your data? You have to escape those now. Always easier to allow your delimiting character to escape itself or you are simply adding new delimiters.
Admin
Head->Desk
Admin
Admin
But then you loose out on the Dim employee.
Admin
http://www.waterfall2006.com/Refuctoring.pdf :D
Admin
I'm guessing this is a typo..
Function CheckString(s) p = InStr(s, "'") While p > 0 s = Mid(s, 1, p) & "'" & Mid(s, p + 1) pos = InStr(p + 2, s, "'") Wend CheckString = "'" & s & "'" End Function
because if this code is run as above, it'll get stuck in an infinite loop.
Admin
But if you allow ,, to escape , how do you specify an empty column?
Admin
[quote user="bstorer"][quote] ...whereas the two latter have been lost to the ages. [quote] Can you lose something you never wanted?[/quote]
Mona Mayfair: "I didn't lose my virginity. I obliterated all traces of its existence."
Admin
Well true. But you should have one escaping character and use it everywhere even when escaping itself. I admit my example was off the mark but it does show part of the problems with not defining an escaping character. There are other formats that come to mind, VB and SQL handling things in a similar fashion while C uses \ and \ to escape the escape character.
Then XML comes to mind where there is no easy way to place a & in a field that needs to be parsed by XSL then used in the resulting HTML. For example you want to have a non-breaking space so the final HTML needs to show but the XSL transform will escape it out to a space on it's own leaving you with literally a blank that might not get rendered so you have to encode this in the original XML as such: . This means you have to know how many transforms you are going to go through from the begining before you can encode it properly. Got another level to transform through, then you need to encode it as such:  
Things just get hairy when you don't have a good escaping format.
Admin
I can only guess how horrible a print-my-own-sourcecode program would look in VB.
Admin
The only real problem there is if you were doing syntax highlighting. As all lines would be read in as strings already rather then you trying to build the string you need not worry about the " character, it is already contained in the string.
What you do have to worry about is when you are doing syntax highlighting you need to look for " and read ahead one character to see if the next one is also a ", if it is print just one, if it isn't back up and change text color and move forward again. At least with C you know when you reach a \ you simply print the next character knowing it is still part of the string itself. You don't stop highlighting your string until you reach a lone ".
Admin
Admin
The fact that a good majority of the "code WTFs" are in VB doesn't help my opinion that VB is an inferior language. :P
(catpcha: onomatopoeia -- come ON... if a captcha decoder script can read 5 letters written as normal text, what makes you think it can't read 12...is it necessary to make me type long words?)
Admin
Using quotes to escape themselves is not readable - that's the problem. It's pretty hard to look at a bunch of quotes stuck together and know exactly what they represent.
However, slashes are extremely easy to count. They only start to get ridiculous around 6 or so, and really how often do you encounter that many? The most I've ever been forced to use (due to ajax and passing special strings back and forth) is 8 (\\\\), and that's a hell of a lot easier than reading """""""", especially if your text editor doesn't use a monospace font.
Admin
It isn't that VB is an inferior language, it is rather that inferior programmers tend to work more in VB. This does not imply that the reverse logic is true, meaning that just because you work in VB does not mean you are an inferior programmer; you just have a higher probability of working with one.
Admin
Still, the old joke goes, "The 'B' in VB stands for 'Beginner'."
([Visual] Beginner's All-purpose Symbolic Instruction Code)
Admin
They actually make those? And people use them??? Coders????
Admin
Yes they still make slashes. They were going to stop production of slashes thinking that only mathematicians used them and by their calculations there should have been a surplus for decades; then us coders spoke up and started using this untapped resource in mass quantities. Since then, instead of stopping production, they have had to increase production seven fold.
Oh wait, you were talking about mono-spaced fonts, sorry.
Admin
Admin
Yeah no replacements, see I'm not perfect.
But empty strings are handled easy, because you have to actually be in the string before you can escape it.
Hit the first quote, we are not in the string yet so start highlighting Flag it now as in string.
Next character read in. If it is a quote and PriorQuote is true keep highlighting and set PriorQuote = !PriorQuote. If it is not a quote and PriorQuote is True stop highlighting and flag it as out of string. All other characters, set PriorQuote to false and keep highlighting.
Admin
Use "vi", then /<a>/ finds just that variable, and not the "a" in assert or whatever
Admin
I nominate this as Post-of-the-Day.
Admin
But it would also find "a" in the string sentence "Bob bought a car."
Admin
Even easier, (assuming by 'vi' you mean 'vim'), just move your cursor to the 'a' token, then type *. You'll get the word-boundary restrictions automatically.