Should I indicate no input arguments to a function?
16 次查看(过去 30 天)
显示 更早的评论
Suppose I have a function which requires no inputs. Should I indicate it with parentheses () or leave it naked? Both cases work, but is there a convention in the MATLAB community?
Example:
someFunction
% do sth
end
vs
someFunction()
% do sth
end
1 个评论
采纳的回答
Walter Roberson
2017-9-23
If a function requires no inputs, I prefer to use () after calls to it. It is unambiguous, and saved remember whether the name is a function directly or a function handle (function handles require the () to call them)
2 个评论
Walter Roberson
2017-9-23
If I am creating a function with no arguments then it is most likely because I am answering a question here, tossing together something of no lasting importance. In such cases I usually do not bother to put the () in the function definition. In my own code, I do not typically have functions with no parameters.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!