Hi all,
I have a little design question: here's the scenario.
I have to do 'X' function if a condition is fulfilled, otherwise I have to do 'Y' function. Also, 'Y' function split in other 2 cases.
In these functions I have to modify the same table but in different methods (obviuosly
).
the question is: is it better to create three functions for the 3 cases (X, Y1, Y2) or 2 functions and an 'if' statement in the 'Y' function?
EDIT: Moreover, I can also Create 'X' and 'Y' and then let 'Y' Call other two functions...
Personally I think it is a designer's choose, but to be sure I ask you too.
-Mirko-
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
By the way good rule kine, i'll remember it
thanks a lot
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
1) If you have complex code, try to divide it into functions
2) If you have code,which can be reused elsewhere (is "generic" or have specific "inputs" and "outputs" and functionality is not depending on some global variables etc. (outer state of the system)) just keep it as separate function.
But the detail level of splitting of code into functions is on the developer. You know, to have 150 functions with 5 lines of code each is too much, have one function with 150 lines of code can be too much too... :-) but it depends from case to case. 8) Just make the code as LEGO pieces...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
The reusable part is good practice for every developer, even for small bits of code (like GetItem, GetCustomer, etc.), that just makes your code more robust. You make a change to the function and the whole system behaves the same. The readability part is a matter of personal style in my opinion, you will find many different opinions on that.
RIS Plus, LLC
Yes, the "complexity" is subjective and it is on you when you tell that the code is "complex" enough to split it into more functions :-)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.