Issue#30 - Clean Code: Separate Query from Modifier
Keep your code clean following this simple technique
I took a long break (2 months) from my newsletter writing. I have been mostly busy with work, personal life and travel. I am rethinking the structure of this newsletter and will experiment a bit with different type of content before I find the right fit. Hope you would stick around and thank you for reading this newsletter all this time.
Knowledge Byte
One of the technique to keep code clean is keeping query and modifier separate. This means, functions should either return(query) or change something (modifier), but not both at the same time.
❌ Bad (Mixing Query & Modifier)
✅ Good (Separate Query & Modifier)
Why This is Better?
calculateCartTotal
is now a pure function (query) that simply returns the total without modifying the cart.The separation makes code easier to test, understand, and maintain.
Links Around The Web
FFMEG is a collection of libraries which can be run through command line for processing multimedia files. I find this to be very useful for working with media files locally without having to install heavy softwares. Very useful for doing small task quickly like converting one file format to another(wav to mp3, mp4 to gif), trimming audio, merging video or audio files and other advance staff all through command line. Check out the link to see some really good examples.
CSS tricks for HTML Dialog elements
I think CSS going through it's best era, features that were only possible through JS like disabling the body scrollbar when a modal is open, are now doable with CSS. Check out the blog to learn more.
I don’t think there is any better way to ship good code at enterprise level without code reviews. It is one of the best way to mentor junior programmers, great for pair programming and overall when someone go through your code, you may get a new perspective you didn’t have before.
You only learn the advanced stuff in Git when you screw up—and that’s the harsh truth. I’ve used most of the commands listed here only when my Git history got messed up. If you haven’t used any of these commands, you’re not Git-ting hard enough.
Books I am Reading
I am currently reading No Longer Human By Osamu Dazai. It’s a story of a young man who can’t fit into society, struggles with feelings of alienation and have addiction problems. The book explores themes of depression, isolation, and self-worth and it somehow reflects the life of the author himself, who also suffered from depression and committed suicide. Favorite quote from the book-
I felt as though the vessel of my suffering had become empty, as if nothing could interest me now. I had lost even the ability to suffer.
My unhappiness stemmed entirely from my own vices, and I had no way of fighting anybody.
Great read!