Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Questions on good code practise.

Hi,
Any suggestions on the answer for if there are many if statement in the code, how to make it more efficient in rewriting the code.
2. If there are too many constants declared at the beginning of the code , how to rewrite it.
3. Any suggestions for concurrency.

Thanks
SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
Mike McCracken

You question needs more detail.

1.  Can you give an example of code with many if statements?  In some cases it is the way to achieve what you desire.

2.  What do you mean too many constants?  If you need them all in the application and have them defined with good names, there is no problem.

3.  What concurrency issues are you having?
Avatar of RIAS

ASKER

Thanks, Concurrency is two or many people trying to update the same record.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There are static code analysis tools/add-ins that can evaluate the complexity of your code.  There are also linters that can help you adhere to good coding practices, especially with respect to your (variable, routine) naming practices.
1) Any suggestions on the answer for if there are many if statement in the code, how to make it more efficient in rewriting the code.
2) If there are too many constants declared at the beginning of the code , how to rewrite it.

For 1)  After rewriting the code may run just the same - if statements are not necessarily inefficient.  (They might even help the readability compared to a more compact way.  I personally hate code that takes ages to decipher just what it is doing.)

For 2) Just move any constants to before the code they are needed.  (Or consider adding constants together if that is suitable - see how numbers of flags together work such as the READ, WRITE, CREATE... flags when working with files)
Versioning is also a protection to conflicting writes, in-app record rollback as a new version (like Sharepoint or most documentation systems).
Avatar of RIAS

ASKER

Thanks!