Cleaning Your Coding with Clean Code

*not* this kind of cleaning

“Clean code is code that has been taken care of. Someone has taken the time to keep it simple and orderly. They have paid appropriate attention to details. They have cared.” — Robert C. Martin

  • Easy to understand the execution flow of the entire application
  • Easy to understand the role and responsibility of each class
  • Easy to understand what each method does
  • Easy to extend and refactor
  • and more…

Naming Variables

var a; // elapsed time in days
var elapsedTimeInDays;
const yyyymmdstr = moment().format(“YYYY/MM/DD”);
const currentDate = moment().format(“YYYY/MM/DD”);
if (student.classes.length < 7) {// Do something}
if (student.classes.length < MAX_CLASSES_PER_STUDENT) {// Do something}

Making Functions

“The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that.” — Robert C. Martin

  • Functions that are lengthy
  • Functions that are difficult to understand and test
  • Functions names that are vague
  • Functions that are fragile
Before and after making a function “clean”. https://dev.to/gonedark/writing-clean-code
function greetings(timePhase:string) {if (timePhase === “morning”) {console.log(“Good Morning”);} else if (timePhase === “afternoon”) {console.log(“Good Afternoon”);} else if (timePhase === “evening”) {console.log(“Good Evening”);} else {console.log(“Good Night”);}}// callinggreetings();
function printGreeting(greeting:string) {console.log(greeting);}function greetings(timePhase: string) {let greeting = ‘Good’ + timePhase;printGreeting(greeting);}
https://www.slideshare.net/mariosangiorgio/clean-code-and-code-smells
https://www.slideshare.net/myposter_techtalks/concepts-of-clean-code-adapted-for-javascript-techndrinks-myposter
Beware the dead! https://twitter.com/intelsoftware/status/925432702781837312

Conclusion

--

--

--

Undergraduate Computer Science Student

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to set up express App and generate a single model using Node.js(express

How to send the JSON data from a Drupal 8 site?

Asynchronous JS in < 30 lines of code

10 Best Angular Development tools for Developers | AchieversIT

Bypass IP Restrictions with Burp Suite

Redux: A Gradual Approach (Part 2)

Javascript part 12

The current state of Internet Explorer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Muhammad Fadhil Qorano W.

Muhammad Fadhil Qorano W.

Undergraduate Computer Science Student

More from Medium

NoSQL — Top 9 Interview Questions & Answers

It looks S.O.L.I.D !

XML Validation with dtd on VSCode

How does HashMap work in Java?