V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
expkzb
V2EX  ›  Swift

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

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

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

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

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