V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
expkzb
V2EX  ›  Swift

没有人觉得 swift 是一门丑陋的语言吗?

  •  
  •   expkzb · 2015-10-10 14:21:53 +08:00 · 3232 次点击
    这是一个创建于 3093 天前的主题,其中的信息可能已经有所发展或是发生改变。
    dorentus
        1
    dorentus  
       2015-10-10 16:08:00 +08:00
    说说哪里丑陋了?
    expkzb
        2
    expkzb  
    OP
       2015-10-10 16:20:27 +08:00
    @dorentus 比如这种东西

    func jediTrainer () -> ((String, Int) -> String) {
    func train(name: String, times: Int) -> (String) {
    return "\(name) has been trained in the Force \(times) times"
    }
    return train
    }
    let train = jediTrainer()
    train("Obi Wan", 3)

    操作符太多,也过于抽象,个人认为不太符合编程语言发展的趋势
    dorentus
        3
    dorentus  
       2015-10-10 18:00:54 +08:00
    func jediTrainer()(name: String, times: Int) {
    return "\(name) has been trained in the Force \(times) times"
    }

    这样看着是不是舒服些?
    dorentus
        4
    dorentus  
       2015-10-10 18:08:08 +08:00 via iPhone
    另外通常情况下比较少会遇到一定要这么做的,如果一定要这么做那么你肯定有使用函数式语言的背景,那么理解上也不会有啥问题。
    dorentus
        5
    dorentus  
       2015-10-10 18:09:16 +08:00 via iPhone
    @dorentus 不过上面这个我把参数写反了😏
    expkzb
        6
    expkzb  
    OP
       2015-10-10 18:14:06 +08:00
    @dorentus

    func jediTrainer()(name: String, times: Int) {
    return "\(name) has been trained in the Force \(times) times"
    }

    对 swift 了解不深,这个和我的那个是等价的吗?貌似只返回了一个字符串并没有返回函数
    dorentus
        7
    dorentus  
       2015-10-10 21:05:15 +08:00   ❤️ 1
    @expkzb 看下这个你就明白了:
    http://swifter.tips/currying/
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5219 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:21 · PVG 15:21 · LAX 00:21 · JFK 03:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.