Is it worth it to convert my functional JavaScript code to an object-oriented design?

I am currently creating a small web application that includes enough JavaScript. When I prototyped the original idea, I simply hacked a few functions to demonstrate how the application would eventually behave forward to rewrite JavaScript in an object-oriented manner.

Now, when I enter the implementation phase, I think that creating object-oriented JavaScript for an object-oriented view seems redundant - the project is unlikely to require any major changes in the future, it would guarantee an object-oriented design. Instead, I find that a set of concise, cohesive functions works well.

So, with that said, and with an attempt to adhere to the KISS principle, when a set of functions provides a suitable solution to the problem, are there any other reasons that should be considered in order to convert my code into an object-oriented design?

+6
javascript web-applications software-design
source share
8 answers

No, although I personally consider OOP more tasty, it is a means to an end, not an end in itself. There are many cases where procedural programming makes more sense than OOP, conversion to conversion may be, as you said, redundant.

+11
source share

No, let it move forward - it is more productive, in my opinion.

+10
source share

If your code is well-structured, well laid out, and well-commented, and it performs the task that is required of it, then messing with it for any reason other than adding functions is not recommended.

Although it would be nice to say that the program is good for OOP, etc., if it does not need to be changed to work, I would definitely leave it as it is.

If it does not break, do not mix it up :)

+5
source share

If this code is already implemented and does not require maintenance or, even better, updates, stick to it. If you are going to implement it now, and it can become complicated, consider the OO approach.

Experience has shown me that it is fairly easy to write and maintain procedural code, while complexity is low, but after a certain threshold it begins to complicate the task of exponentially increasing complexity when using procedural programming, while OOP, although it’s more difficult to start, complexity is much more manageable.

Bottom line: if the task is simple enough or already implemented, save it simply. If it can become more complex, consider OOP.

+2
source share

I would say that before deciding, it’s still worth considering your code. The obvious downside of the rewrite code is that there is a cost to testing to make your code work the same way as before. Do you have any unit tests? If not, then your testing costs are even higher. In general, I am opposed to re-writing working code if it does not serve the other end, which will allow you to more easily write the new functionality that is now required (i.e., Reorganizing common functions, etc.).

HOWEVER, anytime a person says "I hacked together," I suggest that you should always look at your code. Why was it hacked together in the first place? I know that many people say that object-oriented code is not an end in itself, but it is a methodology that you should not think about after that. You just start to do it.

Maybe your js is relatively simple, and therefore OO scafolding is really an extra overhead. Good. But I still suggest that you always check the code (and especially someone else), some code that you call "hacked." It may have been a Freudian slip ... but it slipped.

+1
source share

Consider it obsolete code from now on. When you want to change something, reorganize it to make the code easier in your mind. If you need a little OOP, use it. If you do not, do not do this.

OOP is a hammer, please do not handle the screw problem as a nail.

0
source share

If it works and it is easy to maintain, I would not convert it for conversions. There should be more interesting things.

0
source share

Just in mind. Objects are pretty expensive to create in javascript.

Keep construction facilities to a minimum.

0
source share

All Articles