r/ProgrammerHumor • • Nov 25 '22

Meme Coding strategies

Post image
52.2k Upvotes

385 comments sorted by

View all comments

3.9k

u/faze_fazebook Nov 25 '22

super modular code that can cope with changing requirements :

gets so complicated that it gets scrapped by the next developer

1.4k

u/bam13302 Nov 25 '22

I've literally been both devs in that comment for the same code, twice. As in, wrote code, scrapped it for being unmaintainable and wrote new simpler easier to maintain, then had to scrap it and write new code again.

656

u/sillybear25 Nov 25 '22
  1. Thoroughly field-tested code with all the weird exceptions, edge cases, and other discovered requirements covered: "This code is so complicated! It's not even worth refactoring, so let's just scrap it and start over."

  2. Rewritten code: "It used to frobnicate instead of mogrifying when you click the 'download' button after sorting the table by reverse priority order during a month with two full moons. The customer needed that functionality yesterday, get it fixed and pushed to prod ASAP."

  3. Several top-priority bug-fixes and tens of thousands of man-hours later: All the weird edge cases, exceptions, and unspoken requirements have been rediscovered and implemented. Go to 1.

208

u/No-Witness2349 Nov 25 '22

Occasionally you can genuinely find abstractions which make expressing and maintaining those requirements easier. Designing a high-quality rule system can be difficult, but often well-worth it, imo

87

u/CanadaPlus101 Nov 25 '22

That's the dream, isn't it?

→ More replies (8)

107

u/DoktorMerlin Nov 25 '22

3. Several top-priority bug-fixes and tens of thousands of man-hours later: All the weird edge cases, exceptions, and unspoken requirements have been rediscovered and implemented. Go to 1.

You forgot that these top-priority bug-fixes (and feature-requests) are top-priority while coding but then this part of the software is never used once by the customer. 7 months later you are asked how the functionality works only to figure out that it has never worked in the first place because the SQL query is containing a syntax error

48

u/sillybear25 Nov 25 '22

Nah, the bug reports wouldn't exist if the functionality was never used by the customer. (You think we're spending money on QA when refactoring is "too expensive"? Ha!)

No, it's used roughly once every couple of years by the manager of the customer's purchasing department, who misunderstood the requirements relayed to them by the manager of the people who actually use the product.

→ More replies (5)
→ More replies (1)

31

u/tangentandhyperbole Nov 25 '22

Its funny how similar this is to architectural design.

Floor plan that incorporates all the required structural and client needs, is designed around real world products.

But you need to rotate part of it 5 degrees.

There is an overwhelming urge to reach for File > New

→ More replies (6)

213

u/Ler_GG Nov 25 '22

aGILE iS gOOD

51

u/marcosdumay Nov 25 '22

Well, actually, the faster you can rewrite, the less you have to protect against it.

→ More replies (1)

97

u/invalidConsciousness Nov 25 '22

With waterfall as the alternative, agile is preferable.

Agile is like democracy. It's shit, but it's less shit than any other alternative.

→ More replies (26)
→ More replies (5)
→ More replies (3)

93

u/Alarid Nov 25 '22

"It's too modular" says management.

69

u/tomkat0789 Nov 25 '22

“What we need is a tightly integrated monolith… yeah it could probably be modified later for those other products and their corner cases. It’ll be fine.”

35

u/TheAJGman Nov 25 '22

We aren't even launched and we have to re-architect the monolith because our contractors through the design docs were "guidelines". As a plus I get to engineer a few systems from the ground up with no tech debt; it's a rush to assert my will on the codebase like that.

19

u/SuspiciouslyElven Nov 25 '22

You guys had design docs?

→ More replies (1)

46

u/[deleted] Nov 25 '22

A team lead at AT&T told me that a single function shouldn't be too clever because that makes it harder to read, maintain, and reuse. This was in reference to a monstrosity I created that would take in an object of data that could have arbitrarily nested arrays and objects and try to transform them into html groups, headings, tables, etc. I made it a little too clever when we wanted to handle some data differently so I added a second parameter for transformation options like rules for pluralizing, sorting, or entirely replacing some keys.

I started this solution because they gave me 2 or 3 days to model and map literally hundreds of fields into a very simply formatted series of tables. The tedium was so great that doing it by hand would actually take longer than the time allotted. It was actually great for a few sprints that whenever we wanted to add another massive page they could just pipe the data through my ember component. But eventually we started adding overseas people to the teams and coordination was harder and they were much less skilled, so the team lead tasked a few people with converting all of those pages to html.

Unfortunately they didn't ask me to. They were happy with the generated output, but they wanted it to be easier to maintain by the new folks. That's all well and good, but we could have saved a lot of dev hours if they mentioned that so I could tell them to just capture the html being generated by the component instead of writing all of the HTML since they were not changing names, orders, or styles lol.

And that's my story :)

13

u/shrubs311 Nov 25 '22

this is the most classic software developer horror story lol it has everything

→ More replies (3)
→ More replies (1)

67

u/vhite Nov 25 '22 edited Nov 25 '22

Yeah, I work with something like that, large codebase elegantly divided into modules and plugins. It usually works like this.

Layer 1 - General top level function handling basic logic between several components. Calls specific component functions.

Layer 2 - Component's outer interface function, has few parameters to appear simple, does pretty much nothing but some boilerplate to call internal component function.

Layer 3 - Internal component function, takes dozen parameters with mysterious meanings, and uses dozen more private states and variables and has even more boilerplate. You think you're are finally getting to the core functionality you're trying to uncover, but then...

Layer 4 - DoTheThing function. Short and simple, the only problem is that it doesn't do the thing. Instead is calls some higher communication interface with an action flag and some data, and then shoots it into the oblivion.

Layer 5 - You have finally reached the point where the flag is being processed, at least you think so because the direct path was lost in a dozens of communication interface functions and so you just searched for the flag used in DoTheThing function. You found 6 results but this one looks closest to what you want. Here the interface notifies all the members of a mysterious array.

Layer ??? - You dig trough the origins of the array, it's type, initiation, all the instances where members are added, etc., but you only keep finding more abstractions. The name of the type suggest some higher level components, but you don't know which ones are in the array at the time it's being notified, and you don't know how the abstractions are connected to the actual components. Notify only calls an abstract function, and you have no idea where and by what it's being overriden. You're lost, cold, and you just wanna go home.

41

u/shrubs311 Nov 25 '22

Layer 2 - Component's outer interface function, has few parameters to appear simple, does pretty much nothing but some boilerplate to call internal component function.

it says "layer 2" but there's probably 2-4 of these

Layer 4 - DoTheThing function. Short and simple, the only problem is that it doesn't do the thing.

me after spending two hours looking at our codebase in layer 4: i'm convinced this app literally doesn't process the data

me after spending 5 hours looking at code: oh it's actually extremely simple

me 3 days later: it wasn't simple at all but i have tamed the code to do what i want, i'm a god at software development and imposter syndrome has been defeated (for the next 16 hours)

20

u/Discount-Avocado Nov 25 '22

Jesus. So relatable.

Finally you add 300 breakpoints where you think it could be. Turns out it’s none. Then you add 50 more and find it. You relieved, but then experience the same thing again when you reverse the logic and realize how insane it is.

→ More replies (2)
→ More replies (2)

26

u/mrheosuper Nov 25 '22

With 10000 Lines config file, this module can be used anywhere

→ More replies (1)

16

u/ImprovementTough261 Nov 25 '22 edited Nov 25 '22

This is something I struggle a lot with.

I always start my projects with modularity in mind, but then the spec changes and I have to add conditions to account for super weird edge cases.

Or the spec changes and a function is meant to do something slightly different, but it is already referenced everywhere throughout the program so it is not feasible to re-factor. Instead, I end up having to do some really hacky workarounds that would make this sub cry.

How do I combat this? Is the answer to just make everything even more modular until the program can resist all possible changes in spec? I feel like I would end up with hundreds of hyper-specific functions that way, which is hard to keep track off.

40

u/Tetha Nov 25 '22

Hm. I've kind of grown into a kind of effective lazy over the years, with ideas how to progress from lazy.

By now, if there is a requirement, I tend to write the most simple and straightforward code possible. Like don't bother with anything. Is there a requirement for different database engines? Pfsh, just hardcode some ORM to postgres during startup. No one asked for XML or YAML on an endpoint? Pfsh, hardcoded JSON decoding it is. And then just add the most boring straightline code to make whatever they want work.

And if you need to add something new, embrace copy-pasting code (for now). Just take whatever is doing 60% of what's doing what you need now, copy it, adjust it, stop bothering. Yes this violates DRY and that's good, keep reading.

However, there are two important off-ramps and de-tours to look at there.

One is the three-times rule, or the same-bug rule, or the same-change rule. If you have the exact same code in three places, try to extract some abstraction. If you have to introduce the same new feature, or fix the same bug in three or maybe two places, try to introduce an abstraction so you have to fix it once.

Code isn't duplicated because it's the same code. Code is duplicated because it changes together and because it gets fixed together.

And additionally, if you have to change a function, a class, or something, consider the open-closed principle. A class or a function should be open for extension, but closed for modification. So if a method, function, or class has to change behavior, it's good to think if you could introduce some callback, some function parameter, some interface to call into. Something like that.

This is good imo, because if you have to change a detail about a function once, you will have to change that detail more often. So it is good to add a way to add functionality by injection, without changing existing code. This avoids breaking old stuff, because you add stuff, and if the added stuff is broken, just turn it off.

This way, I've found that the systems I touch or stand up start entirely naive and stupid, but they change and mold to accept the changes in requirement the business needs. Instead of putting up an idea of these abstractions and then the requirements move entirely left field and shit becomes weird. Or you know, requirements don't change and we have some entirely dumb code running for years.

→ More replies (9)
→ More replies (1)
→ More replies (11)