Comment On zzGeneralFunctions

A codefile whose name is prefixed with “zz” can be one of two things. It's either a file that someone wanted to get rid of but was afraid to delete, or it's an intentional naming scheme to keep the file at the bottom as part of some crude code-organization technique. There used to be a third option - the file's a part of an application commissioned by a certain American rock trio known for their beards and cheap sunglasses - but the band dropped that requirement a long time ago. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: zzGeneralFunctions

2009-04-22 09:02 • by SR (unregistered)
zzFirst

Re: zzGeneralFunctions

2009-04-22 09:08 • by dpm
257256 in reply to 257253
I have nothing funny to say. I just want to bitch-slap the alleged "programmers" who do this, because I've seen it far far too often.

Re: zzGeneralFunctions

2009-04-22 09:09 • by zzFirst1 (unregistered)

Re: zzGeneralFunctions

2009-04-22 09:11 • by snoofle
zzzzz*! Huh? Wha? Did he at least pick one of the duplicated functions and implement the others in terms of that one? At least that way, you can eventually stream edit the code to remove all the duplicity.

Re: zzGeneralFunctions

2009-04-22 09:13 • by Skizz
Still can't concentrate on work.
Currently imagining Charlize Theron and Nicole Kidman making out.
Dammit.

Skizz

P.S. Those coders should be rounded up in a field and nuked from a great height, just to be sure.

Re: zzGeneralFunctions

2009-04-22 09:14 • by Code Dependent
Global search and replace is your friend.

Re: zzGeneralFunctions

2009-04-22 09:15 • by Skizz
The biggest WTF is the file name. Surely it should be zzGeneralFunctionsPluralZAlpha.

Skizz

Re: zzGeneralFunctions

2009-04-22 09:15 • by Anon (unregistered)
I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.

Re: zzGeneralFunctions

2009-04-22 09:19 • by Single User (unregistered)
257265 in reply to 257264
Anon:
I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.

It's for concurrency. If MonthName is already running in another thread, you can fall back on using GetMonthName. Clear as daylight.

Re: zzGeneralFunctions

2009-04-22 09:20 • by monkeyPushButton (unregistered)
257267 in reply to 257264
Anon:
I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.
Well, they probably already had it in their code and this was faster than changing the call in their code. Besides, just this one time...

Re: zzGeneralFunctions

2009-04-22 09:26 • by Razumny (unregistered)
Sing it with me:

I love code'n'roll/so come on do recursion with me
I love code'n'roll/so put another snippet in the GeneralFunctions yeah!

Re: zzGeneralFunctions

2009-04-22 09:33 • by ThePants999
257271 in reply to 257264
Anon:
I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.

I suspect that they copy-pasted it from some crappy website, and then someone else did exactly the same thing.

Re: zzGeneralFunctions

2009-04-22 09:33 • by nonny nonny (unregistered)
Rats, I need to get the month name, but all in upper case. Guess I'm writing another function from scratch.

Re: zzGeneralFunctions

2009-04-22 09:35 • by Cas (unregistered)
The comments at the top should have read:

'Any time you want to do something, check if it already exists in a function here; if so, use that function to do that thing.
'If you do something more than once and it doesn't already exist in a function here, add a function here to do it and replace your existing code with calls to that function.
'If you're feeling crazy, add details of what your function does in a comment at the top. But don't strain yourself.

Re: zzGeneralFunctions

2009-04-22 09:35 • by ThatGuy (unregistered)
What would make this even better is if this was for the National Institute of Health (NIH).

Re: zzGeneralFunctions

2009-04-22 09:36 • by dave (unregistered)
First!!2

nothing like repeating what someone's already said

Re: zzGeneralFunctions

2009-04-22 09:43 • by Slydder
zzGetFirst

Re: zzGeneralFunctions

2009-04-22 09:44 • by BoBThESeXy (unregistered)
It's like trying to recreate wheel. Except the wheel is lumpy, deformed, and irritatingly stupid.

Re: zzGeneralFunctions

2009-04-22 09:47 • by ubersoldat
257279 in reply to 257274
Cas:
The comments at the top should have read:

'Any time you want to do something, check if it already exists in a function here; if so, use that function to do that thing.
'If you do something more than once and it doesn't already exist in a function here, add a function here to do it and replace your existing code with calls to that function.
'If you're feeling crazy, add details of what your function does in a comment at the top. But don't strain yourself.


'Before writing a stupid function, see if it's already implemented by any of our API or libraries, it's probably better than yours'

There, now is complete

Re: zzGeneralFunctions

2009-04-22 09:47 • by Anon Ymous
257281 in reply to 257278
BoBThESeXy:
It's like trying to recreate wheel. Except the wheel is lumpy, deformed, and irritatingly stupid.

And also made of jell-o.

Re: zzGeneralFunctions

2009-04-22 09:54 • by AnyonymousOrSmthing (unregistered)
I'll add this:

'Before writing a new function be really , and I mean really, sure that said function is not stupid, kkthxbye'

Re: zzGeneralFunctions

2009-04-22 09:56 • by Charlie Very Sure (unregistered)
By the time Mark got to zzFormatDate4, he just gave up looking. It was going to be a very long maintenance project.

Yeah, I mean, imagine if you had to add another month to every one of those functions! Kinda like Y2K: miss one and the world falls apart.

Re: zzGeneralFunctions

2009-04-22 10:00 • by snoofle
257290 in reply to 257286
Charlie Very Sure:
By the time Mark got to zzFormatDate4, he just gave up looking. It was going to be a very long maintenance project.

Yeah, I mean, imagine if you had to add another month to every one of those functions! Kinda like Y2K: miss one and the world falls apart.
You mean, like for folks that use lunar calendars? Cuz that never happens.

Re: zzGeneralFunctions

2009-04-22 10:07 • by Marc B (unregistered)
257291 in reply to 257265
Single User:
Anon:
I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.

It's for concurrency. If MonthName is already running in another thread, you can fall back on using GetMonthName. Clear as daylight.


Yeah, but I'm planning on running 10 simultaneous threads, and I'm running out of names:

Thread 1: MonthName
Thread 2: GetMonthName
Thread 3: TheMonthName
Thread 4: GetTheMonthName
Thread 5: MonthsName
Thread 6: GetMonthsName
Thread 7: TheMonthsName
Thread 8: GetTheMonthsName

What do I do for 9 and 10?!?

Re: zzGeneralFunctions

2009-04-22 10:12 • by pseudocode (unregistered)
I tell you why they wrote these. Try and use the VB builtins! They depend on system settings such as the current language of the logged-on user. At least these hardcoded functions produce predictable results!

Re: zzGeneralFunctions

2009-04-22 10:12 • by AnotherAnonymous (unregistered)
#1: Maybe the coder fell asleep while coding it?

#2: Don't be ridiculous. If he had fallen asleep, he wouldn't have typed out "zz", he would have just snored.

#1: Perhaps he was dictating.

Re: zzGeneralFunctions

2009-04-22 10:20 • by Anon (unregistered)
257305 in reply to 257291
Marc B:
Single User:
Anon:
I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.

It's for concurrency. If MonthName is already running in another thread, you can fall back on using GetMonthName. Clear as daylight.


Yeah, but I'm planning on running 10 simultaneous threads, and I'm running out of names:

Thread 1: MonthName
Thread 2: GetMonthName
Thread 3: TheMonthName
Thread 4: GetTheMonthName
Thread 5: MonthsName
Thread 6: GetMonthsName
Thread 7: TheMonthsName
Thread 8: GetTheMonthsName

What do I do for 9 and 10?!?


Thread 9: GetNameOfMonth
Thread 10: GetNameOfTheMonth
Thread 11: NameOfTheMonth
Thread 12: NameOfMonth
Thread 13: ...?

Re: zzGeneralFunctions

2009-04-22 10:20 • by iToad (unregistered)
Maybe there is a company requirement that all new programmers must write their own version of a month name format function, and add it to the file.

Re: zzGeneralFunctions

2009-04-22 10:21 • by shadowman
257307 in reply to 257275
ThatGuy:
What would make this even better is if this was for the National Institute of Health (NIH).


Why?

Re: zzGeneralFunctions

2009-04-22 10:25 • by LightStyx
257308 in reply to 257271
ThePants999:
Anon:
I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.

I suspect that they copy-pasted it from some crappy website, and then someone else did exactly the same thing.

TheDailyWTF better start securing it's code a little better then *wink*

Re: zzGeneralFunctions

2009-04-22 10:25 • by ih8u (unregistered)
257309 in reply to 257291
Marc B:
Single User:
Anon:
I love that MonthName and GetMonthName are identical, even down to the commented out line, which suggests that somebody saw the first function that did exactly what they wanted and decided to copy/paste the function and give it a new name. Clearly they don't understand the purpose of functions.

It's for concurrency. If MonthName is already running in another thread, you can fall back on using GetMonthName. Clear as daylight.


Yeah, but I'm planning on running 10 simultaneous threads, and I'm running out of names:

Thread 1: MonthName
Thread 2: GetMonthName
Thread 3: TheMonthName
Thread 4: GetTheMonthName
Thread 5: MonthsName
Thread 6: GetMonthsName
Thread 7: TheMonthsName
Thread 8: GetTheMonthsName

What do I do for 9 and 10?!?


Generally, you would start with blatant mispellings:
GetTehMonthName, GetTheMothName, etc.

Then you could try using different languages by translating the method name to French, German, Spanish, etc. Just use babelfish.

Also you could use another name entirely:
strcmp, format, JessicaSimpson, etc.

HTH

Re: zzGeneralFunctions

2009-04-22 10:26 • by Code Dependent
257310 in reply to 257305
Anon:
Marc B:
Yeah, but I'm planning on running 10 simultaneous threads, and I'm running out of names:

Thread 1: MonthName
Thread 2: GetMonthName
Thread 3: TheMonthName
Thread 4: GetTheMonthName
Thread 5: MonthsName
Thread 6: GetMonthsName
Thread 7: TheMonthsName
Thread 8: GetTheMonthsName

What do I do for 9 and 10?!?


Thread 9: GetNameOfMonth
Thread 10: GetNameOfTheMonth
Thread 11: NameOfTheMonth
Thread 12: NameOfMonth
Thread 13: ...?
Thread 13: WhatMonthIsThis
Thread 14: WhatMonthIsThis_Yo

Re: zzGeneralFunctions

2009-04-22 10:28 • by Scott (unregistered)
257319 in reply to 257271
ThePants999:
I suspect that they copy-pasted it from some crappy website, and then someone else did exactly the same thing.


Is it just a coincidence that Jeff @ Coding Horror has a blog post about just that? http://www.codinghorror.com/blog/archives/001257.html

Re: zzGeneralFunctions

2009-04-22 10:28 • by Mike H
257321 in reply to 257291

Yeah, but I'm planning on running 10 simultaneous threads, and I'm running out of names:

Thread 1: MonthName
Thread 2: GetMonthName
Thread 3: TheMonthName
Thread 4: GetTheMonthName
Thread 5: MonthsName
Thread 6: GetMonthsName
Thread 7: TheMonthsName
Thread 8: GetTheMonthsName

What do I do for 9 and 10?!?


Don't worry, I've got you covered.


function GetMonthName(thisNum)
'pared down to built-in function for brevity
GetMonthName = MonthName(thisNum)
end function

Dim i, j, funcName, code
code = ""
For i = 0 To 25
For j = 0 To 25
funcName = Chr(Asc("a") + i) & Chr(Asc("a") + j) & "GetMonthName"
code = code & vbCrLf & "Dim " & funcName
code = code & vbCrLf & "Set " & funcName & " = GetRef(""GetMonthName"")"
Next
Next

Execute(code)


Now you have 26^2 versions of the function you can call, from "aaGetMonthName" to "zzGetMonthName".

WScript.Echo aaGetMonthName(1)
WScript.Echo wtGetMonthName(3)
WScript.Echo fwGetMonthName(6)
WScript.Echo zzGetMonthName(5)

Re: zzGeneralFunctions

2009-04-22 10:29 • by Scott (unregistered)
257328 in reply to 257319

Re: zzGeneralFunctions

2009-04-22 10:33 • by Ancient_Hacker (unregistered)
Could be worse.

I've seen apps that do SQL lookups to get the name of the days of the week. Every time.

Re: zzGeneralFunctions

2009-04-22 10:34 • by Sanity (unregistered)
To me, the icing on the WTF is that "on error resume next" is in every single one of those. It seems to me to be a more naive form of this, in Ruby:
begin

...
rescue
# do nothing
end

At least in that code, execution will drop out of the "begin" block on an error. My understanding is that "on error resume next" means execution will continue to the very next line.

Can anyone explain to me where "on error resume next" would EVER be a good idea?

Re: zzGeneralFunctions

2009-04-22 10:36 • by GalacticCowboy
' before adding more comments to this thread, consider
' the implications of including thousands of lines of
' classic ASP code in every page on your site...

' Don't know about you, but it gives me the willies...

Re: zzGeneralFunctions

2009-04-22 10:40 • by Scott (unregistered)
257379 in reply to 257344
Ancient_Hacker:
Could be worse.

I've seen apps that do SQL lookups to get the name of the days of the week. Every time.



That's the equivalent of creating a Excel document in code to add two numbers and get the result. Wow. Reminds me of The FileSystemHashMapNotepadCalculator

Re: zzGeneralFunctions

2009-04-22 10:40 • by Code Dependent
257382 in reply to 257344
Ancient_Hacker:
Could be worse.

I've seen apps that do SQL lookups to get the name of the days of the week. Every time.
Assuming the absence of the built-in VBScript function (and therefore the necessity of rolling your own), a string array of month names would work well:

month = monthNameArray[mNum]

Re: zzGeneralFunctions

2009-04-22 10:43 • by s0be
257392 in reply to 257321
Mike H:


function GetMonthName(thisNum)
'pared down to built-in function for brevity
GetMonthName = MonthName(thisNum)
end function


Sure would be nice to be able to do:

#define GetMonthName MonthName

for those cases, let the preprocessor sort out the ugly details.

Re: zzGeneralFunctions

2009-04-22 10:43 • by Satanicpuppy
See, I love to see that crap. It's a sign that I'm following a half-competent hobbiest, who doesn't know enough of the lingusitic scary tricks to leave good pitfalls.

Nothing more entertaining than coming across a pitfall made by someone with sub-standard skillz...It's kinda cute actually. "Ooooh, da little coder thinks he hid his secret libraries, yes he does."

Spend a day doing search-replace on the code base, and you'll have completely removed a problematic file, made the code more maintainable, and made so many changes you'll look like a god of productivity. It's win-win.

Re: zzGeneralFunctions

2009-04-22 10:45 • by Joe Coder (unregistered)
257394 in reply to 257351
Sanity:
To me, the icing on the WTF is that "on error resume next" is in every single one of those. It seems to me to be a more naive form of this, in Ruby:
begin

...
rescue
# do nothing
end

At least in that code, execution will drop out of the "begin" block on an error. My understanding is that "on error resume next" means execution will continue to the very next line.

Can anyone explain to me where "on error resume next" would EVER be a good idea?


No.

Re: zzGeneralFunctions

2009-04-22 10:46 • by Flash
257395 in reply to 257308
LightStyx:
TheDailyWTF better start securing its code a little better than *wink*


I agree...and FTFY.

Re: zzGeneralFunctions

2009-04-22 10:50 • by rocksinger (unregistered)
257396 in reply to 257270
"
Sing it with me:

I love code'n'roll/so come on do recursion with me
I love code'n'roll/so put another snippet in the GeneralFunctions yeah!
"

that's a WTF right there in so many ways - it does not scan, (still, that never bothered Rush...), recursion != repetition and the lines are the wrong way round for "I love rock and roll...."

but hey, it's actually quite hard to make the thought fit - my best effort is still pretty dire...

I love cut'n'paste/so put another dupe in the functions, baby
I love cut'n'paste/so come an' take your code and paste with me...

Re: zzGeneralFunctions

2009-04-22 10:55 • by Masm (unregistered)
Except that the function already exists in VB, evidently no one wanted to rely on another programmer's code: what if the author of MonthName decided his function had to return the month names in dutch?

Captcha: Aliquam (a lot of functions?)

Re: zzGeneralFunctions

2009-04-22 11:06 • by bjolling
257400 in reply to 257394
Joe Coder:
Sanity:
To me, the icing on the WTF is that "on error resume next" is in every single one of those. It seems to me to be a more naive form of this, in Ruby:
begin

...
rescue
# do nothing
end

At least in that code, execution will drop out of the "begin" block on an error. My understanding is that "on error resume next" means execution will continue to the very next line.

Can anyone explain to me where "on error resume next" would EVER be a good idea?
No.
Yes!
It is the first statement of your error handling block:

'Boilerplate Sub
Sub mySub
On Error Goto mySub_Err
...
Exit Sub

mySub_Err:
On Error Resume Next
...

End Sub

Re: zzGeneralFunctions

2009-04-22 11:06 • by Buddy (unregistered)
257401 in reply to 257351
Sanity:
To me, the icing on the WTF is that "on error resume next" is in every single one of those. It seems to me to be a more naive form of this, in Ruby:
begin

...
rescue
# do nothing
end

At least in that code, execution will drop out of the "begin" block on an error. My understanding is that "on error resume next" means execution will continue to the very next line.

Can anyone explain to me where "on error resume next" would EVER be a good idea?


In VBScript that's all you have.

In other cases, you can put OERN in a single higher level main-like function, the lower level functions will exit on error, and you can check the results of each step in the higher level function. This allows for graceful recovery even of "really bad" errors.

Also, using one OERN in a higher level function can be cleaner than setting up a whole lot of gotos and line labels.

Re: zzGeneralFunctions

2009-04-22 11:11 • by bjolling
257402 in reply to 257296
AnotherAnonymous:
#1: Maybe the coder fell asleep while coding it?

#2: Don't be ridiculous. If he had fallen asleep, he wouldn't have typed out "zz", he would have just snored.

#1: Perhaps he was dictating.
Aaaarrrrggghhh...

Re: zzGeneralFunctions

2009-04-22 11:18 • by Spectre
257403 in reply to 257351
Sanity:

Can anyone explain to me where "on error resume next" would EVER be a good idea?


In VBScript. The only other option (which is the default) is "On Error GoTo 0", which makes all errors fatal.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment