DEV Community

Cover image for Problem-solving techniques to avoid yelling at your computer

Problem-solving techniques to avoid yelling at your computer

Damian Demasi on April 12, 2022

I have been facing some tough code monsters at work lately. I guess I'm out of shape and my sword isn't sharp enough, because I find myself struggl...
Collapse
 
calebanthony profile image
Caleb Anthony

I think this type of problem-solving is where TDD really shines. It gives you a space to write your ideal code and how you would prefer things work. Then you get to go out into your application and make that code a reality with the helpful guiderails of your test.

Collapse
 
colocodes profile image
Damian Demasi

Interesting take. Thanks for sharing it!

Collapse
 
akostadinov profile image
Aleksandar Kostadinov • Edited

I think yelling at computer is a mindset. No rules can help you unless you stop expecting things to work as expected. Problem solving is another point.

hate programming

Collapse
 
colocodes profile image
Damian Demasi

I think the problem is not about the expectation of things working as planned, but our reaction to the moment in which they don't. We shouldn't feel angry, upset, or disappointed. Instead, we should remind that this is a process, and failure is just part of the process.

Collapse
 
techman09 profile image
TechMan09

Nice article! But what if we love throwing words at our computers???

Collapse
 
colocodes profile image
Damian Demasi

Go for it! 😅

Collapse
 
ebrahimmfadae profile image
Ebrahim Hoseiny Fadae

Interesting subject! Thanks for sharing.

Collapse
 
kraftaka profile image
Kubat Aiupov

Awesome Article. Damian thank you.

Collapse
 
colocodes profile image
Damian Demasi

I'm glad you enjoy it!

Collapse
 
justmedev profile image
justmedev

The article by itself isn't bad, the example is.
You took an example and solved it by slowly reducing it into multiple smaller steps. This, by itself is fine. But you managed to end up with a less readable and over engineered example.

You could simply do:

const rows = 5;
let out = '';
for (let i = 0; i < rows; i++) {
  out += `${'#'.repeat(rows - i)}\n`;
}

console.log(out);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
colocodes profile image
Damian Demasi • Edited

That's a great improvement over the final code! 👍

I think the example's objective is to demonstrate the reasoning behind the solution of a problem, and not the most efficient way of writing code. The example is also not using any other method apart from the for loop and the console.log() method. In your case, the inner for loop gets replaced by the repeat method, which adds an extra step of complexity and deviates from the initial objective of the example.

I think your solution could be presented as an extra step in the problem resolution: "improve and make the solution more efficient".

Collapse
 
mfurmaniuk profile image
Michael

Great stuff. Remember about Plans though, they are good until they encounter the enemy, so prepare to be adaptable as well.

Collapse
 
colocodes profile image
Damian Demasi

Totally!

Collapse
 
stevebmurphy profile image
Steve Murphy

Brilliant article.

Collapse
 
colocodes profile image
Damian Demasi

Thanks, Steve!