How to create good code

How to create good code

[[155438]]

Someone recently emailed me asking me how to write good code. I was feeling a bit under the weather, so I rambled a bit. I’m feeling better now, so I wanted to share the following thoughts because I think they’re an interesting starting point for this important discussion.

At the time, I wrote:

  1. Good code doesn't just compile, it communicates. It talks to you now, and it talks to you later when you maintain the code. It's understandable to your team and anyone else who looks at it from the outside.
  2. Good code values ​​reliability and testability over clever tricks. If it needs to clearly express its intent and results, good code will tend to use one or more extra steps to express it.
  3. Good code also takes into account its usage. The requirements for a piece of code that runs a million times and runs it only once are different, just like a tree in the forest and a lonely tree.
  4. Good code, even when broken down, can be broken down into reasonable units, rather than into a massive monolithic implementation.
  5. Good code is not just implemented once or twice, but also reviewed and refactored. This makes it possible to make it the best and most robust implementation.
  6. Good code takes globalization into account and provides for potential users of different cultures. Adding internationalization and related accessibility is really a matter of code, not just an afterthought.
  7. Good code not only considers what specific environment it runs in today, but also considers how to adapt to these environments that may change over time.

That’s what I thought of. What do you want to add, delete, or modify about my list of “how good code is made”? I look forward to seeing your thoughts.

renew

Seivan Heidari suggested adding: Good code does not expose internal implementation details when exposed as an API to the outside world.

Anonymous suggested adding: Good code is natural. Good code does what you need it to do and is delivered on time. The rest is bullshit.

Dave DeLong suggested adding: Good code inspires awe in those who read it, and inspires those who read it to write good code of their own.

Paul Cantrell suggested adding: Good code pays attention to trade-offs. It makes trade-offs based on engineering, not absolute dogma. It also doesn't make tools or techniques in-group status markers.

Rainer Brockerhoff suggested adding: Good code can be easily reused (even after several years) and can be extended or adapted with just a few lines of code.

<<:  Android Activity Security

>>:  Next time your boss asks you to refactor your system, let him read this article

Recommend

Traffic 2.0 era: How do operators manage data traffic?

1. China Telecom’s “Flow Treasure” and China Unic...

What should I do if my Xiaohongshu account/notes are restricted?

Since Xingyuan opened up the recruitment of blogg...

How does product operation achieve user growth?

Recently I saw a growth-related topic on Zhihu, w...

Three tips to teach you how to successfully operate an APP

What does an APP need to do to retain users? 1. D...

Analysis of Tik Tok Media Advertising in Q4 2019

The short video industry still has great potentia...

Wuwei Qinglong "Bull Stock Rise Practical Camp" stock trading tutorial video

Course Contents: Section 1: Rising Point System.m...

Taobao Through Train 618 targeted promotion optimization tips!

Since last year, many merchants should have disco...

How Li Huaiyu built Whale into the Alibaba of VR

“Weijing wants to be the Alibaba of VR.” At a med...

These 3 key points can save you 50% of your promotion costs!

Whether for marketers or operators , advertising ...

Warning: Never put frozen food back into the refrigerator after thawing!

During the Spring Festival holiday, you may have ...