Hacker News new | ask | show | jobs
by eropple 4405 days ago
> But there are a lot of ass hats who care if you should have built a function rather than copy and pasting the same code with minor variations 20 times.

That larger vocabulary you sneer at is much of what allows developers to be multiplicatively productive, allows them to do much more work and do it in a faster and less error-prone way.

Or, put another way: are they having to maintain your code when you get tired of it and move on or are they having to deal with second-order effects from your code being more brittle, less flexible, and slower to work on? 'Cause if so, they're not the asshat.

1 comments

I looked at the nightly order-processing workflow for the regional retailer I worked for one time. I was gobsmacked to find that one section of it consisted of launching the same suite of 5-6 programs one time for each of our 25 locations. And "launching" meant setting a handful of run-time variables, executing the object, waiting for it to finish running, and examining the result.

It was fairly easy to see why this happened. That workflow was the heart and soul of the company's revenue processing, and no one wanted to touch it any more than absolutely necessary, to avoid breaking anything. So when they expanded from one warehouse to two, it made more sense to simply re-iterate the existing code with the new location id. When they added another location, re-iterate it again, and so forth.

I created a Launch subroutine, then replaced all those hundreds of lines of code with a for loop that simply called the Launch subroutine for each object needed. Then I went through the rest of the workflow and swapped in Launch calls where appropriate. Overnight, that workflow became much shorter, more readable, and most importantly, significantly more maintainable. Previously, if you wanted to change what programs were run per branch, you had to insert the launching logic in twenty-five separate spots. Now? Once.

That, my friends, is why we build functions, rather than copypasta-ing the same code over and over.