Which one's is the best practice ?

shankar25_12_82shankar25_12_82 Member Posts: 45
Hi All,

I'm writing a piece of code in which there is some condition & then i'm inserting the data into a table using a function,say Func(). This is one way of doing it ..Now other way could be -- by directly calling that function Func() & writing the code inside the function directly.
My question is which is better way of doing it /Best Practise ? Also which is best as per the system performance is concerned. Waiting for your valuable inputs.

Regards,
Shankar

Comments

  • krikikriki Member, Moderator Posts: 9,110
    For performance, it doesn't change. Calling a function is something about nanoseconds (or at worst microseconds) an you're working with a DB (that works in milliseconds). So calling a function and doing the test or not calling it because the test is before calling the function doesn't change.

    My preferred way is to call the function and do everything in there.
    It is more logical: in this way you can keep the calling code more readable.
    In case you would have a "monster" of a test to do and you put it in the calling code, it would be less readable.
    Also you have to consider something about functions: A function must do something for you (if needed). The same happens in the real world: If you ask a person (the function!) to do something for you, you are not interested if he actually had to do something (unless you have to pay him for it) or just to control if it was necessary to do something. You are only interested that he comes back to you saying:Done!
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • diptish.naskardiptish.naskar Member Posts: 360
    If before entering the data into the table it needs to satisfy some condition then it is quite logical that you satisfy a condition before inserting the records in the table, if you have do directly insert then obviously the ececution of the program will not get into the codes of condition and will directly insert.

    It hardly matters in this case which is the best practice, as this is more to do with the logical way.
    Diptish Naskar
    For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
Sign In or Register to comment.