Clean code and path become better developer

Tram Ho

Monday morning everyone went to work and I went to coffee alone: ​​D. Unemployed ahiuhiu. With a guy coder said correctly, sitting and sipping a cup of coffee looking back on life is also great. Especially having time to think about writing three things for fun :). Recalling the sentence you say: “In football there are some people who are free to use themselves”, so sometimes you want to be easy to use: D.

What is a clean code? How to know which code is clean?

Let’s go back to the issue of clean code – So what’s the clean code? Why do our developers need clean code, what does it mean to become a better developer. If you answered clean code, of course, the code is not dirty: D. That’s right, the code is how the code is not clean (use rough words too: D). Check out the code below:

In this code, what do you feel is not very clean? Maybe many of you look at kiu: m * this guy is stupid, now anyone has a banana code like that: D. Hehe just suffered, before I was so stupid and irresponsible code ak: D.It was a long time ago, I was less upset (-_-). I have to go home to escape the maintain both lie sky =]]. So now share again for those who have not yet enlightened about clean code ?

Back to the example, this code has a lot of clean code issues

  1. [Meaningful names] The variable name is very meaningful. He code these lines and the code is finished running ok, no problem, great. After a lot of new 3 months features and related to this code, come back to read it and not understand what it does – must read the code, debug to know what it is doing, even worse than reading, it doesn’t know what, is it -> a lot of useless time -> fail
  2. [Don’t return null] Suddenly the getItems function returns null to make a beep to take the effort to check null, it is quite redundant to use null checking every time. What we want is simply to get the product list and the totality. Instead of return null we can return an empty list .
  3. [CLass, method does one thing well] Great, a function that does both functions if it returns results knows the total product of this customer buys, there are errors then know the customer buys more than the current amount . But in the end, it is just what makes it difficult to understand, must be cumbersome to explain, making it difficult for other colleagues to use this method, meet me, m ** always write another function for health ?

Is my example too obvious? Looking at it, she saw her grandmother sadly, with her fairy: D. But that is one of the many clean code issues that when we want to be a better developer we need to care about, high-level people in programming, then just look at the code, they I felt very empathetic, experienced supreme things hidden in the lines of code looked so simple.

Sea heaven knowledge

My knowledge and experience are only limited so I need to read more tips to know more than my little knowledge, and these are two books that if I want to be more proficient in this clean code problem should read:

  • Clean Code (Robert C. Martin)
  • The Clean Coder (also Mr. Robert C. Martin always)

I will list again as well as discuss more about what is written in the book, actually saying clean code is something quite realistic but it is also quite emotional like we always see other girls’ girlfriends while it thinks vice versa: D. But these are shared by early predecessors, so it is very valuable experience for our programmers ?

1. The predecessors share of clean code

  • Clean code does one thing well. (Bjarne Stroustrup)
  • Không thể mã số được xác định và direct, Clean mã đọc như cũng được-ghi prose. (Grady Booch)
  • Clean code can be read, clean code should be literate. It has meaningful names (Dave Thomas)
  • Có thể xác định kích cỡ của tập tin như là nó được ghi rõ từ một người ai cares. (Michael Feathers)
  • Reduced duplication, high expressiveness, and early building of simple abstractions. (Ron Jeffries)
  • Bạn Know bạn đang làm việc khi cài đặt mã này khi mỗi thời gian bạn đọc các kết quả vào có thể là nhiều nhiều gì bạn mong đợi. (Ward Cunningham)

These are the share of clean code of the leading people in this industry. It can permeate or will permeate any programmer, with myself. I still can’t say that I understand all these shares, because I really don’t understand what it says: D. Translate and watch, hehe …

2.Clean code rules

2.1 Meaningful names

2.1.1 Use intention-revealing Names

Name the variable as an art in programming, you have to put the name so meaningful, easy to understand, read right away, grammatically correct (vs me =]]). Like Le Van Nhat, Le Van My (wanting their children to go abroad) or Nguyen Vang, Nguyen Hoc Xon (want rich children) …

Do not like Nguyen Van A, Nguyen Van B, but some of the teachers who teach programming often take it as an example. Perhaps the life of Nguyen Van A is the best example of this life. Ignore it ? In general, naming variables in programming is very important, the project fails one because of it.

For example:

Tao green, two months later or later, does not know what pot he always made. Zu zu wrote this function.

This is much better, isn’t it, taking a few more seconds to think about the name, saving hours later này

2.1.2 Use Pronounceable Names

2.1.3 Use Searchable Names

ITZone via jinhduong

Chia sẻ bài viết ngay