Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
My most favorite code sample
Message
 
 
À
16/01/2014 05:49:41
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01591669
Message ID:
01591989
Vues:
45
Depending on the specific situation, (because I don't know what is happening in those various methods), in most cases I create a collection of objects and the code is in each object seperated. If there is data shared between those methods, a controller object can be passed as parameter.

The class names can be structured also using a naming convention that can be used by a factory to instantiate the classes.
Debugging should be done using a logger or error handler that can be passed to the various methods.
LOCAL loLogger AS Logger
loLogger = Createobject("Logger","Logger")
*
LOCAL loMethods AS Collection
loMethods = Newobject("Collection")
loMethods.Add(NewObject("Method1","SomeMethods.vcx"))
loMethods.Add(NewObject("Method2","SomeMethods.vcx"))
loMethods.Add(NewObject("Method3","SomeMethods.vcx"))

LOCAL loOneMethod AS BasicMethod OF SomeMethods.vcx
*
FOR EACH loOneMethod IN loMethods FOXOBJECT
  IF NOT loOneMethod.Execute(loLogger)
    EXIT
  ENDIF
ENDFOR
*
RETURN loLogger.Success
>Such code is only manually hard to debug as entering a specific function is problematic.
>But IF the called functions are nothing but a sequence of functions depending on errorless call of previous like executors of a template pattern
>local llOk
>llOk = FirstFunc()
>llOk = m.llOk + NextFunc()
>.
>.
>llOk = m.llOk + LastFunc()
is IMO better - and if a specific action needs to be done sometimes after error I might use case !Function() as a fall-through structure to reach the Otherwise - but with a little comment added preventing that pattern being abused... 3 lines for each func is wasteful if trying to adhere to 1 screenful of lines >>> 1 method if you sometimes need to code on laptop screens ;-)
>
>>IF ThisFunction() or ThatFunction or TheOtherFunction()
>> .
>>
>>
>
>
>>IMHO, code like that is a nightmare to debug. I hate code like this:
>>
>>
>>IF ThisFunction() or ThatFunction or TheOtherFunction()
>> .
>>
>>
>>Much easier to debug if written like this:
>>
>>
>>llRetVal = ThisFunction()
>>IF llRetVal
>>  llRetVal = ThatFunction()
>>ENDIF 
>>IF llRetVal
>>  llRetVal = OtherFunction()
>>ENDIF 
>>
>>
>>At least if there is a bug in the code you can easily determine which one of the functions is causing the problem.
>>
>>Just my 2 cents...
Christian Isberner
Software Consultant
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform