Not envy mandarin duck not envy fairy, a line of code half a day. Original: Taste of Little Sister (wechat official ID: XjjDog), welcome to share, please reserve the source.

I hide a knife in the wind, cut all the autumn in the world. Destined for immortality, this famous poem, written by XjjDog on September 6, 2020, embodies the author’s ambivalence about wanting to destroy the autumn color, yet being unable to do anything about it.

Autumn is annoying. Besides being the beginning of the slump, it is also prone to flareups and recurrent rhinitis. Everything is affected by the season and loses its nature. Of course, programmers are no exception.

It’s the weekend. You’re supposed to be off. But before 1995, there was no weekend in China. The weekend was the rights and interests of countless martyrs.

The weekend doesn’t mean Sunday, it means Saturday. Sunday is actually called Sunday “, because God rests on the seventh day, so westerners go to church on this day. Therefore, programmers generally choose to work on Saturday and not on Sunday.

But obviously, it’s imported! I think I found a reason to stay late!

In a word, today we come to work overtime! With the air conditioning on, it’s a good day to share knowledge.


Today, some students share a topic: why is it recommended to use placeholders to write logs?

log.debug("Processing trade with id: {} and symbol : {} ", id, symbol);
Copy the code

Little A says: Obviously, this is because {} is very elegant. Using placeholders, the parameters involved in the placeholder can be reused. This is very elegant in design.

Little B said: I kind of agree with little A’s point of view. With {} substitution, it takes CPU to find and replace each time. Efficiency is definitely not optimal, since the author provided this way, it must be designed for the simplicity of the code such trade off.

Small C said: I think the author simply took off his pants and farted. There is no problem with using + to splice directly. I’ve been using + splicing for years with no problem. This is just an API that the author provides, and it doesn’t make any sense.

Little A asks little C: Do you know how + is handled in Java? .

Small C say: don’t take this kind of corny question to ask me. + Finally, the bytecode is stitched together using StringBuilder. I also know that StringBuilder and StringBuffer are no different in terms of efficiency.

Small A not satisfied: how have no distinction? One is synchronous method, one is normal method, there must be a difference.

Small C white small A one eye, did not speak, it seems to be disdain to answer this question.

Don’t digress. There is a very good reason to recommend using placeholders. Take a look at the code below to see how the student who shared it covered up the embarrassment in time.

if (log.isDebugEnabled()) {
    log.debug("Processing trade with id: " + id + " and symbol:" + symbol);
}
Copy the code

The discussion was in full swing. Since the discussion is long and tedious, XJjDog concludes here.

The log level is usually INFO or WARN. DEBUG logs are not printed because they are very verbose. In the preceding code, check whether DEBUG logs can be printed before printing them.

The log.debug method already does this once, so why bother?

Note the contents of the debug method, we use the + to determine, () parameter priority, is higher than the debug method itself. If we do not add the outer judgment, then the parameters in debug, whether to print or not, are concatenated.

If we are at ERROR level, these parameters will still be concatenated. Since strings are immutable, these concatenated strings take up a lot of heap space and become wasteful.

This makes it easier to interpret the {} placeholder. Because it generates a fixed number of strings, the string is concatenated only when it is actually needed to print.

By this logic, if the log.error method is used, you can play it any way you want.

Little A, little B, little C, little F, all nodding yes.


What the hell are you talking about here? Is everything on schedule? . In the heat of the discussion, an incongruous voice came.

Everyone looked back, it was the project manager. He cradled an old gray laptop, his favorite Excel open on the screen, and the colorful statistical tables looked pretty.

Small A say: our progress all normal ah. I mainly came to work overtime today, waiting for the confirmation of demand.

The project manager said: Didn’t the requirement come to you already? Manager Wang is very serious about this need. You need to be nervous. I haven’t found a task item for this requirement this week.

B said: This requirement is not clear at all, we need to define the basic function points first. We can’t work overtime for nothing. Let’s discuss technical issues here to increase the technical atmosphere. What’s the problem?

The project manager said: What’s the use of a technical climate? Overtime is used to do the demand, the progress of abnormal code and then cow X what is the use? Manager Wang requires that this function will be on next week, you still have leisure to discuss here. Can’t we talk about needs?

I watched quietly in the side, the project manager is obviously affected by the fall, there is a big ignition. It was a clear violation of the project manager’s need for emotional stability, and he was furious.

Programmers, on the other hand, are blushing and argumentative, with a little pride in their bones.

X you m, Lao Tze endure you for a long time, small C jump up, a slap in the project manager’s computer. The brightly colored spreadsheets were suddenly bursting with waves of electronic interference.

I’ve put up with you for a long time!! Project manager also angry, pointing at small C nose roar: TM number you work slowly, the whole day some useless.

Saliva flew, insults flew, and dust fell from the ceiling.

Why don’t they do it, you might wonder? Because this is a precedent. Not long ago in the company, two war were fired, and do not give compensation, so can not take this risk.

After a while, everyone was tired of arguing and staring at each other angrily. The project manager didn’t lose just because he was alone, because all the other programmers were losers and only Little C was yelling at him.

I talked with the customer about this requirement, but I don’t think we should do it. You can leave work early today. Just when everyone was stunned and embarrassed, Wang’s voice spread to come over. He had just gotten off the phone with a client and had missed the spectacle.

I secretly ran to Mr. Wang’s side, stretched out his hand to cover his mouth, and quietly whispered a few words to Mr. Wang. I must inform him of the problem.

Mr. Wang’s face sank down: a project team is a big family! Neither love nor kill each other. Your actions undermine unity and are highly undesirable. The performance of all members of the project team this month was C!

For a moment, everyone gloated at me. I smiled awkwardly, they should not hate me, this is the fall to blame.

Xjjdog is a public account that doesn’t allow programmers to get sidetracked. Focus on infrastructure and Linux. Ten years architecture, ten billion daily flow, and you discuss the world of high concurrency, give you a different taste.