I wrote a simple program that accepts input from the user and capitalizes it, obviously this can be done in different ways
class example():
def say_it(self):
result = input('what do you wanna say to the world')
return result
def get_result(self):
res = self.say_it()
return res
def capitalize(self):
res = self.get_result()
res = res.upper()
print(res)
def main():
Ex = example()
res = Ex.capitalize()
if __name__ == '__main__': main()
This program has 3 methods in the class body, then a new instance is created in the main function and only the capitalize method is called and the class does the whole magic and prints out a capitalized in put from the user making the whole main method look very clean
class example():
def say_it(self):
result = input('what do you wanna say to the world')
return result
def capitalize(self, words):
words = words.upper()
return words
def main():
Ex = example()
res = Ex.say_it()
final_result = Ex.capitalize(res)
print(final_result)
if __name__ == '__main__': main()
The second program does the same thing but it has less methods in the class body and more methods in the main method, it calls the methods in the class and works with the results returned, and then the final print statement is actually issued in the main method unlike the first program, thought it looks like the main method could get very confusing when the program expands and grows
My question is this which method will scale better in real life situations (i.e more readable, easier to debug) where they might be like 15 methods, will it be better to just call a single method that does all the magic and gets the result or call the methods one by one in the main method, i sometimes find myself writing programs the first way where i just call one method and the class handles everything else, Also is there any difference in speed between this two programs, which one will be faster?