A curious case
Bob Sneidar
bobs at twft.com
Wed Mar 2 18:03:46 EST 2011
I think the switch control structure is pretty handy for this. If you put all the conditions that will not require a break at the top, then the program will flow down through your conditions and only execute the code inside your case statements if the conditions are true. Towards the end of the switch statement put the conditions that will break when met (if any). It reads much cleaner.
Bob
On Mar 2, 2011, at 2:39 PM, Peter Brigham MD wrote:
> On Mar 2, 2011, at 11:26 AM, Richard Gaskin wrote:
>
>> Andre Garzia wrote:
>>> I tend to work on the same way. longer forms makes shorter understanding
>>> time. I'd rather write more and understand more than write faster and then
>>> one week from now, be completely lost in nested mazes
>>
>> Well said.
>>
>> And sometimes lengthy deeply-nested IFs are good candidates for a switch block.
>>
>> I once stumbled across two tips about code style that have been very helpful:
>>
>> 1. If a given function has nested IFs more than three levels deep, it may be a good candidate for breaking it up into smaller functions.
>>
>> 2. If a function is longer than can be viewed in one screen, it may be a good candidate for breaking it up into smaller functions.
>>
>> Sometimes those can't be applied for sound practical reasons, but where they can oh boy does it make code more readable.
>
> I grapple with this all the time. My status with LC is "dedicated amateur," so I may not use the best practices, but.... One other consideration is breaking out a chunk of code when it needs to be reusable, but this is not without problems too.
<snip>
More information about the use-livecode
mailing list