Location>code7788 >text

The Way to Neat Code - Reading Notes (6)

Popularity:233 ℃/2024-09-09 23:03:53

The Way to Neat Code

image-20240904225436374

Synopsis:

This book is a summary of the experience of programming guru "Uncle Bob" over 40 years of programming career, explaining what kind of attitude, what kind of principles and what kind of actions are needed to become a real professional programmer. The author takes the detours and mistakes he and his colleagues have made as examples, with the intention of guiding those who come after him and helping them to take a higher step in their careers.

This book is suitable for all programmers and can be used as a reference for all those who want to become professionally literate in the workplace.

Chapter 6: Exercise

image-20240909224659172

Professionals need specialized training to improve their skills, without exception. Musicians practice scales, players practice roundabouts, doctors practice cutting and stitching, lawyers practice arguing, and soldiers practice performing tasks. To excel, professionals choose to practice. This chapter is going to talk about how programmers can improve their professional skills.

shifts

Anything that you want to do fast can't be done without practice.To repeat the coding/testing process as quickly as possible, you need to be able to make decisions quickly. This requires recognizing a wide variety of environments and problems and knowing how to cope with them.

If there are two martial arts practitioners grappling, each must be able to quickly recognize the other's intentions and respond correctly within one hundredth of a second. When grappling, you cannot have enough time to study the stance and think about how to respond. At that point, you can only rely on your body's reaction.

In reality, it's your body that actually reacts, the brain is thinking on a higher level. In a state of coding/testing many times per minute, the muscles in your body memorize which keys to hit. The more basic part of the consciousness recognizes the scenario and responds appropriately in a hundredth of a second, and the brain is free to think at a higher level.

6.2 Programming the Judo Dojo:

Kata:

In martial arts, a kata is a set of moves designed to simulate one side of a fight. The goal then is to gradually practice the entire set of moves until they are pure. Martial arts practitioners work hard to train their bodies to familiarize themselves with each move, linking them into a smooth routine. A well-trained kata looks quite beautiful.

Similarly, a programming kata is a set of keyboard and mouse strokes that are used to simulate the process of solving a programming problem. The practitioner is not solving a real problem because you already know the solution. Instead, you are practicing the actions and decisions needed to solve the problem.

To learn about hotkeys and navigational operations, as well as test-driven development, continuous integration, and the like, it's quite effective to find the whole set of kata to practice with. What's more, it's especially good for subconsciously constructing generic problem-solution connections, so that when you come across such problems later in real programming, you'll immediately know what to do about them. Like martial arts practitioners, programmers should know a variety of different kata and practice them regularly to make sure they don't fade or get forgotten.

The real challenge is practicing a kata to the point where you can glimpse the rhythm. It's not easy to do that.

Vassar:

Practice for two.

Vassal can basically be described as a kata for two people. The moves in it need to be memorized precisely and rehearsed over and over again. One person is in charge of offense and the other is in charge of defense. Various moves have to be repeated again and again as the attacker and defender swap.

Programmers can use a game called "ping pong" for similar exercises: two people choose a kata, or a simple problem, one writes a unit test, the other writes a program that passes the unit test, and then switches roles.

The programmer who writes the unit tests will have extreme control over how the problem is solved, and he also has plenty of room to impose limits: if the programmer chooses to implement a sorting algorithm, the person writing the tests can easily limit the speed and memory to pressure his peers. This makes the whole game very testing ...... and arguably very fun.

Free practice:

Multi-Player Exercise.

Many programming workshops play a game called "free practice". It's a lot like Vassal with two participants solving a problem, except that free practice involves a lot of people and the rules are portable. In free practice, a screen is projected onto a wall, one person writes a test, then sits down while another person writes a program to pass the test, then writes the next test. One by one, people at the table take turns taking over, or those interested can line up to participate on their own. However it's organized, it's a lot of fun.

6.3 Expansion of Self-Experience

Professional programmers are usually limited in a way that the kinds of problems solved are relatively homogeneous. Bosses usually emphasize only one language, one platform, and the programmer's area of specialization. Less experienced programmers have some sort of damaging blind spot in their resumes and thinking.It's not uncommon to see scenarios where programmers find themselves unprepared to face new situations created by cyclical changes in the industry.

Open Source:

One way to stay on top of your game is to contribute code to open source projects, just like lawyers and doctors participate in pro bono activities. There are a lot of open source projects out there, and contributing a little to an open source project that other people really care about should qualify as the best way to improve your skills.

On practicing professional ethics:

Professional programmers practice on their own time. A boss's responsibilities don't include keeping your skills from falling behind or building you a great-looking resume. Doctors don't need patients to pay for practicing surgery, players don't need fans to pay for practicing roundabouts (usually), and musicians don't need fans to pay for practicing scales. So bosses are not obligated to pay for programmers to practice. Since you practice on your own time, you don't have to limit yourself to the language and platform your boss dictates. You can choose your favorite language and practice your favorite technique.

Conclusion:Regardless, professionals need to practice. They do it because they care about the best results they can achieve. More importantly, they practice on their own time because they know it's their responsibility, not their employer's, to keep their skills current. You won't make any money while practicing, but after practicing, you will be rewarded, and handsomely.