TURI BLOG

[Nomad Coders Challenge] Clean Code - Assignment #06 본문

Nomad Coders

[Nomad Coders Challenge] Clean Code - Assignment #06

TURI BLOG 2024. 12. 6. 08:12

 

📍 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 #06

  • ✔️ Mission #01
  • 📚  Recap  
    • Top quotes from the book - Chapter 3. Functions
    • Remaining questions

 

🎯 Mission #01

    • Quiz 1.
      • Use searchable names
        // BAD ⛔
        // What the heck is 86400000 for?
        setTimeout(blastOff, 86400000);
        
        // GOOD 😎
        const MILLISECONDS_PER_DAY = 60 * 60 * 24 * 1000; //86400000;
        
        setTimeout(blastOff, MILLISECONDS_PER_DAY);
        From numbers without any explanation, not only is the code not searchable later, but you also won’t know what the values represent.
        This is neither an understandable nor an efficient way to write code.
        To address this, I defined a variable with a readable name and used it in the method.
  • Quiz 02.
    • Use meaningful and pronounceable variable names.
      // BAD ⛔
      const yyyymmdstr = moment().format("YYYY/MM/DD");
      
      // GOOD 😎
      const currentDate = moment().format("YYYY/MM/DD");
      This variable name for the method is not meaningful or readable for users.
      It should have a meaningful name to convey what it represents clearly.
  • Quiz 03.
    • Don't add unneeded context
      • If your class/object name tells you something, don't repeat that in your variable name.
        // BAD ⛔
        const Car = {
          carMake: "Honda",
          carModel: "Accord",
          carColor: "Blue"
        };
        
        function paintCar(car, color) {
          car.carColor = color;
        }
        
        // GOOD 😎
        const Car = {
          make: "Honda",
          model: "Accord",
          color: "Blue"
        };
        
        function paintCar(car, color) {
          car.color = color;
        }
        ..

 

📝 Recap - Chapter 3. Functions 

  •  

 

 

🔍 Remaining questions

  • Moment.js
  •  

 

🔗 Additional Resources

 

Comments