Hacker News new | ask | show | jobs
by bshimmin 4010 days ago

   3.3 Use readable synonyms in place of reserved words.

   // bad
   const superman = {
     class: 'alien',
   };

   // bad
   const superman = {
     klass: 'alien',
   };
What is unreadable about "klass"? Rails, for example, uses "klass" and it's never been hard for me (or, I suspect, anyone) to understand.
2 comments

The problem I see with "klass" is that you can't easily talk about it to another developer. e.g.:

"Make sure you set the class-with-a-k property to 'alien'."

"Make sure you set the type property to 'alien'."

They probably don't mean 'class' in the programming language sense and should therefore use another name.
Well maybe they are using "class" in the OOP sense, for instance if they're implementing a programming language. Even if they're not, if they use the word "class" in the specification for what they're implementing (maybe they're representing a taxonomical hierarchy in their program and have fields named "kingdom", "phylum", "class", etc), or have the word "class" in a user facing output (maybe they're making an RPG where a character object has fields "race", "class", "level").

It's confufing to use one name inside your code and different one elsewhere.