E
E
Evgeny Zhurov2022-02-13 15:04:47
Node.js
Evgeny Zhurov, 2022-02-13 15:04:47

What is the best approach to backend design? What is the fundamental difference between the approaches?

For example, a controller in Node.js can be written like this:

export class UserController {
    static async login(req, res) {
        try {} catch(e) {}
    }
}


And it is possible like this:
const login = async (req, res) => {
    try {} catch(e) {}
}

const controller = { login }
export default controller


In other words, in the OOP style and in the functional (if I understand correctly).
Is there a fundamental difference between these approaches? Faced the code written and so, and so. And he wrote in one project - so, in another - differently. But either I didn’t encounter any situations specific to each approach, or something else, but I can’t decide for myself which approach is more correct to use. While there is a feeling that all this is purely a matter of taste. Is it so? And what other approaches are there? What can I read / watch on this topic?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Nesterov, 2022-02-13
@Zhuroff

Is there a fundamental difference between these approaches?

Well, yes, in the first case, classes are used, in the second - functions. In that
which approach is better to use. While there is a feeling that all this is purely a matter of taste.

This, IMHO, is a matter of the size of the project and the complexity of orienting in it. That is, for a simple KUD-oriented system, classes may be redundant. But the more logic is taken out of the limits of "reading-writing" from the database, the more tangibly the classes will be needed.
And what other approaches are there?

There is also procedural, but it is now used exclusively for simple programs and in scripting languages ​​like python and vanilla js.

R
Romi, 2022-02-13
@romicohen

И какие еще есть подходы?
Laravel for example :) Joking
aside: - JS is still a language for the front, and its main advantage over other languages ​​is that it runs in any browser. It simply has no other advantages :D

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question