TURI BLOG

[Nomad Coders Challenge] Clean Code - Assignment #03 ๋ณธ๋ฌธ

Nomad Coders

[Nomad Coders Challenge] Clean Code - Assignment #03

TURI BLOG 2024. 12. 1. 13:08

 

 

๐Ÿ“ It is part of a book club challenge on a programming learning website called Nomad Coders. The challenge is to demonstrate what I have learned after reading Clean Code by Robert C. Martin.

 

๐Ÿ“ It will consist of the following sections over three weeks: the range of reading, the top quotes from the book, my review, and remaining questions. 

  ๐Ÿ”—Challenge Schedule


๐Ÿ’ป  I plan to read Clean Code in JavaScript and Python, referring to the GitHub repositories shared by Nomad Coders with the challengers.

 

Assignment #03

  • ๐Ÿ“š Chapter 2. Meaningful Names - Variables
  • โœ”๏ธ TIL 
    • Top quotes from the book
    • My review
    • Remaining questions

 

๐Ÿ“ Top quotes from the book

  • ์˜๋„๋ฅผ ๋ถ„๋ช…ํžˆ ๋ฐํ˜€๋ผ
    • ๋ณ€์ˆ˜๋‚˜ ํ•จ์ˆ˜ ๊ทธ๋ฆฌ๊ณ  ํด๋ž˜์Šค ์ด๋ฆ„์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ตต์งํ•œ ์งˆ๋ฌธ์— ๋ชจ๋‘ ๋‹ตํ•ด์•ผ ํ•œ๋‹ค. ๋ณ€์ˆ˜(ํ˜น์€ ํ•จ์ˆ˜๋‚˜ ํด๋ž˜์Šค)์˜ ์กด์žฌ ์ด์œ ๋Š”? ์ˆ˜ํ–‰ ๊ธฐ๋Šฅ์€? ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€? ๋”ฐ๋กœ ์ฃผ์„์ด ํ•„์š”ํ•˜๋‹ค๋ฉด ์˜๋„๋ฅผ ๋ถ„๋ช…ํžˆ ๋“œ๋Ÿฌ๋‚ด์ง€ ๋ชปํ–ˆ๋‹ค๋Š” ๋ง์ด๋‹ค.
    • ์ฝ”๋“œ ๋งฅ๋ฝ์ด ์ฝ”๋“œ ์ž์ฒด์— ๋ช…์‹œ์ ์œผ๋กœ ๋“œ๋Ÿฌ๋‚˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ๋ฌธ์ œ๋‹ค.
  • ๊ทธ๋ฆ‡๋œ ์ •๋ณด๋ฅผ ํ”ผํ•˜๋ผ
    • acountList (x) -> accountGroup, bunchOfAccount, Accounts (o)
    • ์„œ๋กœ ํก์‚ฌํ•œ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ์ฃผ์˜ํ•œ๋‹ค. 
    • ์ผ๊ด€์„ฑ ์œ ์ง€ : ์œ ์‚ฌํ•œ ๊ฐœ๋…์€ ์œ ์‚ฌํ•œ ํ‘œ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค. 
  • ์˜๋ฏธ์žˆ๊ฒŒ ๊ตฌ๋ถ„ํ•˜๋ผ 
    class Product -> class ProductInfo, class ProductData (x)
    class Customer, class CutomerObject (x)
  • ๋ฐœ์Œํ•˜๊ธฐ ์‰ฌ์šด ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ผ
    • ํ”„๋กœ๊ทธ๋žจ์€ ์‚ฌํšŒ ํ™œ๋™์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
  • ๊ฒ€์ƒ‰ํ•˜๊ธฐ ์‰ฌ์šด ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ผ -  ๋ฌธ์ž ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด๋ฆ„๊ณผ ์ƒ์ˆ˜
  • ์ž์‹ ์˜ ๊ธฐ์–ต๋ ฅ์„ ์ž๋ž‘ํ•˜์ง€ ๋งˆ๋ผ
    • ์ „๋ฌธ๊ฐ€ ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” ๋ช…๋ฃŒํ•จ์ด ์ตœ๊ณ ๋ผ๋Š” ์‚ฌ์‹ค์„ ์ดํ•ดํ•œ๋‹ค. ์ „๋ฌธ๊ฐ€ ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” ์ž์‹ ์˜ ๋Šฅ๋ ฅ์„ ์ข‹์€ ๋ฐฉํ–ฅ์œผ๋กœ ์‚ฌ์šฉํ•ด ๋‚จ๋“ค์ด ์ดํ•ดํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๋‚ด๋†“๋Š”๋‹ค.
  • Class Name - Noun, Noun Phrase
    e.g) Customer, WikiPage, Account, AddressParser (o)
    Manager, PRocessor, Data, Info (x)
  • Method Name - Verb, Verb Phrase
    e.g) postPayment, deletePage, save (o)
  • ํ•œ ๊ฐœ๋…์— ํ•œ ๋‹จ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ผ
    • ์ถ”์ƒ์ ์ธ ๊ฐœ๋… ํ•˜๋‚˜์— ๋‹จ์–ด ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ด ์ด๋ฅผ ๊ณ ์ˆ˜ํ•œ๋‹ค. 
  • ํ•œ ๋‹จ์–ด๋ฅผ ๋‘ ๊ฐ€์ง€ ๋ชฉ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ๋ผ. ๋‹ค๋ฅธ ๊ฐœ๋…์— -> ๊ฐ™์€ ๋‹จ์–ด (x)
    • ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” ์ฝ”๋“œ๋ฅผ ์ตœ๋Œ€ํ•œ ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๊ฒŒ ์งœ์•ผ ํ•œ๋‹ค. ์ง‘์ค‘์ ์ธ ํƒ๊ตฌ๊ฐ€ ํ•„์š”ํ•œ ์ฝ”๋“œ๊ฐ€ ์•„๋‹ˆ๋ผ ๋Œ€์ถฉ ํ›‘์–ด๋ด๋„ ์ดํ•ดํ•  ์ฝ”๋“œ ์ž‘์„ฑ์ด ๋ชฉํ‘œ๋‹ค. ์˜๋ฏธ๋ฅผ ํ•ด๋…ํ•  ์ฑ…์ž„์ด ์žˆ๋Š” ๋…์ž์—๊ฒŒ ์žˆ๋Š” ๋…ผ๋ฌธ ๋ชจ๋ธ์ด ์•„๋‹ˆ๋ผ ์˜๋„๋ฅผ ๋ฐํž ์ฑ…์ž„์ด ์ €์ž์—๊ฒŒ ์žˆ๋Š” ์žก์ง€ ๋ชจ๋ธ์ด ๋ฐ”๋žŒ์งํ•˜๋‹ค.
  • Name Based on Domain (x) -> Use computer science (CS) terms, algorithm names, pattern names, or mathematical terms.
  • ์—ฌ๋Š ์ฝ”๋“œ ๊ฐœ์„  ๋…ธ๋ ฅ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ด๋ฆ„ ์—ญ์‹œ ๋‚˜๋ฆ„๋Œ€๋กœ ๋ฐ”๊ฟจ๋‹ค๊ฐ€ ๋ˆ„๊ตฐ๊ฐ€๋Š” ์งˆ์ฑ…ํ• ์ง€๋„ ๋ชจ๋ฅธ๋‹ค. ๊ทธ๋ ‡๋‹ค๊ณ  ์ฝ”๋“œ๋ฅผ ๊ฐœ์„ ํ•˜๋ ค๋Š” ๋…ธ๋ ฅ์„ ์ค‘๋‹จํ•ด์„œ๋Š” ์•ˆ ๋œ๋‹ค.
  • ์ด ์žฅ์—์„œ ์†Œ๊ฐœํ•œ ๊ทœ์น™ ๋ช‡๊ฐœ๋ฅผ ์ ์šฉํ•ด ์ฝ”๋“œ ๊ฐ€๋…์„ฑ์ด ๋†’์•„์ง€๋Š”์ง€ ์‚ดํŽด๋ณด๋ผ. 

 

๐Ÿ–Š๏ธ My review

  • From the example below, I better understood the importance of using searchable and meaningful variable names, something I hadnโ€™t paid much attention to in the past. I used to think naming variables with overly long names was unnecessary, but now I understand why even a single variable should be thoughtfully named.

 

 

๐Ÿ” Remaining questions

  • polymorphic method(๋‹คํ˜• ๋ฉ”์„œ๋“œ)
  • noise word(๋ถˆ์šฉ์–ด)

 


๐Ÿ”— Additional Resources

 

๐Ÿ”— Reference

Comments