4 ms·
I don't like this because it forces you to use the tool, and even if you do I've seen so many times when IDE breaks down and won't autocomplete, navigates to co
by rubber_duck 9y ago
I don't like this because it forces you to use the tool, and even if you do I've seen so many times when IDE breaks down and won't autocomplete, navigates to compiled binary definition on a same solution project reference, fails to find extension methods so you need to Google which namespace to bring in to get it (which isn't always as simple as class.method search, especially when reading code example snippets), etc. Admittedly this was Visual Studio/C#, never used Kotlin for anything serious.
I see extension methods as an inferior substitute for free functions and piping/chaining operators in C#
- georgemcbay 9y agoAs someone who had a heavy skepticism of autocomplete from other environments (including Visual Studio, though I admittedly haven't been using that since the VS 2008 era), I have to say I find the autocomplete in Android Studio damn near magical. It is spooky fast and Just Works, in my rather extensive experience with it. Almost all of my experience with it has been in Java, so I'm not sure the same is true in Kotlin though I would assume it would be similar.
- nolok 9y agoThat's the IntelliJ's magic (android studio is based on it), and that's also why Kotlin is feeling so great compared to other similar language that try to do the same(at least to me); being a jetbrain's made language it has perfect support by their tooling.
- euyyn 9y agoIt doesn't force you to use the tool; it's no worse than the alternative even if you want to write your code in notepad.exe.
- rubber_duck 9y agoNot true, it's very misleading - makes you believe the method is defined inside class body. Also with functions you know they can't access private members, with extension methods you confuse them with real methods and have to think they can. It's only the same thing if you know about it and without a tool you can't know, even with tool it takes some inspection.
- pennaMan 9y agoExtension functions are syntax sugar for static methods that receive the class instance as this. They do not access private members. Also, you need to specifically import the namespace of the extension function in order to use it, making it very clear to the reader of what is going on. It is not some hidden IDE magic, it's built into the core language.
- rubber_duck 9y agoI never said otherwise. I said it was misleading syntax sugar because it implies that static functions defined in any namespace (extension methods) are the same as methods - which have access to internal members and are defined within class hierarchy. If you know something is an extension method then you know it's just syntax sugar, but you can't determine that just by looking at the code.
- euyyn 9y agoI suspect the design of a class, if I have to worry about whether a method I'm calling is able to access private members or not.
- rubber_duck 9y agoSure, but I've been stuck maintaining a codebase a couple of years back written by someone on fluent API hype train - exploring that codebase was a major PITA thanks to VS bugs and extension methods.