- 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
"The Year of Our Lord Nineteen Hundred And Seventy Eight" is considerably longer than fifteen characters.
Admin
"Nineteen Hundred and Seventy Two" -- 29 characters....
Addendum 2021-07-27 06:38: (Did not see Steve's comment...)
Admin
Also known as the Y1Q problem.
Admin
sprintf (or your local equivalent) by any other name is YearPadText ... for certain variations of the operand
Admin
Aha ... so TRWTF is:
rather than using val.Len directly in the switch statement? Amirite?
Admin
Now I'm worried about the year 100,000,000,000,000 bug !
Admin
VB.Net: for when you're not worried about the sun going Black Dwarf.
Admin
"An" VB.Net?
Admin
@PrimeMover
Any time I see VB.Net code that's not obviously brand new fresh, I suspect that it's really a port from VB6 and was originally written in VB-about-3. And for sure I think of the possibility the dev who wrote it dates from VB-about-3. Or that the book they learned VB.Net from last year came from way back when.
This coding gem smells to me like it started life eons ago as an If/ElseIf/ElseIf/ElseIf/.../ElseIf/Else construct. Where hoisting the repeated property access into a single access saved in a temp makes sense. In the days before VB compilers, much less optimizing ones, that would need to be done manually by the dev.
Though I do wonder why one would ever need to right-pad a year string out to 15 chars.
Talking about separation of concerns, this code is separating concerns a bit more than most. Even setting aside the inevitable copypasta of the same exact function into different modules, it makes me wonder how many other specialized similar functions there are: FirstNamePadTextLength10(), FristNamePadTextLength15(), LastNamePadTextLength15(), CItyPadTextTo12Long(), etc., etc.
Admin
This fuction takes a string value and expects it to be a year. How do you know it's a year? If you pass in any value that's not a year, God will strike you with lightning and flood your office.
Admin
This code can be greatly simplified:
Admin
My eyes are burning!
Admin
Or for that matter
MMDCCLXXIV Ab Urbe Condita
Admin
Frist thing that comes to mind is they're building a display for a green screen which doesn't have absolute positioning.
Admin
no no no , it's gotta be
Addendum 2021-07-27 12:17: arrggh, with open parenthesis in the right place, of course
Admin
If only VBscript had function to left you easily grab a substring so this could be done in one line.
Admin
If only we had case fall-through we could save a lot of white space in between those quote marks.
Admin
@WTFGuy
It is of course possible that it started as a simple routine to pad a 2-digit (or 1-digit) year out to a string of length 4, then someone decided: hey! That's cool! We can use this to pad out the (whatever field) out to fill a 15-character field! Just need to add a few more options ... rename it? Nah, that compromises the integrity of the codebase, leave it as is.
So you end up with:
... and so on, whatever the syntax of this appalling language is.
Admin
Those who do not learn PRINT USING are doomed to re... using it. (okay, so there's no sprintf equivalent, shush)
And yes, you know that "YearPadText" ended up being re... usinged for everything.
Admin
The fix:
That answers the how, but the question still remains, "Why?"
Admin
nuget install leftpad
Admin
Regarding the why, this is probably not meant to apply padding to the year on itself, but rather providing a spacing to go between a 16-chars max. label and a year in a list view. So the input would be the text label and the year would be printed following to it. Much like a 16-character width tab stop.
Admin
I'm concerned that seeing these code snippets is making me a worse programmer
Admin
Great comment, and I agree that it's entirely possible for correct code to become a WTF with the evolution of the language and porting through language versions.
That said, even going back to QBasic, I think this snippet is a WTF. The usual way to pad strings back in those days was to add spaces, then use LEFT$() or RIGHT$() to grab the required length string. I would expect ported code to look something like
Also Val() has been a reserved keyword since those days too. Using it as a variable name is another WTF.