![]() |
|
[Python] Connecting functions Vs. Handling from main - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Connecting functions Vs. Handling from main (/showthread.php?tid=5874453) |
Connecting functions Vs. Handling from main - ApexLead - Aug 16, 2018 Hello, I recently started to wonder, is it better calling 1 function from main and then call other functions from within it, or make every function return some value to main and decide which function to call next by it (from main)? What is wiser and considered better coding? Thanks in advance :) RE: Connecting functions Vs. Handling from main - koolkid - Aug 16, 2018 (Aug 16, 2018 12:38 AM)ApexLead Wrote: Hello, better coding is totally up to the coder. say for example you have 3 random functions all returning something PHP Code and you wanted to print the largest value you can do it from main which for me would be the best way. however if each function rely on data returned from each other then it would be best to make them call each other and not use main however if you have RE: Connecting functions Vs. Handling from main - hash - Aug 16, 2018 There are a couple of best practices that you should know. A method should only do 1 thing, that's it. If you have your architecture focus on building it in the right way according to software patterns. Afterwards make a class that is a mediator and basically calls the other methods. If you do it like this all the methods can stay the same and if you want to change something you only have to check the mediator. Never put logic in the main, you will have dependency problems later. https://en.wikipedia.org/wiki/Mediator_pattern |