Recommendations for definition of Swift functions

Source: Internet
Author: User
/* Smart *///for function naming in Swift 1. In general, we write a function that is so written in Func SayHello (name:string, greeting:string) {    print ("\ (greeting), \ (nam e)}//call, this function does not read very well in accordance with human reading habits SayHello ("Rinpe", Greeting: "Hello")//2. The following is a modification to this function, func sayhelloto (name: String, withgreeting:string) {    print ("\ (withgreeting), \ (name)")}//called so that it is comfortable to read, like reading a sentence Sayhelloto (" Rinpe ", withgreeting:" Hi ")//3. But then there is a problem, that is, the function of the internal direct use of the external name is very awkward, so we can define an internal name Func Sayhelloto (name:string, Withgreetingworld greeting:string) {    print ("\ (greeting), \ (name)")}//is called like this, both to ensure that the reading is comfortable and ensure that the function is also comfortable to use inside:) Sayhelloto ("Rinpe", Withgreetingworld: "Hi")//4. Another case is that when the function performs a specific operation, the function name uses the verb directly, omitting the external parameter name, for example: Func multiply ( Numberone:int, _ Numbertwo:int), Int {    return numberone * numbertwo}//is called so that it represents two numbers multiplied by a similar function: Max (x:t, y: T) Multiply (10, 10)

  

Recommendations for definition of Swift functions

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.