AlexanderM
(Alexander Momchilov)
1
One things I quite enjoyed in some other languages, was that the community had an established notation for distinguishing static and instance members (functions, properties, etc.). This would be useful in written communication, documentation, and so on.
Some examples:
| Language |
Example class function |
Example instance method |
| Objective-C |
+[MyClass foo], +foo
|
-[MyClass foo], -foo
|
| Ruby |
MyClass::foo, ::foo
|
MyClass#foo, #foo
|
| Python |
static MyClass.foo |
MyClass.foo |
| Swift |
??? |
MyClass.foo |
Do we have an established notation for this? If not, could we decide on one?
2 Likes
xwu
(Xiaodi Wu)
2
It's worth noting that, in source, MyClass.foo preferentially refers to an unapplied reference to a static method:
extension Int {
func f() -> Int { 42 }
static func f() -> Int { 21 }
}
let x = Int.f
x() // 21
1 Like
tera
3
If we don't have this already my vote would be for the Python version: static MyClass.foo vs MyClass.foo
How do you plan to use this notion?
Note the two members have different types:
class MyClass {
func foo1(String)
static func foo2(String)
}
MyClass.foo1 type is: (MyClass) -> (String) -> Void
MyClass.foo2 type: (String) -> Void
1 Like