Location>code7788 >text

The Way to Neat Code - Reading Notes (4)

Popularity:579 ℃/2024-09-07 18:56:19

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 4: Coding

image-20240907184649596

The key to mastering each skill is to have "confidence" and the ability to "sense error".

4.1 Be prepared

Coding is a challenging and exhausting intellectual activity. Coding requires more concentration than other types of activities.

  1. First, the code must work.

Must understand what problem is currently being solved and how it should be solved. Must ensure that the code written faithfully follows the solution. Every detail of the solution must be managed and all issues with the language, platform, existing architecture, and current system must coexist peacefully.

  1. The code must be able to help you solve the problem posed by the customer.

    Often times, customers present requirements that don't actually solve their own problems. It's up to you to identify these issues and communicate them to the customer to ensure that the code meets their true needs.

  2. The code must be able to integrate seamlessly with existing systems.

    Your code must not make the system more rigid, fragile, or obscure, and dependencies must be properly managed. In short, code must be written following robust engineering principles.

  3. Other programmers must be able to read your code.

    This includes not only things like writing good comments, but also carefully hammering out code so that it expresses your programming intent. It's not easy to do that. In fact, it's probably one of the hardest things for programmers to master!

    Never code if you feel tired or distracted. If you force it, you'll only end up going back and reworking it again. Instead, find a way to eliminate distractions and calm the mind.

4.2 Fluidized zone

This is the state that programmers enter when they write code, where their consciousness is highly focused, but their mind's field of vision is narrowed. In this state, they feel extremely efficient; in this state, they feel "error-free".

In the streaming state, you're actually giving up on the big picture, so you're likely to make decisions that you'll have to push back on later. It may be faster to write code in the flow zone, but you'll have to go back and revisit that code more often later.

For authors, listening to music helps to keep from entering the "flow zone". (Strange request.)

twinningis a great way to respond to interruptions. When you are answering the phone or responding to another colleague's question, the pairing partner is able to maintain the context of the interruption. When you return to work with your partner, he or she can quickly help you regain the thinking you had before the interruption.

Of course, interruptions can't be avoided and there will always be interruptions that will interrupt you and consume your time. One thing to remember when this happens is that maybe next time it will also be your turn to interrupt someone asking for help. Therefore, it is only professional to politely demonstrate a willingness to help.

4.3 Blocking

There are times when deadlines just won't write code. I've had it happen to myself and seen it happen to others. Dry sitting in front of the computer, but can't write anything.

causeAnother major factor for me is sleep. If I don't get enough sleep, I can't write any code. Other factors include anxiety, fear and depression.

cure: Find a partner to pair program with.

Creative output" depends on "creative input".

4.4 Commissioning

An important aspect of measuring whether you are a professional is whether you can minimize debugging time as much as possible. Absolute zero debugging time is an idealized goal that cannot be achieved, but it is something to strive for.

4.5 Keeping the pace

Software development is a marathon, not a sprint. You can't keep sprinting as fast as you can the whole time to win the race; you can only win by conserving your energy and maintaining a steady pace. Marathon runners carefully condition themselves both before and during the race. Professional programmers are just as careful to conserve their energy and creativity.

  • Know when it's time to leave for a while.

  • Driving home.

  • take a shower

    When you're buried and busy solving a problem, you may sometimes be too close to the problem to see all the available options. As the creative part of your brain is inhibited by intense concentration, you miss out on great solutions. Therefore, sometimes the best way to solve a problem is to go home, have a nice meal, and then go to bed before waking up early the next morning to take a shower.

4.6 Progress delays :

The trick to managing delays is early detection and transparency. Progress should be measured regularly against targets, using three multi-factor deadlines.Optimistic forecast, nominal forecast, pessimistic forecast. Try to stick as closely as possible to these three points in time. Don't confuse predictions with expectations! Present all three numbers to the team and stakeholders and revise them daily.

Delivery failures:

Of all the unprofessional behaviors a programmer can exhibit, the worst is claiming to have completed a task when you know it hasn't.Sometimes it is just a lie that goes too far, and that is bad enough. But the potential danger is greatest when attempting a new rationalization of "done".

We fool ourselves into thinking that the task is done well enough and move on to the next one. We make excuses to ourselves that other tasks we haven't had time to complete can wait until we have more ample time.

Solution:Delivery failures can be avoided by creating a precisely defined "completion" criterion. The best way to do this is to have business analysts and testers create automated acceptance tests [9], and the development task is only complete if it fully passes these acceptance tests.

4.7 Help

Programming is not easy.The younger the programmer the less sense this may make. After all, code is just a bunch of if and while statements. But as you get more experienced, you start to realize that the way you put these if and while statements together is very important. You can't expect to get the best code by simply mixing them together.

Instead, the system must be carefully broken down into small, easy-to-understand units, while making the relationships between those units as few and far between as possible, which is no easy task.Programming is hard, in fact, you cannot write excellent code by yourself. Even if you are extraordinarily skilled, you can certainly benefit from the thoughts and ideas of another programmer.

4.7.1 Helping others

  • It is the duty of every programmer to help each other. Closing yourself off in a cubicle or office and isolating yourself from the rest of the world goes against the spirit of professionalism. Your job can't be so important that you can't take a moment to help others. In fact, as a professional, take pride in being able to help others whenever you can.
  • Offering help to others is not a sign that you are much smarter than they are, but because you bring a new perspective that is a significant catalyst for problem solving.

4.7.2 Acceptance of help from others

  • If someone offers you a helping hand, accept it sincerely, accept the help gratefully and cooperate in good faith.
  • Remember that just as it is important to take pride in being helpful, it is also important to take pride in accepting help from others.
  • It's unprofessional to have help at your fingertips but leave yourself stuck there alone.

4.7.3 Counseling

  • Nothing but your own internal drive and effective coaching from a senior mentor can elevate a young software developer into an agile and efficient professional faster.
  • So, again, it is the professional responsibility of senior programmers to take the time to mentor young programmers hand-in-hand. By the same token, it is also the professional responsibility of young programmers to seek mentoring from senior mentors.