Day 25 of #100DaysOfCode

Writing Clean Concurrent Code

If only writing clean code single-threaded application wasn’t hard enough already

Dhananjay Trivedi
The Startup
Published in
4 min readOct 12, 2019

--

Photo by Wes Hicks on Unsplash

Your multithreaded code might look easy on the surface but deep down it might be broken.

Why do we need Concurrency?

It helps in decoupling our code, decoupling what gets done from when it gets done. In a single-threaded application, you can determine the state of the program exactly by looking at the stack trace. We use breakpoints for the job which is quite fair and simple.

Writing multithreaded improves the structural and performance of your program. From structural POV, it looks like multiple computers collaborating instead of one single main loop. This makes your system easier to understand, and there are some other benefits as well.

Imagine you have a new website that shows news from all the other websites combined. You have a web scrapper that scraps news from different websites one after the other.

--

--