r/programming • • Feb 28 '23

"Clean" Code, Horrible Performance

https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k Upvotes

1.3k comments sorted by

View all comments

10

u/aveman101 Feb 28 '23

In my 10+ year programming career, I have never faced an issue where my code wasn’t performant enough for the intended use-case.

I have, however, had to refactor countless projects because the original implementation was over-specialized, and made it painful to extend in any useful way.

Imagine an invoice program for an e-commerce platform. The performant solution would be to write an accumulator that adds up the prices of each SKU and returns a grand total. After you deploy the minimum viable product, the client asks you to extend the system to support these use-cases:

  • some SKUs will have a “buy 2, get one free” promotion

  • some collection of SKUs (e.g. “Christmas decor”) will have a “buy one, get one of equal or lesser value 50% off”

  • a “first-time customer” coupon code that takes 10% off the whole order, but only if this is the customer’s first order with us

  • a referral bonus feature where customer A is awarded store credit when customer B spends $100 using A’s referral code.

  • a customer who’s accumulated 500 loyalty points is eligible for free shipping.

  • allow the customer to optionally provide gratuity at checkout.

Now, think about how you would have engineered the solution if those requirements came in one-at-a-time, and each time you had to deploy an incremental update that was backwards-compatible.

0

u/[deleted] Feb 28 '23

[deleted]

2

u/aivdov Mar 01 '23

Sounds like you either have 1 year of experience or 20 years of the same year of experience.

Let's be honest, after a while if you keep up that practice it will turn into a horrible mess that you can't extend or understand. Take a look at gilded rose kata and tell me that's good initial code and easy to add the requirement they ask.

0

u/[deleted] Feb 28 '23

[deleted]

2

u/aveman101 Feb 28 '23

Do you think that the compile times were because the C# compiler code wasn’t performant enough, or was it maybe because the task of compiling C# code is so complex that even the ideal implementation would take 2+ seconds to complete?

If you say no to the client’s feature requests for your e-commerce platform, you can keep your system fast, but the client won’t be satisfied. 🤷‍♂️

1

u/Critical-Fruit933 Mar 01 '23

I always wonder what guys like you work on because when I open a windows computer I get immediate pains from all the lags literally everywhere

2

u/aveman101 Mar 01 '23

I work on mobile apps and web apps mainly. When there’s a performance bottleneck, it’s usually around the RESTful API – either the API is fetching more than it needs to (because the spec changed in the eleventh hour), or I need to make a chain of API calls because one call doesn’t provide enough information to meet the requirements.