News for hackers. Stuff that matters.
Re:Android KTX: Kotlin Development for Android by kornish on Monday February 05, 2018 @04:07PM (#16312191)
Discoverability via autocomplete is much higher in the second one. Extension methods probably seem really strange to anyone coming from a FP background (myself included), but in practice they've ended up being pretty useful when paired with Intellij.
Re:Android KTX: Kotlin Development for Android by rubber_duck on Monday February 05, 2018 @05:10PM (#16312705)
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#

Re:Android KTX: Kotlin Development for Android by georgemcbay on Monday February 05, 2018 @05:14PM (#16312748)
As 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.

Re:Android KTX: Kotlin Development for Android by nolok on Monday February 05, 2018 @06:26PM (#16313210)
That'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.
Re:Android KTX: Kotlin Development for Android by euyyn on Monday February 05, 2018 @06:35PM (#16313260)
It 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.
Re:Android KTX: Kotlin Development for Android by rubber_duck on Tuesday February 06, 2018 @05:19AM (#16315382)
Not 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.

Re:Android KTX: Kotlin Development for Android by pennaMan on Tuesday February 06, 2018 @07:15AM (#16315756)
Extension 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.

Re:Android KTX: Kotlin Development for Android by rubber_duck on Thursday February 08, 2018 @05:51PM (#16336291)
I 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.

Re:Android KTX: Kotlin Development for Android by euyyn on Tuesday February 06, 2018 @01:43PM (#16318362)
I 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.
Re:Android KTX: Kotlin Development for Android by rubber_duck on Thursday February 08, 2018 @05:53PM (#16336301)
Sure, 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.
Re:Android KTX: Kotlin Development for Android by TheAceOfHearts on Monday February 05, 2018 @04:12PM (#16312239)
Doesn't it get a bit overwhelming to get a huge list of choices with autocomplete? I've never done any serious work with Java or Kotlin, so I'm genuinely curious.

As long as you have good docs, I find discoverability is rarely an issue. One of the first things I do when picking up a language is look through its built-in constructs, to familiarize myself with the available options.

Re:Android KTX: Kotlin Development for Android by izacus on Monday February 05, 2018 @05:23PM (#16312797)
Hmm, have you used any of the Java-based autocompletion systems? - IntellJ / Android Studio autocompletion system is context aware and will only list relevant methods (which means that the list is rather short and useful for the context). Which is a stark contrast to many ctags-like autocompletion systems, which will just dump all the symbols on you and aren't very useful in my experience.

Using autocompletion means you don't have to leave the editor window and I've found it hugely useful for methods which have several overrides - instead of leaving the editor, you just choose the one you need as you type.

Re:Android KTX: Kotlin Development for Android by TheAceOfHearts on Monday February 05, 2018 @06:41PM (#16313299)
Most of my experiences with Java were during college with Eclipse. I just remember finding it rather frustrating to have the autocomplete regularly popping up and showing me dozens of options without an easy way of learning more about em.

At some point I read through the Kotlin docs and found it interesting, but didn't have any projects in mind for it. I might try my hand again along with IntelliJ / Android Studio.

I've happily used other JetBrain products such as RubyMine and WebStorm.

Re:Android KTX: Kotlin Development for Android by ReidZB on Monday February 05, 2018 @10:05PM (#16314146)
With autocomplete open in IntelliJ, you can press F1 to view the docs for that currently highlighted autocomplete method inline. Works really well.
Re:Android KTX: Kotlin Development for Android by kornish on Monday February 05, 2018 @04:17PM (#16312273)
Typing a couple characters is generally enough to cut out most of the noise, so long as you know vaguely what you're looking for and the methods are sensibly named.

I don't think it's the built-in constructs which are hard to find. In JVM-land, it's sifting through often verbose library interfaces that makes discoverability a huge win. Looking in Javadoc for that single function to convert from Type A to Type B properly can be a real pain.

Re:Android KTX: Kotlin Development for Android by Groxx on Monday February 05, 2018 @04:52PM (#16312572)
Only when things become ambiguous semantically. E.g. if they had `toUri` and `asUri` and `parseUri` etc then sure.

But even then it's far more discoverable / less overwhelming than "I have a String. I want a Uri. Do I use a UriBuilder, UriParser, Uri, StringConverterFactory, etc?". Not only do you have all classes to choose from, you need to pick the one with the right methods (usually not visible when choosing the class) for the data you have.

Some IDEs can and do improve the helper-classes case a bit by letting you type e.g. `myString.uri` and showing you "uri" methods both on string and static methods anywhere which accept strings... but it's not widespread, sometimes unhelpful (there are far too many "parse" methods), and you're still missing out on the class context which sometimes has important info.

Re:Android KTX: Kotlin Development for Android by merb on Monday February 05, 2018 @04:50PM (#16312559)
Well I'm coming from a FP background. But if you're String needs to have a toUri() method, things are already wrong. Uri.parse is just fine, even in scala.