programming languages - Use of special characters in function names -
In Ruby, a standard conference method uses a question mark at the end of the name indicating that method gives the boolean Is the result:
[] Empty? # = & Gt; The truth is
There is another standard relation to terminating a method name with a demolition point if the method is destructive (i.e., it modifies the original data):
mylist.sort! #Sortmist In-Place
Recently I have seen these similar conventions used in the plan. Which makes me wonder, do other languages support / support this conference? Are there any special characters that are usually used for the names of these or other languages?
The answer is, of course, language (and language culture) specific.
For example, depending on the language, all of the following are appropriate: empty-p, empty ?, blank, is_empty or empty (these examples are definitely not included).
The examples in the original question come from Ruby, where such use? And! To end the legal name, where appropriate, accepted. This acceptance comes from 1) Is it easily accessible in the form of symbol terminator in grammar 2) use? And! However, it should be noted that in the standard library! Side effects "are not universally interpreted and generally only exist on alternative forms : save / save !, sort / sort, etc. There are several ways in which side- Prefix!
Personally, if I was preparing a language, what would I do? And the symbol names should have valid untraced trailing characters, even though some languages have full symbols like Scala Permission to escape These symbols are usually saved because it is a pain to quote them for the experiment.
In Scala, with special java-compartment, the last form is commonly used. However, // first two are completely legitimate - what is understood in language foo. "" FMM "? Foo.isEmpty
< P> When in Rome ...
- Scala - 'Empty?' Or empty_? (Not normal)
- C / C ++ / JS / Java / Python / Pearl - No? Or! In Identifier; JS / Java $ Permission; $ Perl has a sigil
- C / C ++ / Pearl / JS - Hand in air?
- C # - IsEmpty (method or asset) or empty (property)
- Python - is_empty (But usually __len__ protocol:
if not lane (foo): "empty!"
) - Java - Guide
- Ruby - Special Following? And!
- JS - Indirect Identifier Use: obj ["empty?"] (Not common to this)
- "Lisp" (Traditional): Vicious for blank-p;
Comments
Post a Comment