|
Maybe there is a i++ in some states in the if blocks to skip steps?
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
Nope, the i did nothing else
|
|
|
|
|
How else would he know what step he was at? Now he can simply refer to i in the debugger!
|
|
|
|
|
While a select-case statement would probably be better than the cascaded if/else-if, the illustrated construct may not be unreasonable in certain cases where it is expected that the inside of the loop will be pulled out into a separate routine for use as a state machine. Having the code within a for-next loop may be handy during development while the code is being perfected, even if the final construct will be something else.
To be sure, when running on a PC it's often easier to use threads rather than state machines, but state machines can often have a much lower 'footprint'. If an application will require hundreds or thousands of objects each with a multi-way state machine, and all have to be operable concurrently, a select-case state machine may be a reasonable approach. Delegates should be considered as well, since they have some advantages (but also some disadvantages), but state machines are reasonable in simple cases.
|
|
|
|
|
Wow...
Just wow...
Where in the original WTF did it mention a problem that would require State Machines or Threads to solve?
You've created a mountain out of a grain of dirt.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Tristan Rhodes wrote: Where in the original WTF did it mention a problem that would require State Machines or Threads to solve?
My point was that there are circumstances where code like that illustrated may be useful. While it is true that there was nothing to indicate that such circumstances applied here, I would not wish to condemn code without knowing that such circumstances did not apply.
BTW, another circumstance where such code may be useful is in cases where the loop will evolve into something like:
for i=1 to 5
.. do some stuff in every case
if i=1 then
.. handle first case
else if i=2 then
.. handle second case
... etc
end if
.. do some more stuff in every case
In many circumstances, that style of code could be handled better by putting the different parts into subroutines and just calling them:
everycase_prep()
.. handle first case
everycase_cleanup()
everycase_prep()
.. handle second case
everycase_cleanup()
In some cases, however, the prep and cleanup would need to share many local variables, thus requiring either long parameter lists or awkward class constructs.
|
|
|
|
|
Take brain – Turn off brain – Start coding.
yvind Bratland wrote: We don't work together anymore
Surprise! Surprise!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Of course you two don't work together anymore.
This guy's a visionaire! You simply cannot understand the superior maths under this construction.
Kazz
"Users are there to click on things, not think. Let the archs do the damn thinking."
|
|
|
|
|
yvind Bratland wrote: We don't work together anymore
I bet that's a good thing
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I just found this board, and just had to share...
A programmer had the job of writing a routine to perform calculations based upon fees over time (the detail's not important - essentially she needed to know the number of days between two dates, and apply an algorithm something like 'for the first 30 days, a fee of 10c per day, up to 45 days, 25c per day, from 46 through to 100 45c per day)
Now, there's 1001 ways to do it - but I couldn't believe that she produced a huge Cobol program to do it.
It contained a huge array of constants, called January1984, February1984 etc. etc. etc. wach one being the number of days in that month.
Then she had an
If FromDateMonth = "January" and FromDateYear = 1984
Subtract DateDay from January1984 Giving calcDays.
Else If FromDateMonth = "February" and FromDateYear = 1984
Subtract DateDay from February1984 Giving calcDays
etc.
etc.
for every month of every year for about ten years.
THEN she repeated the same set of If's for the end date.
THEN she repeated the same set of If's, in a loop, for each month in between!
I couldn't believe that any programmer could be quite so dumb! When asked, she just said she couldn't think of a better way of doing it! (Oh, it had taken her nearly two weeks to do - I had estimated a day, and allowed her a week, as she was new to the company, though not to Cobol)
And sure, I should have looked at the code before she got so far - but she wasn't a junior (and she never became a senior)
(Oh and excuse my code - it's been a long time since I did Cobol and can't really remmeber the syntax)
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
maxxx# wrote: but she wasn't a junior (and she never became a senior)
I bet after that she was not even employed anymore, was she? :P
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: I bet after that she was not even employed anymore, was she?
Now she is the boss lover, I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I bet you she is not taking leap years into account.
|
|
|
|
|
Strangely enough she was!
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
It is a good thing she did not try to take into account that years ending in hundreds area not, but thousands are. The control code would have been smaller, but the array would have had 12000 entries.
Silver member by constant and unflinching longevity.
|
|
|
|
|
I'm pretty sure that, given thetime, she would have!
And the actual calc is that 'century years' are leap years when divisble by 400 - so 2000 was, but 3000 isn't
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
It does look like she was trying to be very through, so I am not suprised that she accounted for leap years. What this really points out is that it is not enough for a programmer to be able to write code that works; we also have to be able to come up with fast and efficient ways to solve problems.
Bill
|
|
|
|
|
maxxx# wrote: Oh and excuse my code - it's been a long time since I did Cobol and can't really remmeber the syntax
maxxx# wrote: It contained a huge array of constants, called January1984, February1984 etc. etc. etc.
Dont you mean: JAN84, FEB84 ?
|
|
|
|
|
Probably - though I seem to rememebr a 32 character limit on field names in Cobol - so could have been the full month name and year
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
maxxx# wrote: Probably - though I seem to rememebr a 32 character limit on field names in Cobol - so could have been the full month name and year
I was just making a Y2K joke
|
|
|
|
|
Sorry - me being dense (or you just being too bloody clever!)
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
|
Cobol is horrific anyways
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Here's a gem I found in some C++ legacy Windows code I am starting to have to maintain:
if (hWnd ? hWnd == pWndAppts->m_hWnd : pWndAppts)
pWndAppts->DeleteSelected();
else if(hWnd ? hWnd == pWndNotes->m_hWnd : pWndNotes)
pWndNotes->DeleteSelected();
pWndNotes and pWndAppts are class pointers (the exact specifics are unimportant). hWnd is, well, an HWND.
Note how nothing checks to be sure pWndNotes or pWndAppts are not NULL (until it is too late).
Someone obviously thought they were very clever.
|
|
|
|
|
Yuck.
Tom Delany wrote: Someone obviously thought they were very clever.
Maybe they were some intern trying to be a show off?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|