Is there room for optimization of this code?

As a programmer, during job interviews, questions about source code are favored by many interviewers.

Zhang Gong is a java programmer. He recently went to a well-known Internet company for an interview. After doing a written test,

During the interview, the interviewer asked this question:

Is there room for optimization in the following code? If yes? How to optimize?

Zhang Gong took a closer look at the program and found it familiar.

So I said, "This is not the source code of LinkedHashMap, and I can't see where it needs to be optimized."

Hearing what Zhang Gong said, the interviewer was shocked, interviewing so many people, this is the first time I met with such a simple answer.

For this topic, the first few job applicants either said that there is too much if else code, or that the variable naming is not standardized. Didn't see the source code of LinkedHashMap.

Zhang Gongneng judged it at first sight, and it was really great. The interviewer was very satisfied with this and said that Zhang was hired on the spot.

Personally, I feel that I should pay more attention to reading the source code when studying.

Why do you want to read the source code? The old saying goes: "Read through ten thousand books, and write like a god."

Accumulating by reading the source code helps us to integrate some fragmentary knowledge points, knowing what is and why.

Take Kafka message queue, how does it achieve high performance and high availability

Not only that, we can also learn from the source code. The stone of the mountain can be used for jade. If there is a need to start making wheels by ourselves, then it is definitely helpful to refer to the current excellent projects.

So how to read the source code effectively?

Sort out the code organization level

When you need to look at the code, don't just start when you find a file, first look at the code organization level.

For example, LinkedHashMap is well understood, inheriting HashMap, and HashMap implements the Map interface. The level is very clear.

Reading the code, it is recommended to focus on the main body first, ignore some details, step by step, and reach the goal.

The above is just a personal opinion, I don't know what you think about it, welcome to communicate!

For technical exchanges, media cooperation, brand promotion, please add Xiaoai WeChat: iyiyouyou

Recommended in the past

Programmer: can withstand loneliness and temptation

More exciting, please scan the QR code to follow Xiao Ai

Guess you like

Origin blog.csdn.net/X8i0Bev/article/details/108543764