DAY 13
๐ย ์ค๋ ์ฝ์ ๋ฒ์ : 7์ฅ
<aside>
๐ ์ฑ
์์ ๊ธฐ์ตํ๊ณ ์ถ์ ๋ด์ฉ์ ์จ๋ณด์ธ์.
</aside>
- Use Exceptions Rather Than Return Codes
- Try to write tests that force exceptions, and then add behavior to your handler to satisfy your tests. This will cause you to build the transaction scope of the try block first and will help you maintain the transaction nature of that scope.
- If you throw a checked exception from a method in your code and the catch is three levels
above, you must declare that exception in the signature of each method between you and
the catch. This means that a change at a low level of the software can force signature
changes on many higher levels.
- This is called the SPECIAL CASE PATTERN [Fowler]. You create a class or configure an object so that it handles a special case for you. When you do, the client code doesnโt have to deal with exceptional behavior. That behavior is encapsulated in the special case object.
- Returning null from methods is bad, but passing null into methods is worse. Unless you are working with an API which expects you to pass null, you should avoid passing null in your code whenever possible.
- Clean code is readable, but it must also be robust. These are not conflicting goals. We can write robust clean code if we see error handling as a separate concern, something that is viewable independently of our main logic
<aside>
๐ค ์ค๋ ์ฝ์ ์๊ฐ์? ๋ ์ค๋ฅด๋ ์๊ฐ์ ๊ฐ๋ณ๊ฒ ์ ์ด๋ณด์ธ์
</aside>
<aside>
๐ ๊ถ๊ธํ ๋ด์ฉ์ด ์๊ฑฐ๋, ์ ์ดํด๋์ง ์๋ ๋ด์ฉ์ด ์๋ค๋ฉด ์ ์ด๋ณด์ธ์.
</aside>
<aside>
๐ก ์๊ฐ 3์ค ์์ฝ
</aside>
- Returning null from methods is bad, but passing null into methods is worse. โก๏ธย never thought about it because I see it very often, everywhere.
Try Catch
rather than console.log(error)
- Try to write tests that force exceptions, and then add behavior to your handler to satisfy your tests. โก๏ธย TDD. Iโve never tried this so far mainly because I donโt see a very clear benefit of it. ๐ค