Will it be slower to place functions' defintions inside a main function?
I usually do that if the subfunctions are short.
However, with a long subfunction I usually place it outside as I think that would make it easier to read and run faster.
Now I want to do it as the first method below as I want to make it self-contained and easier to manage when I do copy-paste and re-use.
If I place them outside, I usually miscopy some functions and make it not running properly. But I'm worrying if it's slower and harder to read.
I understand about the local/global effect but I want to focus on the speed and readability here.
Method 1:
Place function1
and function2
inside the main function.
myFunction[parameters_] := Module[{},
function1[parameters1_] := Module[{},
(* a long function*)
do something here
];
function2[parameters2_] := Module[{},
(* a short function*)
do something here
];
(*use function1 and function2 to do something more*)
]
Method 2:
function1[parameters1_] := Module[{},
(* a long function*)
do something here
];
function2[parameters2_] := Module[{},
(* a short function*)
do something here
];
myFunction[parameters_] := Module[{},
(*use function1 and function2 to do something more*)
]
myFunction
, or to specifically not be visible? With the above construct they're definitely visible outside. $\endgroup$