I really like your comment on how unnecessary else blocking introduces nonlinearity into your code. I thought I was writing clean code prior but leveraging better if placement has been a huge improvement for me over the last year or so
On top of limiting my use of else blocks I've also found (mostly) eliminating loops and opting for filter, map, and reduce operations instead has also been a huge improvement - I didn't realize how much of an implicit spaghetti-mess loops can be compared to their more explicit functional counterparts
Small improvements like this build up into some really elegant code - thanks again for sharing! :D
Technical writer at ConfigCat | Software developer working primarily with PHP/Laravel and JavaScript. Writes about PHP, WordPress, JavaScript, and programming in general.
Thank you very much, @chrisgreening. I'm glad you took the time to read my little article and even found something valuable in it.
You mentioned replacing loops with filter and map. Do you have any pointers? I'd be glad to read up.
introduces immutability (easier to ensure the state of objects, variables, etc. aren't changing in unexpected ways between operations)
reduces variable scope and side effects (and thus less cognitive overhead on the developer/maintainer)
explicitly states your intentions (instead of having to read through a for loop and understand what it's trying to accomplish, a map, filter, reduce or similar operation immediately tells you why the iteration is taking place and what the expected output will look like, no guessing games)
All these together sum up to some really beautiful code that chains together cleanly and reduces unexpected behaviors significantly improving readability
Technical writer at ConfigCat | Software developer working primarily with PHP/Laravel and JavaScript. Writes about PHP, WordPress, JavaScript, and programming in general.
Thanks so much for sharing!
I really like your comment on how unnecessary
elseblocking introduces nonlinearity into your code. I thought I was writing clean code prior but leveraging betterifplacement has been a huge improvement for me over the last year or soOn top of limiting my use of
elseblocks I've also found (mostly) eliminating loops and opting for filter, map, and reduce operations instead has also been a huge improvement - I didn't realize how much of an implicit spaghetti-mess loops can be compared to their more explicit functional counterpartsSmall improvements like this build up into some really elegant code - thanks again for sharing! :D
Thank you very much, @chrisgreening. I'm glad you took the time to read my little article and even found something valuable in it.
You mentioned replacing loops with filter and map. Do you have any pointers? I'd be glad to read up.
I'm glad you took the time to write and share :D really valuable insights, keep it up!!
Here is a really great article on mapping instead of looping:
map vs. for loop. I almost never use for loops in… | by Andrew Crites | Medium
Andrew Crites ・ ・
Medium
Basically I've found using operations like this:
forloop and understand what it's trying to accomplish, amap,filter,reduceor similar operation immediately tells you why the iteration is taking place and what the expected output will look like, no guessing games)All these together sum up to some really beautiful code that chains together cleanly and reduces unexpected behaviors significantly improving readability
Thanks a lot. I'll definitely read up.
Cheers! Keep up the great work, can't wait to read your next blog posts :~)