Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CASE statements
Message
From
24/10/2003 15:50:44
 
 
To
24/10/2003 15:31:12
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00838740
Message ID:
00842435
Views:
49
Jim,

As I told I'm with you in this whole issue. I think you replied to the wrong person, I did not write the return code, as you can see in the last paragraph I kind of critize this code.

I find this thread quite interesting and useful, as it has to do with programming principles, philosophy if you want. And is quite important, more than a lot of programmers think. More than 10 years ago I had to deep into a complete economic modeling system writen in Lahey Fortran for DOS. It took me several months to understand it fully, as I had to understand both the economic and program implied in the code. Just make the math and calculate how much money is that. Poor code costs a lot of money.

The CASE code that originated this thread is a beautiful example for a teacher to show in a classroom trying to stimulate the brain of the students, but in my point of view is bad practice for production code.

Best,
Javier.


>Javier,
>
>My main argument AGAINST the RETURN statement proferred at the bottom is really that code should clearly and simply SHOW THE READER what is going on AND it (all code) should assume AVERAGE/LOW skill level of the (next) reader.
>
>You could also have suggested
IF firstStep() ;
>    AND SecondStep() ;
>    AND ThirdStep()  ;
>    AND FourthStep()
>    lSuccess = .T.
>ENDIF
but I think that your nested IFs, though much more of a pain to type, are the clearest way to write the code.
>
>The above way is, though, clearer than the CASE construct (and even takes less typing).
>
>cheers
>
>>>
>local llSuccess
>>>>
>>>>llSuccess = .f.
>>>>
>>>>*-- I every step is completed, return .t.
>>>>if firstStep()
>>>>    if secondStep()
>>>>        if thirdStep()
>>>>            if fourthStep()
>>>>                llSuccess = .t.
>>>>            endif
>>>>        endif
>>>>    endif
>>>>endif
>>>>
>>>>return llSuccess
>>>>
So basically you are saying that all four Steps need to return True in order for lSuccess to be True. So why not write:
Return firstStep() ;
>>>   And secondStep() ;
>>>   And thirdStep() ;
>>>   And fourthStep()
>>
>>You are right all must return .T., but not at the same time, i.e. as the code in the original CASE statement implies all steps need the previous step to be commited before.
>>In your example, all steps are executed, at that might not be what's intended, they are supposed to be conditional steps. If they are not, then your code is OK.
>>
>>Javier.
Previous
Reply
Map
View

Click here to load this message in the networking platform