[swift-evolution] [Guidelines, First Argument Labels]: Prepositions inside the parens

Dave Abrahams dabrahams at apple.com
Tue Feb 9 13:18:00 CST 2016

Hi everybody,

Having looked at some examples, the API guidelines working group members
that were present this morning agreed we really want prepositions inside
the parentheses of method calls.

Here are some results for the importer; we're still tuning some of the
heuristics but overall we feel very good about the preposition

Note that this is not final wording, but here are the guidelines we're
working with for first argument labels:

A. Try to form a grammatical phrase including the first argument and
   describing the primary semantics at the call site.

B. The first argument gets a label when and only when:

   1. It does not form part of a grammatical phrase describing the
      primary semantics.  For example,
      x.dismiss(animated: y)
      [more examples needed]
      Note that parameters with defaults never describe the primary
      semantics. so are always labeled.
      func invert(options options: SomeOptionSet = []) // yes
      func invert(_ options: SomeOptionSet = [])       // no

   2. The method is a factory method; such calls should mirror
      initializers, with no preposition.  For example,
      let x = UIColor(red: r, green: g, blue: b)
      let y = monitor.makeColor(red: r, green: g, blue: b)

   3. It is part of a prepositional phrase

     a. The label normally starts with the preposition. 
        For example, 
        x.move(from: a, to: b)
        x.loadValues(forKeys: ["fox", "box", "lox"])
     b. ...unless the preposition would break a very tight association
        between parameters:
        x.moveTo(x: a, y: b)
        [encourage grouping parameters into higher-level concepts,
        e.g. Point, in these cases]

Feedback most welcome, of course.

More information about the swift-evolution mailing list