Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Single exit-point
Message
De
03/04/2002 10:01:20
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00640316
Message ID:
00640332
Vues:
21
>>I read somewhere that a function (or method) should have a single point of exit (RETURN). Is this considered a general design principle, that should usually be followed?
>>
>>I find that it is more complicated to code a function or method to have a single RETURN, but I also see that it may make cleanup (if required) easier.
>>
>>TIA, Hilmar.
>
>Hilmar,
>
>This is an old, but, IMO, still valid design principle. Not only does it make cleaning up easier, but it also helps in debugging. I tend to follow this practice religiously, as one might ascertain from the contents of the work I've made public.
>
>To speak in very broad, generalized terms, if it is more complicated to apply this principle, it may be indicative that function/method is not as functionality cohesive as it needs to be, and might benefit from re-factoring.

Thanks to all, for your replies.

Next question. Let's say I want to follow this principle (in general, or in one specific method - doesn't matter for this question). If something goes wrong, I have to interrupt. Is there an easier way to do this than maintaining a variable, as in the following sample pseudocode?
local llContinue
llContinue = .T.
(Do Something)
if (something goes wrong)
  ErrorMessage("Problem 1")
  llContinue = .F.
endif
if llContinue
  (Phase 2)
  if (something goes wrong)
    ErrorMessage("Problem 2")
    llContinue = .F.
  endif
endif
if llContinue
  (Phase 3)
  ...
endif

(Cleanup)
RETURN && or RETURN llContinue, to signal success
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform