Design question

Belias
Member Posts: 2,998
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.
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.
0
Comments
-
All depends on possible reuse of each method as separate function and on complexity of the functions. If they are creating one atomic functionality, where parts cannot be used separately, just use one function with case of if statements. If you can use each function separately, create special function for each. 8)0
-
it's not an absolute rule i think because, as you say, it depends from the complexity too and sometimes you need to create a function only to make the code clearer..(or more clear? :roll: )
By the way good rule kine, i'll remember it
thanks a lot0 -
Yes, it depends. Priorities are these (for me):
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...0 -
For me the decision to write a function is mostly whether the code is going to be reusable. It has to be a pretty large chunk of code to make me want to write code bits into a function. To make larger chunks of code more readable putting short comments in there is much more effective to me.
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.0 -
DenSter wrote:For me the decision to write a function is mostly whether the code is going to be reusable. It has to be a pretty large chunk of code to make me want to write code bits into a function. To make larger chunks of code more readable putting short comments in there is much more effective to me.
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.
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 :-)0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions