What is the main focus for the developer when coding?

I have read many books on how to code correctly, and they usually talk about all of these methods from a point of view that I cannot understand.

eg. consider a singleton pattern:

I limit myself to the fact that a class can only be created once, but since I only create an application, if I know that a class should be created only once, then why should I create it a second time?

Looks like I'm protecting myself.

It seems to me that the big picture is missing.

What is my main goal when coding an application?

How am I supposed to think?

Thanks.

+4
source share
3 answers

"Creating a product that works" may be the main goal. But it is just as useful as “creating a piece of music that is just rocks” for the aspiring composer. The main question is “ how to create a product that works”, which is largely related to skills.

Programming is such a wide field that you cannot just select a few "fundamental laws" that you can focus on. There may be 1,000 or 10,000 separate considerations, each of which is important in a particular context, from a certain point of view. The only way to learn the skill is to work, write code (this also includes errors), read other people's code, read (often conflicting) opinions and ideas from books and the Internet, etc. Do it regularly for 10-20 years and you will get well.

For example, is it possible to use a singleton approach to make a compromise between initial complexity (using statable singlets is a bit easier than link wrapping) versus future malleability (you may find that you "painted yourself" in the corner "later). Some people are dogmatic about avoiding globals (“singleton is evil”), and although this may be a good empirical opinion in general, globals and singlets have their own application. For example, the Java System class is a global singleton.

+2
source

Make it work, make it work correctly, so it works fast.

Most templates introduce complexity as a single price to use them. Do not add templates if you do not need them .

In the case of singleton - if you do not need to limit the class to one instance (and when you really need it), do not turn it into a singleton. This makes your code more complex and difficult to understand.

+7
source
  • Because after 2 years in the future you will forget that it should be a single and violate this when updating the code. Remember that extremely high (IIRC> 70%) efforts are carried out with the preservation of the existing code, and not with the recording of a new one.

  • Using the template will allow you to train when you are NOT working as part of a team of 1 person. At this point, other people will not know what should be a single.

+4
source

Source: https://habr.com/ru/post/1307852/


All Articles