Day 366

Chep
3 min readMar 24, 2023

--

Well I figured since I’m going to be spending so much time coding I can knock out two goals with one by making this a coding blog. Thus, I’ll be writing about learning to code until I’ve chopped sufficient wood and carried sufficient water that coding is second nature. Brace yourselves peeps: codingChep is here. First lesson: inheritance!

//Rectangle class for clarity
class Rectangle {
constructor(length, width) {
this.length = length
this.width = width
}

area() {
return this.length * this.width
}

perimeter() {
return this.length * 2 + this.width * 2
}
}

export default Rectangle


//Instead of writing out all this

import Rectangle from './Rectangle.js'
class Square extends Rectangle {
constructor(sideLength) {
super()
this.width = sideLength
this.length = sideLength
}

}

export default Square

//We could use to do inheritance this

import Rectangle from './Rectangle.js'

class Square extends Rectangle {
constructor(sideLength) {
super(sideLength, sideLength)
}
}

export default Square

This way, when we call the super, we're passing the length and width arguments required by the Rectangle constructor. Since the Rectangle constructor uses these values to assign the width and height properties, we don't have to do any additional work. It is important to be careful with Inheritance. Most developers will encourage you to use inheritance sparingly. It can be overly used, and it's often tempting for beginners to implement it where it's not necessarily warranted or needed.

Inheritance is an important concept in object-oriented programming where a new class is created by inheriting properties and methods from an existing class. While inheritance can be useful for reducing code duplication and increasing code reuse, it can also lead to several problems if not used carefully. One of the main issues is tight coupling, where changes to the parent class can have unintended consequences on the child class. This can lead to a domino effect, where many parts of the codebase need to be updated. Additionally, inheritance can also make it difficult to maintain code and understand the relationships between classes.

Because of these potential problems, most developers recommend using inheritance sparingly. Instead, it is better to use composition or interface implementation to achieve code reuse. Composition involves creating a new class that contains instances of other classes, while interface implementation defines a set of methods that must be implemented by a class. Both of these methods allow for code reuse without the tight coupling that can occur with inheritance. By being careful with inheritance and using other methods of achieving code reuse, developers can create more maintainable and flexible codebases.

On another note I went to a Mass Adoption Bitcoin meetup tonight and it was an absolute pleasure getting to chat with other Bitcoiners. So much signal. One thing I’ve been thinking about is reforming the system vs burning it all down. Hopefully Bitcoin can allow for the former, but who knows. Humans are messy. It will be interesting to see how it all plays out. Anyways, I’m exhausted. Long day and I need to get some sleep for my first systems check tomorrow so I will end this by noting I need to check out Zion and also spend more time leveraging Nostr. I got zapped 46 sats already for this post.

https://iris.to/note1mya9qxdl8t8trvjlh2ua9c86yyaqc4zueekpzqtjhfplf0q3aersdz6e7f

A photo I took the other day.

3/23/23

Conor Jay Chepenik

--

--

Chep

I've decided to write everyday for the rest of my life or until Medium goes out of business.