algorithm – What defines good logic?

Question:

I was thinking about some code issues that I changed and I remembered what my android development course teacher said and said: "Good logic has a few lines of code". I asked some people who told me it depends. But it depends on what? Of course, the less code, the faster the processing. Does anyone think the opposite of this and have a concrete example of this?

Answer:

What your teacher said is generally right. One problem that occurs is that some misunderstand the phrase "the less code the better". So they make "spaghetti codes" to justify fewer lines.

Having a smaller amount of code does not mean better performance in certain cases.

It depends on the features of the language you are working with and what the goal is.

A simple JavaScript example:

With Jquery, we can select an element this way.

elemento = $('#id_do_elemento');

Simple, isn't it?

Let's see how it looks without JQuery

elemento = getElementByID('id_do_elemento');

Simple, however, uses more characters. So does this mean that using JQuery is more performant?

No, because it was necessary to load a 400kb library to be able to have this type of resource.

Logically, if the use of the library is necessary for more complex tasks or even a relatively large use even of very small functions, it is recommended to use the library.

That's where the logic in determining comes in, having the good sense to discern what can be better employed.

Scroll to Top