1 hour ago · Tech · 0 comments

Every programmer knows that large problems can be split into smaller subproblems. It is done by combining the code for a subproblem in a procedure or function (or a method if we want to create a class). This has several advantages: It defines a clear boundary for the code which solves the subproblem It clearly defines the inputs (parameters) and the outputs (return value) of the code It allows to use the same code at several places in the code Let’s discuss the problem with a typical example: def main_function(param): #… #(do some stuff to create an intermediate result from param) #… intermediate_result = a * b # some stuff #… #(do some stuff with intermediate_result) #… return result The code in the first part of the function is used to calculate the value of intermediate_result. Nothing else is needed anymore as soon as this code has been executed. We also assume that the intermediate_result is something clearly defined and easy to understand. Then, most programmers would probably…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.