Saturday, July 29, 2017

Clean code: Writing Code For Humans (II)

July 29, 2017

Introduction


It is so much learning to go over the lectures again after 2 months. The lecture on pluralsight.com is three hours 10 minutes long. The first time study is documented, the blog link is here.

In order to practice those principles like TED principle, Julia has to write down and try to have some workout first. It is also good practice to go over some lecture note before taking another mocking interview in the weekend.

To be a better programmer, stay competitive, the mocking interview is the great opportunity for Julia to learn how to work on small things each time, learn to communicate with the peer to solve problem. More practice will help Julia learn and have some creative ways to solve the problem.

July 29, 2017  10:30 pm - 11:30 pm
Go over the lecture video again

TED Principle (remember it, repeat three times! TED Principle, TED Principle, TED Principle)
Terse, expressive, do one thing
Don't repeat yourself

How to write Self-document code?
clear intent
layers of abstraction

Assign Booleans Implicitly 
Magic Numbers
Dirty                  Clean 
if(age > 21)        const int legalDrinkingAge = 21
                         if(age > legalDrinkingAge)
                         {
                         }
Encapsulate Complex Conditionals
Principle: Favor expressive code over comments (expressive vs comments, two choices, a principle?)

Be declarative if possible 
Dirty 
Clean -> Use LINQ
return users
   .where(u => u.AccountBalance < minimuAccountBalance)
   .where(u => u.Status == Status.Active); 
Interesting? Call it "Be declarative if possible". It is hard to related to LINQ example. 

Table Driven Methods 
- great for dynamic logic
- avoids hard coding
- write less code - Avoids complex data structures
- Easily changeable without a code change/app deployment


No comments:

Post a Comment