Information générale
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Network:
Windows 2008 Server
>If it is important that a function returns or changes something different then its value then it's a non good design.
>IOW. If a function just does what is is made for (return a value depending on it's input) no harm can be done by shortcutting.
One example of a common function that has a "side effect" (as part of its implementation) is the pseudo-random number generator function. Each call to the function will modify the seed value. Advantage to this implementation is that you've got repeatability (which of course sounds funny as it seemingly contradicts the usage as (pseudo-)random number generator) for debugging and testing -- you simply start with a specific seed value, then you're guaranteed to have the same sequence of (pseudo-)random numbers being generated. Typical way to "randomize" the values is by using some frequently-changing value as the seed (e.g. the system time).
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement