Do not start a script or function by:
This removes all loaded functions from the memory. Reloading them will need a lot of time such that a program can be 100 times slower in a not so unlikely worst case.
I admit that a clear or the equivalent clear variables can help to detect crude typos in names of a variable, if this variable is existing before the script. But this is a really rare case and if a function is used, MLint detects this much better.
But there is a frightening large number of codes starting with clear all. I assume this is recommended in some tutorials which have been written without deeper insight into MATLAB.
2 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/16484-good-programming-practice#comment_36472
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/16484-good-programming-practice#comment_36472
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/16484-good-programming-practice#comment_41337
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/16484-good-programming-practice#comment_41337
Sign in to comment.