Efficiency of function RRS feed

  • Question

  • Just wanted to ask this,

    is it a good practice to use a function which retrieves data from a database by any means and returns the data concatenated with large chucks of html strings, instead of only returning only the data?

    Yes for loops would be required in some cases in the html page.

    Monday, April 15, 2019 6:44 AM

All replies

  • Hi

    Thank you for posting here.

    For your question, could you describe your problem more clearly?

    If your question is related to html, you could post in the following forum.


    We are waiting for your update.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 15, 2019 9:20 AM
  • Function calls are efficient on modern processors. If you're worrying about performance while you're still writing functions then you're probably doing it wrong. Implement the code using proper architecture to solve the problem at hand. After it is working then profile the code and identify any places where the code is not performing well. Then optimize those cases based upon where the bottleneck is. This is the 80-20 rule. Optimize the 20% of the code that is eating up 80% of the time. Unless you are calling a function 1000s of times in a handful of seconds you won't likely notice any performance hit for function calls.

    As to your use case, each function should be named for what it does. If a function has conjunctions in the name then it is probably doing too much (e.g. GetDataAndPrettyPrint). This is a sign that you should be using separate functions. Each function should do one logical thing. In your scenario I'd say getting data from the DB is a data layer operation so it'd be handled by your data layer which has no connection to the UI. Up in the presentation layer is where you know about HTML so in the presentation layer your controller/presenter/etc would get the data from the DB and then convert that to what the UI needs. If you're dealing with a lot of data then streaming the data or blocking it would resolve any performance issues.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, April 15, 2019 1:50 PM