Simpler, shorter, faster without Classes/Types in JavaScript?

Di.rk
3 min readNov 27, 2021

or what is the benefit in using Types/Classes at all — nowadays?

A few days ago I got inspired by a homework in a programming course for JavaScript. The task was to write a little application to create a team home page after answering some questions about your development team. The result should look like this.

The description of the homework forces the students to create four classes

  • Employee (a base class for the following classes)
  • Manager
  • Engineer
  • Intern

and also a test class for each of them.

Than after that you should use a library to ask for your team mates using the command line, creating instances of those classes with the answers and in the end create the above homepage from those objects.

So far so good and clear and the solution was doing all steps and works well or at least well enough for this homework I would think.

But I was wondering if this is the solution I would prefer. I have grown up with OOP, UML, C++, Eiffel, Java and the like during my IT life and a few years ago this could have been also my approach to solve it:

Thinking in Classes, to create a model of the real world.

But today I am far away from this.

Today I am thinking in data.

In the last few years I have created no class hierachy at all, I use objects instead and nothing else. So I took the little challenge to refactore it to what I would do. The result is here.

The idea was simply use the already created objects by the library during the questionnaire as the container for rendering the page and ignore/delete the classes.

This gives me

  • less code,
  • simpler code
  • easier extensible code
  • and no if then else checks for the type of the employee.

And less code is always better, I think, because the best code is to not write code at all.

So the questions I am asking myself are:

  • Is this the way to go?
  • Even for larger projects?
  • And what are the disadvantages I have to expect doing so?

At least I think I would have to write even more test code, and thats a good thing, because it explains the usage of my code and also makes it more robust to changes.

So invest the time you save in creating a class hierachie that restricts you to do what you want, in creating even more tests or some tests at all — I know nobody wants to write tests, because it seems to be a waste of time, but it is the opposite.

--

--