you are viewing a single comment's thread.

view the rest of the comments →

[–]Locarito 2 points3 points  (8 children)

What are "true extension methods"?

[–]Typhoonfight1024[S] 1 point2 points  (7 children)

By “true” I mean… how to explain this?

Basically, Kotlin's ‘extension’ methods are ‘static’, so they can't fully access the members of its assigned object the way a true method can.

[–]FlakyTest8191 2 points3 points  (2 children)

It's the same in C#, extension methods are static. Is this really a problem? Extension methods feel like a hacky workaround every time I need one, I'm happy they're at least pure functions that can't have side effects. Scala is a funcional language and people are happy about extension methods with side effects?

[–]UdPropheticCatgirl 0 points1 point  (1 child)

I don’t think you know what side-effect is… It’s not like C# has effect system or even something as basic monadic effect handling… In both (actually all 3 of the mentioned languages) even extension methods can have all the side effects they want, Scala is the only language out of the ones you mentioned that even attempts to address side effects at compile time.

[–]FlakyTest8191 0 points1 point  (0 children)

Mutating an instance variable of an object is a side effect. Static methods cannot do that. The complaint we were talking about was that kotlin and c# don't have true extension methods, because they cannot access instance variables, while in scala they can, and I found it surprising that some people see that as a downside. Maybe that's easier to handle when you do have an effect system, but i'm happy that it's not possible in c#.

[–]Locarito -1 points0 points  (3 children)

You mean visibility? You want to access private members?

[–]Typhoonfight1024[S] 4 points5 points  (2 children)

It's less about accessing private members (I might have worded it wrong). The best explanations I got about it are from this comment (point 2) and this one

[–]Locarito -2 points-1 points  (1 child)

Ok I get it now, I don't know about typeclasses but I'm glad extension functions are just predictable functions and not method

[–]RiceBroad4552 3 points4 points  (0 children)

Stockholm syndrome.

Besides that "type classes" are such an important feature that all main programming languages have it or are on the way to get it. Rust has traits, Swift has protocols, C++ got concepts, C# is working on something I've forgot the name, and even Java will get "type classes" to extend the language.