Hello everyone, today we talk about a platitude topic, as programmers, how can we improve our code ability?

Before we can answer this question, we need to define what code capability is. Only find the right way to facilitate the force, many students on this problem is not clear enough. Often think that code ability is algorithmic ability, is to brush LeetCode or algorithmic problems. Some students think that code ability is to brush more projects, projects do more, code ability naturally come up.

In fact, I personally feel that these two views are a little misunderstanding, the following simple talk about my own views, I hope to help you.

Language foundation

Many people see here estimate to ridicule, this is not nonsense yao, programmers write code language has not learned how to write code?

In fact, it is not nonsense, different languages have different characteristics, and even different principles, if there is no more solid grasp of the language foundation, it is easy to make some low-level mistakes.

Just to give you a simple example, a former intern wrote this Python code once, and you can see what the problem is.

def funcA(param):

    if param is not None:

     return funcB(param)

    return None





def funcB(param):

    pass

Copy the code

I don’t know how many of you can see what the problem is, but some of you might think is not None is not None. That’s not the problem. Is not None is the standard statement. The real problem is that he writes funcB after funcA in the function call section.

What’s wrong with funcB at the end?

As you’ll see, writing funcB in this way is an error in the Python interpreter, and we have to write funcB before funcA. Because Python is not a compiled language but an interpreted language, it is executed line by line by interpreter. So it will execute funcA first and then funcB, and when it executes funcA it will find that funcB didn’t exist, so it will throw an error.

At that time, the student debug for a long time but did not find the problem, even thought it was the Python version of the problem. This is not because of his poor code ability, but because of his lack of solid language foundation.

There are a lot of examples, because each language has a lot of features of its own, and if we only dabble in one language, the code we write will be very non-standard. For example, if Java does not know about abstract classes, and Python does not know about mutable arguments and decorators, it is often uncomfortable to write code that is not as simple as possible, giving the impression that a very basic function has been implemented with great effort.

So the language foundation is also the basis of code ability, we do not look down on this, think that as long as the basic syntax can be written. This is a big mistake. Some features and syntactic sugar may be used sparingly, but they can greatly simplify code and increase readability when needed.

Code specification

I don’t know if you’ve ever read code that’s particularly non-standard, but I’ve read some of it, and it’s like getting a needle in your eye.

Code specification is actually less about ability than it is about engineer’s own literacy. Highly trained engineers will learn the current coding specifications of the language on their own initiative and will never feel comfortable doing so. You can search the code specification, every language basically has its own code specification, and this specification is very detailed, specific to variable name, class name, method name, file name, constant name how to name the corresponding specification.

Not only that, but it also limits some special cases. Here’s a snippet from Google’s Java coding specification:


The more our code conforms to the specification, the more readable it will be and the better our coding literacy will be.

Code specifications don’t just cover coding, but many other areas as well. For example, the use of database connection pooling, such as kafka setup and use, as well as the use of multi-threading, etc., will have their own specifications. These contents not only play a normative role, there are corresponding principles in each point, which is worth us to learn deeply.

For example, many people know that a database needs to use a database connection pool, so why use a connection pool? How about the number of connections in the connection pool? How does this work?

It may seem like an interview question, but it contains our understanding of the underlying database connection. We’ve figured out that maybe we can use it not just for coding, but maybe we can connect it up later when we’re doing other things. Knowledge is not a web of dots connected together. Before we can series, we need enough accumulation first.

System capacity

System capability is the highest requirement of code capability, and also the most appropriate part of an architect’s capability.

Again, let’s take an example. Let’s say you take on a team task to develop a new system. The system needs to handle 100K requests per second. We do not need all the requested data, we need to do some sampling, and we also need to query some storage systems for feature filling. Finally, store the complete data.

Now that you have the task, what are the performance bottlenecks? How do you design the details of the system?

It is estimated that many students will put their eyes on the number of 100K, thinking that the request volume is very large, and whether the system can withstand it is the biggest risk point. But 100K doesn’t really matter, because these requests don’t need to be returned, they just need to be received, and 100K is not very large. But there are a lot of hidden issues, like how do we sample, do we sample online, or do we store all requests for a certain amount of time and then sample them? If it is stored and then sampling, will not memory support? For example, what is the magnitude of the query request we would make to the storage system? Will the storage system be affected?

As a matter of fact, the storage system fails to carry the device, resulting in severe jitter. And once that happens, what do we do about it?

The ability to be sensitive to, understand and solve these problems requires systems. That is, our ability to understand systems, which involves a lot, and requires a certain knowledge of operating systems, knowledge of distribution, and a certain understanding of upstream and downstream systems. For example, it is known that the performance of the storage system is not very good, and a large number of requests may be overwhelmed. Some of this is experience, but more is our basic ability.

The path to improve

In fact, after reading these three points, I believe that we should more or less have some ideas about how to improve.

It’s not a big deal, but three things. Let’s make a brief summary.

  1. Need to consolidate the language foundation, for learning the language can not dabble, need to have a more profound understanding. Of course, this is not just talk, it will take a lot of practice and reading other great code to learn.
  2. You need to follow code specifications, not only for naming variables and handling special cases, but also for understanding the system usage specifications for certain scenarios
  3. You need to fully understand the system, carefully consider each link, need to accumulate some operating system, distributed knowledge and skill points.

From the conclusion of these three points, it seems that it is not a big deal and everyone can do it easily. But the actual situation tells us, often the simpler the truth, the more difficult to do, I hope we do not despise them.

That’s all for today’s article. I sincerely wish you all a fruitful day. If you still like today’s content, please join us in a three-way support.

Original links, more articles