Skip to content

Commit

Permalink
fix intro
Browse files Browse the repository at this point in the history
  • Loading branch information
zakirullin committed May 10, 2024
1 parent c690fc8 commit ab24326
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
## Introduction
There are so many buzzwords and best practices out there, but let's focus on something more fundamental. What matters is the amount of confusion developers feel going through the code.

Confusion costs time and money. **Confusion is caused by high cognitive load**. It's not a fancy imaginary concept, it's a fundamental constraint, and we can feel it.

Since we spend far more time reading and understanding code than writing it, we should constantly ask ourselves whether we are embedding excessive cognitive load into our code.
Confusion costs time and money. **Confusion is caused by high cognitive load**. It's not some fancy imaginary concept, it's a fundamental human constraint, and that makes it of the utmost importance.
Since we spend far more time reading and understanding code than writing it, we should constantly ask ourselves whether we are embedding excessive cognitive load into our code.

## Cognitive load
> Cognitive load is how much a developer needs to think in order to complete a task.
Expand Down Expand Up @@ -56,20 +56,6 @@ We will refer to the level cognitive load as follows:
`🧠++`: two facts in our working memory, cognitive load increased
`🤯`: working memory overflow, more than 4 facts

## Inheritance nightmare
We are asked to change a few things for our admin users: `🧠`

`AdminController extends UserController extends GuestController extends BaseController`

Ohh, part of the functionality is in `BaseController`, let's have a look: `🧠+`
Basic role mechanics got introduced in `GuestController`: `🧠++`
Things got partially altered in `UserController`: `🧠+++`
Finally we are here, `AdminController`, let's code stuff! `🧠++++`

Oh, wait, there's `SuperuserController` which extends `AdminController`. By modifying `AdminController` we can break things in the inherited class, so let's dive in `SuperuserController` first: `🤯`

Prefer composition over inheritance. We won't go into detail - there's [plenty of material](https://www.youtube.com/watch?v=hxGOiiR9ZKg) out there.

## Complex conditionals
```go
if val > someConstant // 🧠+
Expand Down Expand Up @@ -114,6 +100,20 @@ stuff // 🧠+

We can focus on the happy path only, thus freeing our working memory from all sorts of preconditions.

## Inheritance nightmare
We are asked to change a few things for our admin users: `🧠`

`AdminController extends UserController extends GuestController extends BaseController`

Ohh, part of the functionality is in `BaseController`, let's have a look: `🧠+`
Basic role mechanics got introduced in `GuestController`: `🧠++`
Things got partially altered in `UserController`: `🧠+++`
Finally we are here, `AdminController`, let's code stuff! `🧠++++`

Oh, wait, there's `SuperuserController` which extends `AdminController`. By modifying `AdminController` we can break things in the inherited class, so let's dive in `SuperuserController` first: `🤯`

Prefer composition over inheritance. We won't go into detail - there's [plenty of material](https://www.youtube.com/watch?v=hxGOiiR9ZKg) out there.

## Too many small methods, classes or modules
> Method, class and module are interchangeable in this context
Expand Down

0 comments on commit ab24326

Please sign in to comment.