Am 15.12.2017 um 10:06 schrieb Cédric Champeau:


2017-12-15 8:02 GMT+01:00 Jochen Theodorou <blackd...@gmx.org <mailto:blackd...@gmx.org>>:

    On 15.12.2017 06:10, Nathan Harvey wrote:

        I think your first step - "define a file that contains extension
        functions" -
        is slightly wrong. In Kotlin, you can place extension methods
        anywhere, they
        do not have to be confined to a single file (or worse, like
        Groovy, in a
        totally different dependency). The syntax I discussed is what
        enables them
        to do this.


    I am aware of that you can define them anywhere. But frankly, I find
    that pretty messy. I mean defining quasi global extension methods
    randomly all over the place... does sound like maintenance hell to
    me. Probably best to declare them inline as well, then you will
    never ever be able to find them again, if they are from a library.


I disagree here. The fact that you can define extension methods locally in Kotlin is a huge win, especially for DSLs. Unlike Groovy they are local, so don't leak to other parts of the application.

The key point here is that they are local. In this case I of course will not say that they are messy at all - the local ones. The global ones I consider still messy, because you can still declare them all over the place.

But local extensions then they are more like our concept of static categories, that is on the list for like... I don't know... surely 5+ years. Now... how does Kotlin know if something is local and something is not? I guess https://kotlinlang.org/docs/reference/extensions.html#declaring-extensions-as-members explains that actually.

Then what are we talking then about now in this thread? Global extensions, local extensions, how to improve Groovy extension methods to not require extra steps for the static compiler or even static categories?

bye Jochen

Reply via email to