| « Prev | Page 1 | Page 2 | Next » |
|
[quote]
...whereas the two latter have been lost to the ages. [quote] Can you lose something you never wanted? |
|
[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." |
|
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"? |
|
I think what scares me is how much this natural progression resembles my first attempt at coding an isometric RPG game.
|
|
Forgive my lack of coffee. I meant to type this:
Function replaceEmp( name ) Dim employee employee = replace(name, "old guy", "new guy") End Function |
|
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 ""? |
One might not be giggling because they're too busy trying to figure out why a parameter was included and never used. ;-) |
|
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? |
|
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.... |
Don't cite dictionary definitions at me. You need to get meta! |
|
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)! |
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. |
|
I hate single letter varibles! Everytime I have to search code for a varible named 'a' I want to scream!
|
|
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! |
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? |
|
Thank god they replaced those inscrutable single-letter variable names with longer, self-explanatory var names like "vlu"! |
Re: Refactoring History
2007-03-26 10:16
•
by
Massif
(unregistered)
|
|
Is that where two-letter commands come from? Are well-named variables several generations down?
|
Re: Refactoring History
2007-03-26 10:22
•
by
rp
(unregistered)
|
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:
|
|
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 |
|
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? |
|
man does this forum software suck!
|
Hmmm... perhaps we need a genetic algorithm to generate good variable names... |
Re: Refactoring History
2007-03-26 10:58
•
by
Jimmie
(unregistered)
|
|
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 |
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. |
We all know that variable names should at least be four-letter-words! :P |
|
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. |
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. |
Head->Desk |
That's how you escape a single quote in a string in SQL. Some DBs will let you use \', too. |
But then you loose out on the Dim employee.
|
|
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. |
Re: Refactoring History
2007-03-26 11:54
•
by
JGM
(unregistered)
|
|
But if you allow ,, to escape , how do you specify an empty column?
|
|
[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." |
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. |
Yes, but a string literal in C isn't enclosed in slashes. I can only guess how horrible a print-my-own-sourcecode program would look in VB. |
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 ". |
The same would be the case if you used, say, "\ " to do a non-breaking space. The XSLT would convert it to a space, so you'd have to do "\\ " instead. And if you had two levels of transformation, you'd have to have "\\\\ ". Not exactly a better solution, eh? The key is to keep the XSLT from transforming the escaped characters on every pass, say through using CDATA. More specifically, through the cdata-section-element attribute of the xsl:output element. I'd provide a complete example, but I don't work in XSLT unless I'm getting paid to do so. |
|
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?) |
|
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. |
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. |
Re: Refactoring History
2007-03-26 13:18
•
by
Jon
(unregistered)
|
|
Still, the old joke goes, "The 'B' in VB stands for 'Beginner'."
([Visual] Beginner's All-purpose Symbolic Instruction Code) |
Re: Refactoring History
2007-03-26 13:25
•
by
no name
(unregistered)
|
They actually make those? And people use them??? Coders???? |
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. |
Now you see, that's a perfect example. What happens when you apply your algorithm to an empty string? And since when did syntax highlighting include replacing escape sequences anyway? |
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. |
Re: Refactoring History
2007-03-26 14:54
•
by
Your Name
(unregistered)
|
Use "vi", then /\<a\>/ finds just that variable, and not the "a" in assert or whatever |
I nominate this as Post-of-the-Day. |
Re: Refactoring History
2007-03-26 15:36
•
by
JoshJ
(unregistered)
|
|
But it would also find "a" in the string sentence "Bob bought a car."
|
Re: Refactoring History
2007-03-26 15:39
•
by
drd
(unregistered)
|
|
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.
|
| « Prev | Page 1 | Page 2 | Next » |