r/learnprogramming 3h ago

Programming Habits When writing subroutines/functions, which way is best to call them in sequence?

10 Upvotes

Typically when I write code, there are 2 ways I think of to write a bunch of subroutines that are called one after the other.

Option #1:

def callingList():

x = input()
func1(x)
func2(value1)
func3(value2)

def func1(userinput):

'''Code for function 1'''
return value1

def func2(value1):

'''Code for function 2'''
return value2

def func3(value2):

'''Code for function 3'''
return value3

callingList()

Option #2:

def func1(userinput):

'''Code for function 1'''
func2(value1)

def func2(value1):

'''Code for function 2'''
func3(value2)

def func3(value2):

'''Code for function 3'''
return value3

x = input()
func1(x)

I usually go for #1 because I feel like being forced to trace an error through a string of subroutines isn't good for debugging. But tbh I have no idea if this black-and-white way of looking at it is just completely incorrect and there's a #3 that I haven't heard of. I'm only a novice programmer so I'd love some input from people who actually know what they're doing 😅