News for hackers. Stuff that matters.
Re:Fluent Interfaces Are Bad for Maintainability by erpellan on Tuesday March 20, 2018 @09:59AM (#16628571)
Kotlin solves the problem elegantly with the 'apply' and 'run' extension functions.

  fun foo() =
    Runtime.getRuntime().apply {
        addShutdownHook(Thread { println("Bye!") })
        traceMethodCalls(true)
        exit(404)
    }
Re:Fluent Interfaces Are Bad for Maintainability by m00g00 on Tuesday March 20, 2018 @10:19AM (#16628742)
Which is awfully similar to JavaScript's much maligned 'with' statement.

Never understood the FUD and 'considered harmful' screeds against it. Yes I'm aware of the performance/optimization concerns, but honestly, the whole javascript language is a massive performance/optimization concern and we've managed pretty well.

Simple things like changing style properties on DOM elements:

   with(element.style) {
       display = "block";
       marginLeft = "5px";
       background = "green";
   }
And of course with 'with', everything is a fluid interface, and with the flexibility of being able to enter code between the function calls.
Re:Fluent Interfaces Are Bad for Maintainability by hungerstrike on Tuesday March 20, 2018 @10:13AM (#16628695)
Kotlins `apply` seems exactly like the much maligned `with` statement from JavaScript, which has been deprecated.

Why is it elegant here, but deprecated there?

Re:Fluent Interfaces Are Bad for Maintainability by abiox on Tuesday March 20, 2018 @11:12AM (#16629217)
i suspect some or many of the reasons it's discouraged in js do not apply to kotlin. as we all know, js has... unique constraints in it's design. why is it deprecated in js?
Re:Fluent Interfaces Are Bad for Maintainability by m00g00 on Tuesday March 20, 2018 @10:20AM (#16628751)
Took the words right out of my mouth (literally, and 5 minutes faster).

Why? I'd say because Douglas Crockford.