Should I indicate no input arguments to a function?
조회 수: 12 (최근 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!