https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Ahmed

02/22/2022, 12:33 PM
Hey guys, is there a specific naming convention for class fields which has a number in their name ?
Copy code
class Apartment ( val room1: String, val room2: String )
j

Joffrey

02/22/2022, 12:34 PM
Not that I know of. I always saw such variables/properties written the way you did here. If another word followed the number, it would usually be capitalized, as if the number were a word.
1
That said, note that there are many cases where you can avoid numbers. If the different variables don't play the same role, you could use some word to express that difference:
copy(sourceFile: Path, targetFile: Path)
. If they play symmetric roles, sometimes you can use a list instead. This is true in particular if all those properties are often processed/accessed together in the same way, because an iteration is usually easier to deal with than repeating the same code for each property. In the case of apartment rooms, maybe you're in this case (depends on the usage).
🙏 1
1
2 Views