Swift's syntax for an obsessive-compulsive disorder under swift spat: infix grammar

Source: Internet
Author: User

Infix syntax is a kind of OC Ritter, which is to add an explanatory word to the arguments of the function, so that the meaning of the parameter is understood when the call is made.

Like what:

-(void) Processdatawithparamaa: (NSString *) Paramaa paramab: (NSString *) paramab{}

When called:

    [Self Processdatawithparamaa:@ "A" paramab:@ "B"];

But you find that, this infix syntax is the premise that you must be in the first name of the function, write a with what the name of a parameter, or the first parameter is not infix.

It does make the call look very pleasing to the eye, [xxxxxxwithparamaa:@ "A" paramab:@ "B"] parameters seem very consistent ah, praise.

So let's go back to Swift, if we declare a function like this

    Func ProcessData2 (paramaa:string,paramab:string) {}

But his call to learn OC's infix, omitted the first parameter, then who will tell me the first parameter what meaning?

        ProcessData2 ("a""b")

As an obsessive compulsive disorder, I can't bear it.

If the language is developed in order for us to adapt to OC's function naming habits (that is, the name of the letter to add a withxxx,xxx is the first parameter infix)

Then I must declare this:

    Func Processdata2withparamaa (paramaa:string,paramab:string) {}

Crouching trough, what a ghost!!

And then call it? There is a wood in the outside of the brackets. There's no sense of paramaa inside.

        Processdata2withparamaa ("a""b")

The OC call function is like this [self processdatawithparamaa:@ "A" paramab:@ "B"]

Both sides are in brackets.

This elegance your swift braces don't learn.

Fortunately, the development of the swift Chris Lattner man, and think of some developers do not like to call the time with what feather infix, so want to add an underscore to omit infix method:

    Func processData3 (Paramaa:string,_ paramab:string) {}

In this way, when the call will no longer need to write parameters, mother no longer worry about me fan obsessive disorder:

        ProcessData3 ("a""b")

Then, Yi? Where does it seem to be wrong? The first Paramaa actually become dispensable (in fact, has always been dispensable), meaning that it can be written like this

Func ProcessData3 (_ Paramaa:string,_ paramab:string) {}

Compilation is possible, but the compiler will prompt you, this is not a standard notation.

This is why ah ...

Leave me a way.

Swift's syntax for an obsessive-compulsive disorder under swift spat: infix grammar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.