Skip to main content

Many programmers prefer working with classes. It'sIt's a very easy-to-understand concept that is a good model of human thought processes about the world (i.e.that is, we instinctively relate real objects to the abstract group of items we consider them to belong to, which is what a class is). AlsoAlso, classes make reasoning about object types easier: in a class-based language, applying principles like Liskov SubstitutionLiskov substitution is simpler than it is in a language where we just have objects that may have different methods, or whose type may even change at run time, as is the case in JavascriptJavaScript.

Note that even in JavascriptJavaScript, an awful lot of code simply uses the prototype facility to emulate classes. ThisThis is mostly because a lot of programmers prefer thinking that way.

There is also another reason class based-based languages are preferred: it is easier to compile them to efficient code. TheThe most efficient JavascriptJavaScript VMs effectively dynamically create classes to represent the types of JavascriptJavaScript objects as their methods and prototypes change. SeeSeethis description of V8's implementation for a rationale on why this is done.

Many programmers prefer working with classes. It's a very easy-to-understand concept that is a good model of human thought processes about the world (i.e. we instinctively relate real objects to the abstract group of items we consider them to belong to, which is what a class is). Also, classes make reasoning about object types easier: in a class-based language, applying principles like Liskov Substitution is simpler than it is in a language where we just have objects that may have different methods, or whose type may even change at run time, as is the case in Javascript.

Note that even in Javascript, an awful lot of code simply uses the prototype facility to emulate classes. This is mostly because a lot of programmers prefer thinking that way.

There is also another reason class based languages are preferred: it is easier to compile them to efficient code. The most efficient Javascript VMs effectively dynamically create classes to represent the types of Javascript objects as their methods and prototypes change. Seethis description of V8's implementation for a rationale on why this is done.

Many programmers prefer working with classes. It's a very easy-to-understand concept that is a good model of human thought processes about the world (that is, we instinctively relate real objects to the abstract group of items we consider them to belong to, which is what a class is). Also, classes make reasoning about object types easier: in a class-based language, applying principles like Liskov substitution is simpler than it is in a language where we just have objects that may have different methods, or whose type may even change at run time, as is the case in JavaScript.

Note that even in JavaScript, an awful lot of code simply uses the prototype facility to emulate classes. This is mostly because a lot of programmers prefer thinking that way.

There is also another reason class-based languages are preferred: it is easier to compile them to efficient code. The most efficient JavaScript VMs effectively dynamically create classes to represent the types of JavaScript objects as their methods and prototypes change. Seethis description of V8's implementation for a rationale on why this is done.

Jules
  • 17.9k
  • 2
  • 38
  • 65

Many programmers prefer working with classes. It's a very easy-to-understand concept that is a good model of human thought processes about the world (i.e. we instinctively relate real objects to the abstract group of items we consider them to belong to, which is what a class is). Also, classes make reasoning about object types easier: in a class-based language, applying principles like Liskov Substitution is simpler than it is in a language where we just have objects that may have different methods, or whose type may even change at run time, as is the case in Javascript.

Note that even in Javascript, an awful lot of code simply uses the prototype facility to emulate classes. This is mostly because a lot of programmers prefer thinking that way.

There is also another reason class based languages are preferred: it is easier to compile them to efficient code. The most efficient Javascript VMs effectively dynamically create classes to represent the types of Javascript objects as their methods and prototypes change. See this description of V8's implementation for a rationale on why this is done.

close