The introduction

We work every day, and all we do is sit in front of a computer and type code. Many of us have been doing this for years. But in the last few months, I’ve found more and more that I can’t code at all. I don’t know what good code is. I just know how to type some code.

What is good code?

In fact, in my mind, this question is slowly emerging. I also look back at the days of coding and bug fixing. I still can’t figure out what a good piece of code is.

Maybe we still have some principles in mind. High cohesion, low coupling, single responsibility for functions, annotations, exceptions caught, and clear naming.

However, light is a function of single responsibility this point, I still can not enter the door. What is a single responsibility? What is a thing?

Take the simplest example.

In general, our business systems are divided into multiple levels. There are controller layer, Service layer, DAO layer and so on. Some companies also divide the Service layer into multiple service layers.

Maybe this is how we define the responsibilities that these levels have.

The Controller layer usually does some simple input validation. The Service layer is the logic that does the real business. As much as possible, the DAO layer simply calls the database, gets the raw values, and does some ORM mapping.

If there is query data in the service layer, should the validity of the data be verified?

It seems to have to be checked. Otherwise, an error like a null pointer will be thrown.

What if some util function is used in the service layer? So who does the basic parameter check?

Is it this util function that does that? If the util function is used, then the controller and service layers have already been used. If util does not check, it is easy to throw a null-pointer exception if the util function is used by another function. At this time, there will be no log printing, which is also a very upsetting thing. What to do at this point? So the two sides, the opacity between the layers?

Given our previous experience with Spring source code, how does Spring source code deal with the issue of parameter validity? How do logs get thrown?

Is there a book about Effective Java or Clean Code? It’s worth a look.

This is the role of books to us, predecessors plant trees descendants cool, standing on the shoulders of giants, we can see farther.

About writing

From now on, I will write an article here every day, with no limit on subject matter, content or word count. Try to put your daily thoughts into it.

If this article has helped you, give it a thumbs up and even better follow it.

If none of these are available, write down what you want to say when you finish reading? Effective feedback and your encouragement are the biggest help to me.

And I’m going to pick up my blog. Welcome to visit and eat watermelon.

I’m shane. Today is August 27th, 2019. Thirty-fourth day of the hundred day writing project, 34/100.