Options Paremeters Arguments Flags

在不嚴(yán)格的情況下,parameter和argument是可以混用的。
Java或通常的編程語(yǔ)言中,parameter指代函數(shù)聲明中的變量;而argument指代函數(shù)被調(diào)用時(shí)傳遞的實(shí)際輸入。
在Shell或命令行中,argument的含義和Java是類似的,指代調(diào)用或運(yùn)行時(shí)的輸入值。但parameter的含義有點(diǎn)晦澀和不實(shí)用。若干結(jié)合option,一個(gè)簡(jiǎn)單而實(shí)用的區(qū)分是:argument是統(tǒng)稱,option是--或-開(kāi)頭的argument,而parameter看成option的值。

There are no consistent definitions of the terms "option", "argument", and "flag", and there is no central authority within the software development world that could enforce their usage. This happens with much terminology: after 30+ years of using the word "directory", I now have to deal with people using the word "folder" who have been confused by Microsoft's new-speak.
There are different ways that consensus definitions for terms can come about in programming. In the case of "argument"/"option"/"flag", canonical manuals and tutorials for programming languages have helped to enforce usage, as has the terms used in common libraries.
For instance, the things you put on the command line after a command are often called "arguments" to the command, by analogy with arguments to a function call, and this is probably partly because they are called "arguments" in the C manual (hence argc and argv). The argparse Python library also helps to enforce the term "argument". However, I have also seen them being called "parameters".
The term "option" is derived from "optional", which implies they can be left out. The getopt C library is one use of this term. But there is precedent for "options" that are not actually optional: for example, the argparse manual states that one can create a "required option" (although it also says that this is "generally considered bad form"). Options are often preceded by a single (-) or double (--, long-option) dash, but there are well-known commands that do not require or enforce dash usage for options (e.g., tar, ps, and dd). An option can itself take an argument (e.g., -w80 and --color=always), or occasionally multiple arguments.
"Flags" are, in my experience, the same as options, but usually do not take arguments themselves and essentially represent boolean on-off switches.
On a broader note, since every programmer has the option to try and look up some standard way of doing things and naming things, but can also reinvent the wheel without much extra cost, naming is never going to be consistent. And once you have documented your code, and it is clear what new meaning you have given to these words by giving examples, those names and meanings might just stick if there are enough people who pick them up from your code.

參考

argument、parameter以及option有什么區(qū)別?

Linux中命令選項(xiàng)及參數(shù)簡(jiǎn)介

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容