Hacker News new | ask | show | jobs
by Benjammer 3796 days ago
Could they just go all the way and use a mandatory first argument name to make things even more concise? That would get away from something that annoys a lot of people about Swift, the implicitly unnamed first arguments.

Something like this:

    class BezierPath: NSObject {
      func add(LineTo lineTo: CGPoint) {}
      func add(ArcWithCenter center: CGPoint, radius: CGFloat, 
                          startAngle: CGFloat, endAngle: CGFloat, 
                          clockwise: Bool) {}
      func add(CurveTo endPoint: CGPoint, controlPoint1 point1: CGPoint, 
                          controlPoint2 point2: CGPoint) {}
      func add(QuadCurveTo endPoint: CGPoint, controlPoint: CGPoint) {}
    }

    class main {
        func run() {
            let path = BezierPath()
            let point1 = CGPoint()
            let point2 = CGPoint()

            path.add(LineTo: CGPoint(x: 100, y: 0))
            path.add(ArcWithCenter: CGPointZero, radius: 20.0, 
                             startAngle: 0.0, endAngle: CGFloat(M_PI) * 2.0, 
                             clockwise: true)
            path.add(CurveTo: CGPoint(x: 100, y: 0), controlPoint1: point1, 
                             controlPoint2: point2)
            path.add(QuadCurveTo: point2, controlPoint: point1)
        }
    }
The difference is mostly that it looks even more concise when using code completion. You would see:

    path.add(LineTo: CGPoint)
Instead of:

    path.addLineTo(point: CGPoint)
1 comments

It gets really annoying when you have short single-arg functions. Imagine what swap(_:_) or Collection.suffix(_) would look like with mandatory first arguments.