https://kotlinlang.org logo
#feed
Title
l

LeoColman

10/22/2019, 3:22 AM
Thanks for the articles!
Particularly, I've never seen those examples in a Kotlin codebase
And I think that if people are doing that, it's not a problem with extension functions, it's a problem with people and their dirty coding practices. We can't escape that
2
t

thanksforallthefish

10/22/2019, 3:55 AM
I am always a bit in the middle, I know a language cannot provide a feature only for the positive use cases, once the feature is there it is there ripe for bad (or forced) use cases too. But it is also in human nature to try to find shortcuts and being very bad at assessing long time impact of some decisions which might look smart now but might bite in the future.
2
otoh, a friend of mine is now working in go and he keeps telling me the language is so dry and limited you simply have to redo things over and over, I see the other side of the coin, opinionated language trying to avoid users mistake are no fun (pun intended)
l

LeoColman

10/22/2019, 3:58 AM
I rather give the freedom to make good code with the possibility of making bad code. Crappy and macgyvers will always be around in any language, and I don't believe there is much we can do to prevent that
t

thanksforallthefish

10/22/2019, 4:00 AM
probably not in the general case, but you can help people working with you teaching them. also, I like the macgyvers definition, it might be English is not my first language, but am laughing the wording 🙂
l

LeoColman

10/22/2019, 4:02 AM
In my language(portuguese), there's is a beautiful word called "Gambiarra". The closest concept to it is "pulling a macgyver"
😂 2
And there are codes that are full of those 😄
a

altavir

10/22/2019, 10:05 AM
I agree with the problem description, but do not agree with the conclusion. Yes, Kotlin really wants some way to solve multiple receiver problem, but it certainly does not mean that one should avoid using extensions. On the contrary, we should discuss what is the best way to introduce multiple receivers. In kotlin reveivers are explicit, not implicit, so I do not see any problems here. Also I completely disagree with thi statement that member extensions are bad.
3
m

marcinmoskala

10/26/2019, 9:47 PM
I think that Kotlin is great, but for MacGyvers we need some best practices. Our community is too big. It is not only a language for passionates. There are already many people who chose it because of money, who were forced to use it, or for whom it is their first programming language. They lack of education, but often not creativity. I’ve seen a lot of crazy shit in a variety of projects and I hope to make it better. I believe that Scala has bad name (as unreadable) because of some crazy ways how it is used by some developers. I want Kotlin to keep being loved by developers 🙂 I believe that this best practices are the best I can do. @altavir I do not dislike extensions. Just see their limitation. Can you show me member extension that is good (except of DSL)? Would you like to see extension functions with multiple receivers?
l

LeoColman

10/26/2019, 9:59 PM
I personally use extension functions for almost everything. Mainly when it will be something like
fun foo(bar: Bar)
. Most of the times I can transform it into a private extension function
fun Bar.foo()
and operate with that. I think it reads much, much better
m

marcinmoskala

10/26/2019, 10:06 PM
I agree for all top-level functions
Or most
l

LeoColman

10/26/2019, 10:11 PM
I understand that when you follow all the other good practices, extension functions tend to be readable and understandable. And I understand your point that perhaps allowing everything may derail the train in most situations
👍 1
I like that you mentioned that Kotlin is no longer (if ever) a thing for passionates about it
And that's one of the things people like about Java, the verbosity and limits won't allow much space for hacking
a

altavir

10/27/2019, 6:00 AM
I wrote two articles about extension-based design in kotlin: https://proandroiddev.com/diving-deeper-into-context-oriented-programming-in-kotlin-3ecb4ec38814. There is also an article by Roman Elizarov. Of course, both are about libraries, but still one should not discard such a powerful tool. There could be some limitations for beginners though.
2 Views