def find_sqrt(my_list): sqrt_list = np.sqrt(my_list) return sqrt_list new_summed_list = find_sum(listC, listD) sqrt_list = find_sqrt(new_summed_list) You could instead just reuse the addition function and make a separate square root function to perform this task. It will take unnecessary time in writing the whole code again separately for addition + finding the square root. Let’s say there are now two new lists of which you need to find square roots after their sum. The main sense in doing this is that you are making functions that are specific to your own tasks. listA = listB = def find_sum(listA, listB): summed_list = np.add(listA, listB) return summed_list def find_square(my_list): squared_list = np.square(my_list) return squared_list summed_list = find_sum(listA, listB) squared_list = find_square(summed_list) Both these tasks should be separate functions which are later called to calculate the output. find square (I know I am going with a very basic and boring example but it’s to facilitate understanding). It should be broken down into two functions/subtasks: 1. For instance, if you are writing a program to do addition on lists and then finding the square of each element of the list. The software development principle you need to follow is the Separation of Concerns (SoC), which means you have to divide the code into distinct sections such that each section addresses its own separate concern. ![]() ![]() Break down the codeĪlways limit tasks to their specific functions. So, I aim to share my learning in this piece and focus on how to do production-level coding in Python that is more flexible, dynamic, easier to make adjustments to, and reusable for future work. When I started working, there were a lot of flaws in my own coding style and a lot of inefficient coding habits, but I was fortunate enough to receive thorough guidance and learning from highly experienced fellow engineers, who taught me how to structure my code logically. I am keeping it Python-centric but the same practices apply to all coding languages and generally in all software development work. The purpose of this article is to share what I have learned while working on production-level projects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |