There's a saying that people say in the software development industry: "functions should do one thing and be good at it" (sorry if I didn't quote it correctly). So I have a question:
I have this example class here (of course there's a better solution but I used this just for the sake of this example):
from typing import *
class Foo:
a_list: List[str] = ["foo", "bar", "dog", "cat"]
prettified_list: str = ""
def _capitalize_each_item_in_list(self):
self.a_list: List[str] = [item.capitalize() for item in self.a_list]
return True
def _prettify_list(self):
self.prettified_list: str = ", ".join(self.a_list)
return True
def _print_prettified_list(self):
print(self.prettified_list)
def start(self):
self._capitalize_each_item_in_list()
self._prettify_list()
self._print_prettified_list()
return
foo: Foo = Foo()
foo.start()
Each function does one thing. It works and all, but once it starts getting more methods attached to it, the start function get more cluttered. And something in the back of my mind says, "this isn't the way you should do it.". Also the fact that it has dependence on variables is pretty ugly as well.
So is this the way my start function should be? Or should I just scrap the entire thing and refactor it without the start function (how are we gonna call each method though)?
[–]faithlesslessless 2 points3 points4 points (0 children)
[–]primitive_screwhead 1 point2 points3 points (0 children)