- 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
Loop? Come on get real, a subroutine would be nice.
Admin
It wasn't just the looping that the original coder hadn't learned.
begin
'ToDo - How to assign sctevarS1Name, sctevarS2Name, etc in a loop end
Admin
I'm ... puzzled ... by the mixing of calls to
Concat
and+
for string concatenation...Admin
No, this is Pascal, so it would have to be a
procedure
.;)
Admin
There are also, it appears, a field called 'txtname' and a field called 'txtsname'. I'm sure that's not a bug magnet.
Admin
The dreaded "for-case" pattern would be pretty adequate here.
Admin
Good jorb, guys! You are really worth your dollar per line of codez. Thanks!
Admin
Ideal use case for a for...case structure, no?
Admin
Also nice: use Concat() to concatenate strings, but inside the call to Concat() use "+" to concatenate strings.
Admin
What does "Next" do in Pascal? Also EOF needs a file descriptor, that must be the WTF.
Admin
This (especially the
Next
statement doesn't look like pascal (or any kind of sensible language) to me. It presumably reads a new record from some file into some global variable that is then accessed by theFieldsByName
function. if this is the case then this implicit state held in a global variable would be more of a WTF than the code repetitionAdmin
It looks like this is inside a "With" block. "FieldByName", "Next" and "EOF" are probably part of the object that has been "With"ed.
Admin
There's no reason to assume that, given that there are no traces of the
With
itself. Most likely they are just procedures, either at the top level or nested at the same level as this code.Um.
Procedures that operate on global variables, naturally, since there's no trace of the parameters necessary to make them work correctly otherwise.
And
EOF
is a built-in part of Pascal, a function that returns true if the file it is given (standard input if no parameter is given) is at end-of-file.Note to all readers who haven't ever had reason to work with Pascal: if a function or procedure does not take parameters, when you call it, you do not pass an empty
()
.Admin
Not really that bad, it looks like each block is setting a different higher scoped variable. So a loop would either have code that looks like if itor = 1 set var1 etc.... or everything would have to be refactored to push to an array of some kind.
Admin
Missing punchline: so Andrew reviewed the commit logs, and found that he actually wrote this himself - in is first week in the job.
Admin
I'm just looking forward to seeing what happens on the day when they have five sellers. Maybe they'll turn one away...
Admin
That allows some nice things, like defining something that behaves like a global constant but initializes itself on first use.
Sadly, it also allows for ugly things like things that look like a constant but actually change or depend on mutable global state...
Admin
Unless we're looking at Object Pascal or a lookalike (Turbo>4, Delphi, ...), there are no "Objects" in Pascal. FieldByName looks like a function, and AsString is possibly a field in a record?
Addendum 2022-10-25 03:45: After another look, it can't be a record. Looks like this is not regular Pascal, but some kind of ObjectPascal after all.
Admin
It's Delphi.
The WTF is here that a dev instead of using an array started copy&paste hacks because to lazy for refactoring? Nothing special to see really.
Admin
FieldbyName indicates Delphi dataset / data aware components.
And the code snippet hides the even more ugly "with" construct. Probably a programmer that predates "modern" Delphi (thus learned Pascal before 1995). I don't think it's my code ;-)
Looks like programming by copy and paste ... and it just grew over time. Don't touch old code, just add new code blocks. GIT / SVN / VSS will be very happy about that.
Admin
The reason is
Each record has a unique name. Either
sctevarS1Name
,sctevarS2Name
,sctevarS3Name
orsctevarS4Name
. If only Pascal had some way of subscripting variables, something like