- 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 (최근 30일)
이전 댓글 표시
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
채택된 답변
Stephen23
2020년 2월 5일
In my experience:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!