When you try to build things, do you stare at a JavaScript file and feel unsure about how to begin?
If this happens to you, youโre probably afraid of failing โ youโre so scared that you rather someone give you answers than face the possibility of getting it โwrongโ.
Many people who get stuck here call this the coderโs block โ itโs similar to writerโs block, where a writer doesnโt know what to write.
But the good news is, thereโs no such thing as a coderโs block โ itโs a myth.
You can overcome any coderโs block easily once you know what to do.
Breaking out of coderโs block
To break out of coderโs block, you need to accept that failure is part and parcel of building things โ youโll get stuck, youโll write shitty code, and you may feel like youโll never be able to make that thing.
Once you accept this, you can put aside your fear of failure and focus on these four steps:
- Break down the problem into small problems
- Find solutions to your small problems
- Assemble the solutions
- Refactor and improve
Step 1: Break down the problem into smaller problems
Answer this question: How do you put an elephant into the fridge?
If youโve heard of this question before, you know what the modal answer is:
- Open the fridge
- Put the elephant in
- Close the fridge
Problem solved.
Now this answer is a big joke because you still donโt know how to actually put an elephant in the fridgeโฆ
But even though itโs a joke, many people approach web development the same way โ they throw out a big question and expect to get an easy answer (like put the elephant in and close the fridge).
In reality, you need to be able to break the problem down into many smaller problems. And you do this by asking questionsโฆ
For the elephant example, here are some questions that pop up:
- What fridge are we talking about?
- What kind of elephant are we talking about?
- If the elephant is too huge to fit into the fridge, what do you do?
- Where do you find the elephant in the first place?
- How do you transport the elephant to your fridge?
Donโt worry about the correctness or size of the questions you think up โ just write them all down and break down them into smaller questions. If you canโt break your smaller questions down further, thatโs fine.
Step 2: Find solutions to your small problems
Now pick one of your small problems โ any one of them โ and start trying to solve them. Be as detailed as possible. If you can code, code.
For example:
- What fridge? โ The fridge that sits in your kitchen
- What kind of elephant? โ The african bush elephant
- What if the elephant is too big? โ Get a shrink gun (๐ซ) to shrink the elephant ๐
- Where do you find the elephant? โ Africa
- How do you transport the elephant? โ Put it in your bag after youโve shrunk it, then take a plane back home.
At this point, you may realize that some problems remain too big to be solved. When this happens, you break that problem down into even smaller problems.
In the example above, answers #3 and #4 are still too vague. So, letโs break it down further and get some answers.
- Where do you get the shrink gun? โ Borrow from the mad scientist next door.
- Where in Africa can you find the elephant? โ Addo Elephant Park in South Africa.
Once you have the answers to all your small problems, youโve effectively solved the big problem. Whatโs left is to piece them together so your solution works.
Step 3: Assemble the solutions
For the elephant example, you can probably follow along with the steps now:
- Get a shrink gun from the scientist next door
- Fly to South Africa
- Travel to Addo Elephant Park
- Find an elephant in the park
- Shoot the elephant with the shrink gun
- Put the shrunk elephant in your bag
- Travel back to the airport
- Fly back to your country
- Travel to your house
- Put the elephant in your fridge
Problem solved. Sounds logical, yeah?
Itโs important to get practice by breaking bigger problems down into smaller ones โ once you get to a small enough problem, youโll naturally come to an answer. It might not be the best solution, but at least it works!
And when you have one answer, youโll gain the confidence to work out the rest of the problems you hadโฆ and after a while, you would have solved the big problem without even noticing.
When you have a solution that works, you can improve the solution if you want to โ this is where we go to step 4.
Step 4. Refactor and improve
You probably have spaghetti code the first time you piece your solution together โ itโs messy, itโs ugly, and it goes all over the place.
Thatโs ok.
When you can spare some time, you can clean up the clutter and refactor your solution โ so you improve your code to a point where it doesnโt feel hacky and messy.
Weโll go through the refactoring process together later in the course so youโll understand when you should refactor and why.
Wrapping up
Coderโs block is a myth.
If you donโt worry about the quality of your code, you wonโt get blocked.
Everyone starts somewhere so your best action right now is to start โ start by breaking problems down and writing shitty code to solve those problems.
And donโt worry about improving your code for now because weโll do it together in a later chapter.
With this, youโre ready to begin coding.
Welcome! Unfortunately, you donโt have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson