expkzb
V2EX  ›  Swift

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

  •  
  •   expkzb · Oct 10, 2015 · 4269 views
    This topic created in 4045 days ago, the information mentioned may be changed or developed.
    dorentus
    dorentus
    Oct 10, 2015
    1
    说说哪里丑陋了?
    expkzb
    expkzb
    OP
    Oct 10, 2015
    2
    @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
    dorentus
    Oct 10, 2015
    3
    func jediTrainer()(name: String, times: Int) {
    return "\(name) has been trained in the Force \(times) times"
    }

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

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

    对 swift 了解不深,这个和我的那个是等价的吗?貌似只返回了一个字符串并没有返回函数
    dorentus
    dorentus
    Oct 10, 2015❤️1
    7
    @expkzb 看下这个你就明白了:
    http://swifter.tips/currying/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1775 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:11 · PVG 12:11 · LAX 20:11 · JFK 23:11
    ♥ Do have faith in what you're doing.