https://kotlinlang.org logo
Title
r

rrader

09/13/2017, 8:24 AM
How do you name a class and the name should stand for: iPhoneX, iOS ? Do you name them IPhoneX and IOS? or how do you name a class if the name in real world starts with lowercase letter?
k

karelpeeters

09/13/2017, 8:25 AM
Always, without exception, start class names with an uppercase letter.
2
r

rrader

09/13/2017, 8:25 AM
Why so?
g

gildor

09/13/2017, 8:26 AM
Because of Coding Convention
r

rrader

09/13/2017, 8:26 AM
Why than is not restricted by compiler?
k

karelpeeters

09/13/2017, 8:26 AM
Because we rely on capitalization to tell us whether something is a class or a variable/function.
Because it's not helpful to enforce such a thing.
g

gildor

09/13/2017, 8:27 AM
Kotlin is not so strict about it, you can use own, but official convention requires that
r

rrader

09/13/2017, 8:27 AM
Because it's not helpful to enforce such a thing.
it is helpful, compiler can be much simpler
g

gildor

09/13/2017, 8:28 AM
simpler?
There are a lot of tools that can force you to specific coding convention
r

rrader

09/13/2017, 8:29 AM
yeap, when you parse a string, if it starts with capital you already know that it must be a class
g

gildor

09/13/2017, 8:30 AM
I don’t think so, because other identifiers can use capital letters too, for example objects, constants etc
c

Czar

09/13/2017, 8:30 AM
hm... word
class
is quite a giveaway, even before you notice a capital letter 🙂
r

rrader

09/13/2017, 8:31 AM
but in function body you don't have
class
c

Czar

09/13/2017, 8:31 AM
and in places other than class declaration Andrey's comment applies, you can't rely on capitalization there.
r

rrader

09/13/2017, 8:33 AM
we can inforce variables and function to start with lowercase
methods and properties start with lower case
than we for sure know what it should be
g

gildor

09/13/2017, 8:33 AM
See comment from Dmitry Jemerov about strict coding convention https://github.com/yole/kotlin-style-guide/issues/14#issuecomment-222932510
r

rrader

09/13/2017, 8:35 AM
so, everyone agree to start class with capital, but do not enforce that in compiler, okay
g

gildor

09/13/2017, 8:36 AM
@rrader Also, I’m not a professional in compilers, but I’m very sceptical that naming convention could some how help to compiler
r

rrader

09/13/2017, 8:37 AM
well,
class
somehow helps in parsing, in same way this will help
g

gildor

09/13/2017, 8:39 AM
class is a keyword that cannot be used anywhere except class creation, lower or capital letter can be used everywhere, including keywords