- files in a private folder are easier to maintain with version control. as each file encapsulates one functionality and can be tracked using standard version managment tools. In contrast putting everything into one file means the entire file gets a new version, even if you actually only change one local function.
- you can easily define a test script/function for the functions in a private directory (of course you should be collecting test cases for your functions, edge cases, failed test cases, etc.).
- local functions are useful when distributing code, it prevents functions from going missing and doesn't scare users who are not used to lots of folders and files hanging around.
- nested functions are very very useful... and can only be defined in the same file!
Local functions vs. private functions
13 views (last 30 days)
Show older comments
I am writing my first real piece of code which I hope to publish some day soon on Git and also it's qualification/methodology in a journal. However I wrote the code to employ functions which I have defined locally at the end of the script file. I am aware that you can also seperately write individual script files for each individual function and call these as long as they are within the same directory/folder. By including the numerous functions at the bottom of my main script file the code is rather long, and I am wondering, for the sake of other people's understanding of the code and for clarity, what the advantages/disadvantages to defining the functions either way are (locally at the end of a file, vs privatley)?
0 Comments
Accepted Answer
Stephen23
on 5 Feb 2020
In my experience:
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!