Strange limitations on script files?
3 次查看(过去 30 天)
显示 更早的评论
Just wanted to clarify: Are there specific reasons to enforce scripts to
- have function definitions only at the end of the file
- disallow classdef in script files
?
This feels especially unnatural in live scripts, where it disallows naturally adding functions or data structures in the course of the document.
1 个评论
dpb
2023-9-22
I have absolutely no inside knowledge, but I would presume the reason is to make the parsing/compilation of code simpler by minimizing complexity.
回答(1 个)
Walter Roberson
2023-9-23
- Not allowing function definitions in the middle of a script file removes ambiguity about whether code after a function definition is there accidentally (such as if there is an extra end in the code)
- requiring that classdef be the only (non-comment) thing in the file removes ambiguity about what exactly is executed when the class is defined or invoked.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!