I\'ve always wondered what other programmers think about the idea of creating pu
ID: 647239 • Letter: I
Question
I've always wondered what other programmers think about the idea of creating pure aesthetic functions.
Say I have a function that processes a chunk of data: Function ProcessBigData. Say I need several process steps, only valid for that data: Step1, Step2, Step3.
The normal aproach I see the most in source code is to write comments like so:
Function ProcessBigData:
# Does Step1
Step1..
Step1..
#Does Step2
Step2..
Step2..
What I usually do, but always felt wrong due to the lack of such coding style by fellow peers is:
Function ProcessBigData:
Function Step1:
Step1..
Step1..
Function Step2:
Step2..
Step2..
Step1() -> Step2()
I am mainly concerned if there any drawbacks for such style in Javascript and Python
Are there any alternatives that I'm not seeing?
Explanation / Answer
It's not as strange as you might think. For example, in Standard ML it's customary to limit the scope of helper functions. Granted, SML has syntax to facilitate it:
I would consider this good style, given that 1) small functions facilitate reasoning about the program, and 2) it signals to the reader that these functions are not used outside of that scope.
I suppose it's possible there's some overhead in creating the inner functions whenever the outer function is called (I don't know if JS or Python optimize that away) but you know what they say about premature optimization.