CLOVIS
06/30/2021, 10:24 AMstatic to the language. The semantic relationship between classes and objects are a beautiful way to remove complexity to the language while adding new features. To my understanding, the proposal exists for two reasons:
1. For performance reasons
2. To allow extension functions on classes that do not have a companion object
I don't think it's a good idea to introduce static for performance reasons (the language should be about semantics, the compiler should handle performance). If it's not possible to do automatically by the compiler (because it would break backward-compatibility, or whatever) then at most it should be a JVM-specific annotation.
I don't think a new keyword is necessary for classes that do not have a companion object. I think Kotlin should allow:
fun Foo.Companion.bar() = ...
even if Foo doesn't have a Companion. Obviously the compiler will have to replace the companion by something else, but that's not really a big deal (it will be invisible in Kotlin code, and extension functions are already a bit weird from Java code, so as long as it's not something extremely strange I think it's alright)ephemient
06/30/2021, 1:52 PMthis within the extension function changes depending on whether the target class has a companion or not at the time of compile? having a fake dangling reference like that seems prone to other consistency issuesCLOVIS
06/30/2021, 2:13 PMNir
06/30/2021, 2:58 PMephemient
06/30/2021, 3:39 PMephemient
06/30/2021, 3:41 PMephemient
06/30/2021, 3:41 PMephemient
06/30/2021, 3:43 PMCLOVIS
06/30/2021, 3:52 PMthis doesn't exist in it?Nir
06/30/2021, 4:07 PMNir
06/30/2021, 4:52 PMimportNir
06/30/2021, 4:52 PMNir
06/30/2021, 4:55 PMNir
06/30/2021, 4:55 PMNir
06/30/2021, 4:56 PMephemient
06/30/2021, 4:56 PMNir
06/30/2021, 4:56 PMNir
06/30/2021, 4:57 PMNir
06/30/2021, 4:58 PMNir
06/30/2021, 4:59 PMNir
06/30/2021, 5:01 PMpackage in Kotlin, overall. C# namespaces aren't associated with a class, the way that namespaces in Kotlin are proposed to be 🤷ephemient
06/30/2021, 5:02 PMimport java.util; util.Map, but you can import java.util.Map; Map.EntryNir
06/30/2021, 5:02 PMimport java.util and then util.Mapephemient
06/30/2021, 5:02 PMNir
06/30/2021, 5:02 PMephemient
06/30/2021, 5:03 PMpackage java; val util and then it's ambiguous what java.util refers to as a termephemient
06/30/2021, 5:03 PMnamespace as a new concept, it could define what a naming conflict means (probably forbid it)Nir
06/30/2021, 5:03 PMephemient
06/30/2021, 5:04 PMephemient
06/30/2021, 5:04 PMNir
06/30/2021, 5:04 PMNir
06/30/2021, 5:05 PMephemient
06/30/2021, 5:07 PMNir
06/30/2021, 5:07 PMNir
06/30/2021, 5:08 PMNir
06/30/2021, 5:13 PMNir
06/30/2021, 5:14 PMjava.util.Map but Map is still in the global namespaceNir
06/30/2021, 5:14 PMimport foo then you still need to refer to any entities in foo qualified, i.e. foo.bar will work but bar will notephemient
06/30/2021, 5:14 PMimport java.util.{List, Map}
use std::collections::{Vec, HashMap};
from collections import UserList, UserDict
which is a nice QoL improvementNir
06/30/2021, 5:15 PMfrom foo import bar, baz, qux then now you can use the unqualified names. So, you pick, qualified, or unqualified, or partially qualified if you want, and only the name you want gets brought inNir
06/30/2021, 5:16 PMNir
06/30/2021, 5:16 PMephemient
06/30/2021, 5:18 PM