CS462 Blog Post #1

It feels good to get back into it! And now that we are really focusing on the code-writing aspect of things this term, it is important to talk about writing clean code, and noticing when your code smells.

One thing I would like to do more of this in write clean code, specifically writing readable code. I always find code that is easy to read, even though it’s written in a programming language syntax very satisfying. And especially when working with a team, it is essential. To achieve this readability, I think it is also important to follow the DRY (Don’t Repeat Yourself) principle as well. It keeps things simple and easy to read and follow along.

An example of the difference between Dry and Non Dry Code

FIND tWo Squares – Non Dry
const a = 2**2
const b = 4**2
return sqrt(a + b)
FIND tWo Squares – Dry
const square (number) => number ** 2

const a = square(2)
const b = square(4)
return sqrt(a + b)

The Dry is easier to ready and it is more reusable. And if you ever needed to change the way that function worked, you only have to change it in that one function, not in every place where you squared the number. Much Easier!

Print Friendly, PDF & Email

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *