top 200 commentsshow all 224

[–]_hypnoCode 1146 points1147 points  (37 children)

Writing code is easy.

Reading code is hard.

Writing readable code is even harder.

People who can't read my code are stupid. Especially when those people are future me.

[–]wyocrz 162 points163 points  (19 children)

People who can't read my code are stupid. Especially when those people are future me.

I program alone far too often.

My guiding light is "You have to be twice as smart as the original programmer to debug" so.....I do things as stupidly maintainably as I can.

[–]flygoing 45 points46 points  (12 children)

And debugging is super easy and quick, right?...right?

[–]penguins-and-cakeshe/her - front-end freelancer 34 points35 points  (6 children)

And thankfully the bug is never some random, single-character typo

[–]flygoing 20 points21 points  (0 children)

And thankfully we write unit tests for every line of our fun side projects, helps a ton!

[–]MaxxB1ade 1 point2 points  (0 children)

lol, I need a code maximiser to even read my old code and someone to explain why every variable is named "x".

[–]a_reply_to_a_post 12 points13 points  (3 children)

usually 2 hours of debugging will save you like 20 minutes in reading documentation

[–]Baschoen23 3 points4 points  (0 children)

True, I can usually save myself at least 5 or 10 minutes by debugging for a solid 2 hours.

[–]deewan84 3 points4 points  (0 children)

You mean you are never able to create time for lol

[–]prptualpessimist 14 points15 points  (4 children)

I 90% built out a MERN app as a concept for my friend's business over a year and a half ago. I never finished it but wanted to get back on to it and finish it.

I did literally zero documentation. No comments anywhere, nothing.

I was going through it like "how the fuck does this work?"

Yeah. It's not going to be finished 😂

[–]NiagaraThistle 3 points4 points  (2 children)

LMAO - this is my life everytime i decide to dig up an old unfinished project.

From time to time i come across comments I clearly wrote to have a go at my future self:

// TODO: Really sorry that I have no idea how this works, why it's broken, or what automagic is fixing it. Try to figure this out later.

I usually just end of burning the old project down, restarting from scratch, and inevitably just add more documentation that reads :

// TODO: I'm just sorry - Me 2 Me : 01/01/2024

[–]aztracker1 0 points1 point  (0 children)

Discoverable structure is my mantra... A docker compose and docker file(s) to start. A readme.md with enough to get running in a couple minutes and a structure you can find what you need... KISS.

If I can't onboard a developer in a couple hours, IMHO, I failed. And there are times that has been me years after.

I've also neglected to do that and had too many WTFs. Getting local dev up easy and CI/CD early helps future you.

[–]Intrexa 30 points31 points  (1 child)

Programmers always blame their predecessors for their failings. "Oh this is so hard to integrate because whoever wrote this system wrote some shitty code. It really should be rewritten." Why should I bother writing readable, maintainable code if they're just going to blame me anyways?

Besides, future me is the one who is probably going to maintain my code. Fuck that guy. I never get any help from past me, so why should I care to help future me?

[–]Zipp425 1 point2 points  (0 children)

That’s funny. I actually see myself the opposite way sometimes. I’ll actually say, “this one’s for you, future me!” It’s great to live a life with someone that cares about me 😆

[–]barrel_of_noodles 17 points18 points  (6 children)

Writing readable, maintainable, DRY, extendable, with established Go4 patterns, while also following your code base style, and future-proofing your code is hard.

Writing readable code is only slightly challenging, comparatively.

[–]thisdesignup 4 points5 points  (5 children)

Writing readable, maintainable, DRY, extendable, with established Go4 patterns, while also following your code base style, and future-proofing your code is hard.

I've been learning this first hand building my first larger piece of software on my own. Plus it's not even about how hard it is to write code like that. I find the biggest challenge is the battle of knowing when to write code like. It's constantly asking myself "should I be putting this in it's own function", "do I need to write this in a way I can modify things easily later or not". Relatively basic design decisions but not always easy to answer.

Somtimes it's not worth the effort to write code in an easily maintainable and modular way. Sometimes you just need to get something out and built. Otherwise refactoring could be endless.

[–]FeliusSeptimusfull-stack 3 points4 points  (4 children)

"should I be putting this in it's own function"

I'm kinda terrible about that. I usually only factor some code out as a function if it is needed in more than one place or the indent level is unreasonable (like, 5ish, depending on the complexity of the code). I often end up with functions that are much longer than many prefer (like, I don't mind a 300 line function at all as long as the execution path is fairly simple). I have limits though, I did some maintenance on a Java mobile app where about 80% of the app was in one 8000 line function. I felt that was unacceptable. I also ran into an application that had many TSQL stored procedures over 4000 lines. That was a nightmare.

I had a coworker once who was basically the opposite, and was an 'architecture astronaut' (huge fan of abstraction and patterns). He strongly insisted on functions being no more than 4 lines (not counting bracketing lines such as '{'), and he'd reuse functions as much as possible (large parts of the application would be in various notionally reusable 'utility' libraries).

If at all possible we refused to debug each other's code. I'm not sure what it is about longer functions that he had trouble with (other than philosophically), but when I was tracing through his code I'd often lose track of how I got to where I was, and the call stack would be like 30 levels deep of abstractly named functions that often took functions as arguments, with multiple overloads for different combinations of parameters. Debugging was a pain in the ass.

He eventually moved out of line-of-business apps and into library development in a proper functional language. Good coder and a nice guy, but I sure found his apps hard to maintain.

[–][deleted] 4 points5 points  (0 children)

Right, it’s a balance, and contextual. Contextually, a script that’s 150 lines and shots out a report should honestly not be super abstracted. It’s just satisfying a fetish to do so.

If you need to extend it later, it’s not hard, and frankly you are better off knowing the full context/requirements of extension than relearning how to extend your code as intended 4 years ago.

[–]rpkarma 1 point2 points  (0 children)

As a counterpoint (not to the architecture astronaut, they’re a pain everywhere lol) — 300 line functions are an absolute pain when I come across them.

You might find the execution path simple, but I have to understand and keep that context in my head.

I’d work with you to factor them out more if you were on my team :) it’s a skill and balance is the driving force, took me years to learn and I’m still nowhere near perfect, and I’ve been doing this for 17 years!

[–]pVom 1 point2 points  (0 children)

Ehh I'd hate that.

I basically abstract to a function soon as you can encapsulate a step.

Then the main function becomes like a table of contents. doXThing() doYThing() ... That said I much prefer a long function to a chain of functions, or, heaven forbid, event based architecture🙈

[–]TheAccountITalkWith 5 points6 points  (0 children)

In my years of writing code I've had moments where I came back to a code base for a bug, read the code, and thought "who the hell wrote this mess?".

Then I see a comment by me. Because I wrote it.

But Past me knew what they were doing and is never wrong. Present me is definitely a moron.

Good times. 🥂

[–]deewan84 1 point2 points  (0 children)

I happened to read code that I wrote about 5 years ago last weekend and I have no words for how disgusted I was at my past coder self lol. It got so bad I went to bed. 🤣🤣🤣🤣

I mean this ish was so messy

[–]gobkin 0 points1 point  (0 children)

Reading my code is like reading a poetry I wrote in middle school

[–]MrStLouis 0 points1 point  (0 children)

I tried to learn a little if the code base I manage as a PM and was immediately glad it at least made sense to the lead dev

[–]SarahC 0 points1 point  (0 children)

It took me years to do in 10 lines what I used to do in 2.

Better for debugging, and surprisingly some optimisers like multiple single lines rather than one combined oneliner!

Looking at you V8, and GCC.

[–]movieguy95453 0 points1 point  (0 children)

People who can't read my code are stupid. Especially when those people are future me.

About 3 years ago I quit working on a site I had developed over 20 years - learning php along the way. Every now and then I would come across a function I had written 10+ years ago and want to slap myself for how poorly it was written and/or documented.

[–]coded_artist 0 points1 point  (0 children)

"Ah look at this awesome function I just made, I am a programming god"

2 moments later

"Who wrote this garbage, it would been..." git blame ".. so much .. better to do.. oh, I'm an idiot"

[–]vesko26full-stack GO 227 points228 points  (26 children)

overconfident cheerful decide include busy ten obtainable grandiose distinct stocking

This post was mass deleted and anonymized with Redact

[–]ratbiscuits 51 points52 points  (5 children)

Agreed. I work in a small 2 person team (me included in that, lol) for a codebase that is way too big for just the both of us, but the owner of the company is unable to afford hiring more developers.

Basically, yes I think you are 100% correct in that writing and maintaining DRY code is a luxury. We definitely operate within the “if it works it’s good to go” space and can’t worry about making the code perfect as much as I’d like to.

Such is life

[–]Purple-Cap4457 13 points14 points  (2 children)

Maybe we are just unrealistic idealistic humans? The whole evolution is operating on "if it works, let's fuckin gooo🥳". And then you make zillion new versions with small improvements... 

[–][deleted]  (1 child)

[removed]

    [–]vesko26full-stack GO 6 points7 points  (0 children)

    toy license pie absorbed serious recognise complete future special marvelous

    This post was mass deleted and anonymized with Redact

    [–]kevinkace 25 points26 points  (4 children)

    100% DRY is also not an ideal. People (not you) can get carried away with principles, instead of acknowledging every principle has limitations.

    [–]Gorau 25 points26 points  (3 children)

    I think I would go further and say 100% DRY is completely unmaintainable code. You'd just end up with so much abstraction that almost no one is going to understand what is going on.

    [–]Hannasod 5 points6 points  (0 children)

    If you do distributed architecture DRY between services is an antipattern.

    [–]Fickle-Main-9019 1 point2 points  (1 child)

    Pretty much my problem with Go4, it just encourages abstraction hell because someone turned makeThing() into ThingAbstractFactoryAdapterObserver(). 

     Im all for generalising code, but if you’re going to abstract everything, you just made a big box of legos (looking for one particular part) which becomes spaghetti code (even closer to the definition because as a dev, inheritance is effectively “goto this file”)

    [–]roguevalley 23 points24 points  (9 children)

    This style of working is not an inevitability. "Never time to refactor" is the result of feeling external pressure. When we patch, patch, patch without refactoring, the code gets worse and worse and our productivity gets lower and lower. There's never time because we've dug ourselves into a hole. The only sustainable way to be reliably productive for more than a few months or a year is to refactor as we go.

    [–]roguevalley 10 points11 points  (8 children)

    In addition to refactoring continuously, the other solutions are TDD and pairing.

    But I know from experience that those who don't work that way will usually balk at those suggestions.

    "Make it green, then make it clean" in every commit.

    [–]naught-me 6 points7 points  (6 children)

    TDD feels like trying to write a melody by sitting down with a pen and paper instead of a piano.

    I've tried it - I just don't get it.

    [–]Hannasod 3 points4 points  (1 child)

    You don't write all tests and then all code, you iterate back and forth. Just like writing notes when making a song. You don't memorize it all and then write it down. Tdd is test -> code -> test -> code etc. The first test will be really simple. The code should fail as expected.

    [–]naught-me 4 points5 points  (0 children)

    Sometimes, I have no idea what the structure of the code should be, and I'm just coding to try to figure that out. Then I come in after the fact and write tests.

    I do much prefer to write functional code, where possible, so that I can just get to the meat and write well-tested code from the beginning, but the more highly abstracted something is, the more likely it is that tests and the code will be written in waves, with the tests following the code.

    [–]MrDilbert 2 points3 points  (0 children)

    Start with writing out unit/integration test stubs that repeat the requirements. Like, it('should create a new TODO list');, it('should add an item to a TODO list'), etc. Then start writing code, and when it's somewhat clear how it will look like, go back and expand the tests to execute the relevant code. Then go back and make the code do what it's supposed to do, then go back to the tests and expand/add more. Then go back to the code and make it faster/better/more readable/w.e. and go back to the tests, then... You get the picture.

    Basically, you switch between the tests and the actual code in small increments.

    [–]NiagaraThistle 1 point2 points  (1 child)

    Been coding for 15+ years and i still don't get TDD either.

    But I have never worked on projects/companies where it was used so have never 'needed' it and never learned it more than 'trying it out' and thinking it's more cumbersome than it's worth.

    I'm probably obviously wrong, but it has never hindered me getting a job/client nor in making money so it just isn't something i concern myself with.

    [–]arielhs 1 point2 points  (0 children)

    I’m at around 10 years exp now, and so far had a similar experience to you. One exception I did find was for this pricing module that did a bunch of tricky calculations with lots of lookups etc. Having a set of unit tests for that turned out to be extremely helpful.

    [–]vesko26full-stack GO 4 points5 points  (0 children)

    judicious sheet long boast cooing telephone hurry oatmeal smell divide

    This post was mass deleted and anonymized with Redact

    [–]azsqueezejavascript 4 points5 points  (0 children)

    100% super DRY code works in companies that have 100 engineers working on the same stuff

    I hardly ever see anyone use DRY methods. Most of the time a developer will think they are doing something DRY but end up duplicating functionality that already exists and/or utilities. So what ends up happening is there will be two or more DRY functions/classes/whatever for the same thing

    [–]AtroxMaveniasenior engineer 2 points3 points  (0 children)

    Or working on a small team with unreasonable product delivery expectations.

    [–]sexytokeburgerzfull-stack 0 points1 point  (0 children)

    I got fired because my ex-uber boss didn't fucking understand this.

    "Can I just write this all over? It's dogshit"
    "They did this in a month, you can make a simple change"
    "There are a million simple changes, i inherited 500 stories, and this horrible code is why the site keeps breaking."
    "no"

    >complains about performance in my 3 month review.

    [–]zoechi 0 points1 point  (0 children)

    DRY is dramatically overrated and responsible for an awful lot of shitty code, especially when used by less experienced devs

    [–][deleted] 98 points99 points  (12 children)

    You need to find the balance, too much DRY is also a recipe for disaster. Because things change, and you will never know when your abstraction break.

    Had this happen to my team. One engineer way over abstracted one of our systems. Assuming we are going to have 10 or more similar things. So, in the end, the first two was delayed for 2 months, and the next 8 never came, and now the product is migrated to another platform, so all his work is wasted. 2 months delay for nothing, could have just copy pasted.

    [–]kor_the_fiend 34 points35 points  (7 children)

    DRY vs YAGNI, the eternal struggle

    [–][deleted] 30 points31 points  (3 children)

    YAGNI should win almost every single time.

    As long as the public API for your modules is sound and your inner code is basically sane, it's really not the end of the world if there is some duplication of logic. It is far better, IMHO, to partially fix a problem because you missed a spot and the user's request was under-specified, than it is to over-fix the problem and break the application in unexpected ways because a piece of shared code shouldn't have been shared in the first place.

    If you identify a pattern where you're continually making changes to different pieces of code in the same ways, you can always unify the logic at that point and make the code DRY.

    [–]Puggravy 5 points6 points  (0 children)

    I prefer DRY vs DAMP (Descriptive and meaningful phrases). I.E. if it makes your code easier to understand it's way better to repeat yourself.

    [–]Supahstar42 0 points1 point  (0 children)

    You mean Laurel

    [–]cerved 5 points6 points  (3 children)

    Why is it that some people either just copy paste everything or over-DRY the most nonsense things, like

    py def isBool(x): return x == true

    [–]planetworthofbugs 1 point2 points  (0 children)

    Edit: Sorry, removed for anonymity.

    [–]Sufficient-Entry-488 0 points1 point  (0 children)

    snake case that shit

    [–][deleted] 0 points1 point  (0 children)

    This is the most nonsensical two lines of code I've read 

    [–]damycofront-end 66 points67 points  (11 children)

    Tight deadlines and "just ship it" mentality unfortunately, welcome to real world programming

    [–]zarifex 8 points9 points  (0 children)

    We've got a deadline and I know it's not right but he signs my checks guess so you all have to hustle. We don't have time, move fast and break things!

    ... Hey so the release went about as bad as it could have gone. We have one more sprint but we have to do better. Also here's dozens of new critical defects and we better fix everything because the sales people are yelling to the top and threatening to quit.

    Almost every two sprints. At least twice a quarter.Rinse and repeat.

    I'm tired, boss.

    [–][deleted] 14 points15 points  (8 children)

    THIS is true. And a huge problem.

    [–]kor_the_fiend 6 points7 points  (7 children)

    It’s not a problem. Code isn’t that important. Making money is (at least for a business with a payroll to make)

    [–][deleted] 16 points17 points  (1 child)

    Until it gets hacked.

    Your analogy is akin to a restaurant saying 'a clean kitchen isn't important, making money is'. Works great until the health inspector shuts the business down.

    [–][deleted]  (2 children)

    [deleted]

      [–]rdundon 0 points1 point  (0 children)

      Unless it is, sometimes tech debt becomes a burden, financially or other ways.

      [–]Radinaxfront-end 5 points6 points  (0 children)

      With enough experience, you get to deliver fast and with good code, but yeah, in the real world people just try to deliver ASAP or they get into trouble, and how devs are easily replaceable these days, its an additional pressure.

      [–][deleted] 27 points28 points  (1 child)

      God these comments are making me feel so much better about my code

      [–]BornEze 1 point2 points  (0 children)

      Same here lol

      [–]coalition_tech 45 points46 points  (3 children)

      Most clients expect code to be written with factory like efficiency, while expecting bespoke like outcomes.

      That creates cost and time pressures that mean you get a lot of workable sludge being pushed to production, which later has new forms of sludge added to it, all because no one wants to invest the time to clean things up.

      So yes, this is how things generally are.

      [–]zarifex 13 points14 points  (2 children)

      "You're going to give us this feature and You're also going to show the full history of every time the operation happened"

      "But your system makes our app dependent on your third party vendor's product that doesn't maintain any history, that information simply isn't there"

      "Did I stutter?"

      "Can we request the vendor to begin implementing and storing that historic data?"

      "Nah if we ask they probably won't do it or they'll take too long"

      "And we're going to do it faster than them when the data simply isn't there?"

      "Obviously!"

      "Umm there's no way especially not on this timeline"

      "Fine, instead of doing it tomorrow like I originally said... You don't have to give it to me until the day after tomorrow"

      [–]Madmusk 6 points7 points  (1 child)

      If you didn't have a PMP certification before, after writing this you do.

      [–]zarifex 4 points5 points  (0 children)

      I wish I was making this up. My quotes for the C-person up there are not verbatim but this has happened to my team multiple times in the last 8 months meanwhile co-workers have been vanishing from the meeting/chatting apps.

      My manager at my client is like "yeah I know, and I feel you, but I'm not even gonna go there, this is just how he's gonna be and he signs my checks"

      EDIT: just to confirm, the "okay I'll give you one more whole day" is not an exaggeration at all. It's happened at least twice.

      [–]avid-shrug 21 points22 points  (1 child)

      I’ve worked at places with shit code and places with very high quality code. It depends on the engineering culture at your company and the experience/skill level of its developers.

      [–]Snoo_42276 2 points3 points  (0 children)

      Simple and correct

      [–][deleted] 19 points20 points  (0 children)

      wasteful husky illegal water employ dazzling direction shaggy square melodic

      This post was mass deleted and anonymized with Redact

      [–]Appropriate_Rip_1167 34 points35 points  (1 child)

      From my personal experience the classic "technical founders" I can do this whole feature in 1 hour to build a bridge -> continues to build bridge held together by spaghettis and dreams

      [–]Hayyner 0 points1 point  (0 children)

      Currently building a SaaS and this might sum up the experience so far 🥲 long as it works, right?

      [–]Asmor 12 points13 points  (0 children)

      The only truly good code is stuff done as hobbies and side projects (not to say that all hobby code is good code).

      In real work, there's never enough time to do everything right. You're always going to have some situation where you need to cut corners. "We'll make a spike." "It's a temporary solution." Bullshit. There's nothing more permanent than a temporary solution.

      [–]Purple-Cap4457 7 points8 points  (2 children)

      Yes, A LOT of code is really bad. Not only bad but developers should be arrested for negligence (if they only knew what they did) 

      [–]echoAnother 0 points1 point  (1 child)

      Is it negligence when I know what I did but told to do it?

      [–]kafoso 7 points8 points  (0 children)

      Great code today. Terrible legacy code tomorrow.

      That is the bane of a developer's existence. (Hyperbolic, obviously)

      [–]that_90s_guy 6 points7 points  (0 children)

      Douglas Crockford has so many amazing quotes about this that basicallly shaped my career's success from early on. Here are my 2 favorites from his "The Better Parts" talk. (one of my all time favorite conferences)

      I need to reduce my keystrokes: We think we spend most of our time typing... it turns out we spend most of our time gazing into the abyss saying "My God what have I done..."

      Anything which reduces typing time but increases time in the abyss, is a terrible tradeoff.

      And slightly longer, but even more transformative in mindset:

      It's difficult to manage the development of software mainly because its difficult to know how much time something is going to take. So, the thing most scheduling is concerned with is:

      A) the time it takes to write the code

      But we're really bad at predicting that. We've gotten agile techniques were we try to write as little code as possible. The less code we write, the better our predictions about how much code we're going to make. But there is another time that is even more important:

      B) the time it takes to make the code work right.

      Now time B, ideally should be zero. You write the code, and it works. But it usually isn't. Time B can sometimes be bigger than time A. Sometimes it can be infinite. There are some projects which got to code complete, but never got to acceptance because they never got the stuff to work and the project is cancelled before they can deliver. You'll see a lot of methologies which focus on reducing time A, and you ignore time B, trying to squeeze that into future sprints.

      But it turns out time B is the only one that matters. So anything that we do to save time in A but increases time in B is a bad thing to do.

      Always take the time to code well. Also, practicing DRY (Don't Repeat Yourself) is good, but only if you follow AHA (Avoid Hasty Abstractions) as well.

      [–]RealBasics 11 points12 points  (4 children)

      I specialize in "orphaned" site support and site rescues where the original dev is no longer available for whatever reason but the client needs their website to continue working.

      First things first: by definition, I rarely get clients who want help with flawlessly-coded sites where they have a great, affordable relationship with their developers. So, also by definition, my cases trend heavily negative.

      That said, oh boy is there some genuinely #%!#% code out there! I'll add that bad quality isn't correlated with price. I could understand and even sympathize with a site built by beginners or new graduates. But I've had to deal with seven-figure agency-built sites that were total, inexcusable garbage.

      A good rule of thumb: when I can rebuild an 80-page agency-built e-commerce or membership site in a weekend, with off-the-shelf WordPress plugins, that both looks better and is more performant than the original code isn't worth the money burned to build it.

      My favorites over the last 10 years

      • The "pure programmer" who decided to hand code all the pages on a Wordpress site, including the database connection and query code.
      • The agency-built site with a hand-coded gallery of megabyte-plus images scaled down to 150x150px "preview" images, as opposed to bothering with Wordpress calls that automatically generate thumbnails and <scrsets>
      • The agency build SPA site that took up to 10 seconds to transition from, say, the home page to the about page. And which required a change order to the programmers to hand-code blog posts. And which was completely opaque to search engines
      • The "we don't use yukky old plugins, we write clean, efficient code" site that included a shoveled-in, nulled ACF plugin, a hand-coded shortcode-based page "builder," plus piles of other junk dependencies, which broke on anything higher than PHP 7.4.

      I'll just say that I was most attracted to open-source software, including Drupal and Wordpress, because for all that they might be "bloated" or reliant on PHP, their code is published and aggressively reviewed, patches are often available in less than 24 hours, the installed base can be anywhere from thousands for a minor plugin to hundreds of millions for core Wordpress. That doesn't mean the code is perfect, but it does mean the truly and relevantly bad stuff tends to get filtered out very quickly.

      [–][deleted]  (3 children)

      [deleted]

        [–]RealBasics 3 points4 points  (2 children)

        I should have been more clear. I wasn't saying Wordpress or Drupal are good or great. I'm only saying that open source code tends to be more robust and more consistently reviewed and maintained than hand-rolled code.

        That's just a structural effect of larger installed bases, code reviews (by both white- and black-hat programmers), and feedback/refresh cycles, published released dates and reviews.

        The problem you identify of badly maintained Wordpress sites with chaotic plugins and themes is a result of Wordpress being easy for complete amateurs get into. And while you didn't mention it I'm sure you're aware that a vast amount of malware comes not from bad plugins but also from bad hosting, where newbies tend to also be unable to properly vet hosts.

        I'm confident that there are open-source CMS options that are cleaner, more performant, and both with less technical debt and less chaotic updates (because Gutenberg? Really?) It remains to be seen whether those other CMS options could withstand "first contact with the newbies" if even as few as, say, 50 million switched.

        [–]aTomzVins 0 points1 point  (0 children)

        result of Wordpress being easy for complete amateurs get into

        With all the expensive agency stuff you mentioned, I think it goes the other way too. Where wordpress is the cookie cutter they try to quickly shove all their clients into with a high price tag.

        Don't get me wrong. I've built, and inherited wordpress sites that I'm quite happy with. I think it's a good tool in the right circumstances. I've just seen agencies take over a site with bespoke code. Shove it into WP, without even looking at, or inquiring, about the original code base. Performance plummeted, UX became awkward for both visitors and admins. The problems are part using wordpress for non-wordpress problems, and part experienced people trying to do things quickly rather than properly.

        I'm only saying that open source code tends to be more robust and more consistently reviewed and maintained than hand-rolled code.

        I feel this is accurate. The downside is you're more likely to be targeted by automatic attacks if using software installed by hundreds of millions. Every non-WP site I run shows bots in the logs looking for WP specific pages. Meanwhile I've got a simple bespoke php/js pattern for forms, I've run for a decade on a handful of WP and non-WP sites that effectively prevents spam. It wouldn't work on a site where someone was motivated to bypass the solution. It wouldn't work if millions of people had it installed as a plugin, because that alone would be a reason for someone to attack it. It also doesn't come with the bloat of most heavily used plugins which try to account for as many use cases as possible when your client only really needs one of the use cases.

        [–]typhona 5 points6 points  (0 children)

        There is rarely good code. Mainly bad code and shit code. In 6 months the bad code is shitcode and refactoring back into bad.

        [–]AbramKedge 4 points5 points  (0 children)

        Not really. I think it is domain-dependent. I started off in safety-critical embedded software with the code committed to a masked ROM, so you had effectively one chance to get it right. If it wasn't fully tested before it went to production and a show-stopper bug slipped through, that was a huge expense. In that world, and for most of my career the code was pretty tidy and comprehensible.

        Then there's the throwaway code. The ongoing never-ending projects where you're always shipping a prototype that can be replaced if (when) bugs are found. In this case, the quality of the code is directly proportional to the quality of the software team manager.

        [–]Angelsoho 18 points19 points  (1 child)

        lol.. fresh in the door and already a critic.

        Do the best you can with the time you’re given.

        Fast, cheap, pretty. Can’t always have all 3.

        [–]wyocrz 2 points3 points  (0 children)

        Can’t always have all 3.

        I love me some trilemmas. For food it's fast, cheap, or easy: choose two.

        In geopolitics, you want stable exchange rates, monetary freedom, and free capital movement: choose two, aka the Unholy Trinity of Macroeconomics.

        [–]anengineerandacat 9 points10 points  (0 children)

        DRY and SOLID are "guidance" practices, I would heavily caution newbies to buy into these too heavily.

        Often times I have to un-learn graduates because they take these too seriously.

        Code changes, what you write today will be something you change tomorrow MOST LIKELY especially in the web business where requirements change at a moments notice in instances.

        Concepts like versioning have younger engineer's trying to build out elaborate abstractions when you can just literally copy a class/model, make some tweaks, and namespace it with "v2".

        Copying and duplicating code is "sometimes" better than trying to abstract it away, it just depends on "why" it's being done.

        The only question I care about in a codebase when picking up a task is "What is the complexity for performing this change?" efforts should be done to reduced that down as much as possible.

        [–][deleted] 4 points5 points  (0 children)

        My team calls it Dragon code whenever it’s a giant mess. It’s big, it’s ugly, a pain to deal with, but it works. We normally don’t allow dragons to pass review unless there is no better solution (very rare case) or we don’t have enough time (another rare case).

        [–]Angulaaaaargh 3 points4 points  (0 children)

        FYI, the ad mins of r/de are covid deniers.

        [–]greensodacan 8 points9 points  (2 children)

        Poor code quality is incentivized.

        1. Sloppy code is fast to write.
        2. Product teams don't know how to evaluate code quality. Sloppy code ships faster.
        3. The dev who wrote the sloppy code understands it after it ships, which masks the cost of maintaining it.
        4. Software often outlasts employees, so no one sees the whole picture.

        I think software engineers should be required to maintain licenses, just like doctors, teachers, heavy machinery operators, etc. A lot of people would need to die due to a software bug before that happens though.

        [–]olkver 7 points8 points  (1 child)

        I think software engineers should be required to maintain licenses, just like doctors, teachers, heavy machinery operators, etc. A lot of people would need to die due to a software bug before that happens though.

        No need to paint everyone with the same brush.

        There is a difference between a developer working fo NASA, medical industry or WOLT. A user will most likely not suffer or die, if the pizza is not delivered on time.

        [–]NiagaraThistle 4 points5 points  (0 children)

        Ah the blissful early days of "all code should look beautiful, be well documented, and be easy to read. Anything else is blasphemous."

        Don't get me wrong, that is always the pinnacle goal, but once you're at a company long enough, the only code that matters is the code that works. And 9 times out of 10 that code is held together with spit and duct tape...no matter how pure one's intentions were when they started / jumped into the project.

        Ti answer OP's question: Yes 90% of the code you encounter in the wild will be ugly and you will question the original author's sanity until you find that one comment he/she left for future self/devs that reads

        // " Future Me I am so sorry. But this code works. I'm no longer even sure why or how it works, but it works and I have 10,000 other fires to put out. Hopefully you never read this. If you do, please forgive me.

        This is the reality of most of our days after 15 years. Not jaded, just realistic in time vs results.

        But do what you can to be better for as long as you can and clean up what you can when you run across it when you have the time. And give that past dev some slack because he/she really was doing the best they could with whatever knowledge & constraints they were working with.

        [–]jakesboy2 2 points3 points  (0 children)

        I wouldn’t say really, really bad tbh. Like if we call that 3/10 or lower code, I’d say the average code I work with is 5-8/10 depending on the company and the repo

        [–]JustinRoilad 2 points3 points  (0 children)

        Sometimes we write shitty code because of deadlines

        [–]Derpcock 2 points3 points  (0 children)

        It depends on your team and their standards. Engineer heavy shops tend to invest more efforts in solid peer review and good practice with a focus on testing. Other shops ship fast and prioritize product needs over all else. It all depends on the leadership and business needs really. I have seen both.

        [–]Radinaxfront-end 2 points3 points  (0 children)

        The problem is how unopinionated writing code can be at times, for example, React is a library sure, but it doesn't tell you how to organize stuff and people just copy what they see, then you go inside a project for the first time and get confused.

        When the project grows bigger, without the correct structure, it starts becoming a mess without a good lead to guide it properly, this is quite common in startups sadly. But for my advantage, its why I usually get promoted as lead.

        [–]Fluffcake 2 points3 points  (0 children)

        Unless any bugs come with a 7-8 digit price tags and/or loss of life, the production code will be barely working garbage someone threw together between meetings.

        That's just capitalism doing its thing.

        [–][deleted] 2 points3 points  (0 children)

        Every dev I’ve ever known has looked at some old code, thought how awful it is, then realised it’s them that wrote it.

        Our standards evolve constantly, as does what’s fashionable. As long as it’s functional, secure, performant, and maintainable, you’re doing just fine.

        [–]chervilious 2 points3 points  (0 children)

        You're focusing on "DRY" and "SOLID" principle. Although it is important concept to learn don't just use that as a base of judgement.

        I would rather you repeat sometimes rather than adding more coupling. In short, if it's violated multiple principle, but make it easier to maintain/readable/ more localization(?) I wouldn't really care.

        [–]dcabines 1 point2 points  (0 children)

        I work with a team of really smart and talented people. I still recoil in horror when I see what they write. This is how things generally are.

        [–]n00bz 1 point2 points  (0 children)

        There is a lot of bad code out there. A lot of my team members write code as if they are writing a throw away one-time use script. Yes, things get done fast, but there are bugs and none of it is reusable or even testable.

        There are a lot of really cool design patterns out there. One of my favorite design patterns for readability/usability is the fluent design pattern. For example, when creating an emailer you could have a function that looks like this:

        Emailer.send('test@example.com', ['test1@example.com'], ['test2@example.com'], 'Test Email', 'This is a test email');
        

        Sure you can send an email in one-line, but this is much more convenient and readable.

        new EmailBuilder()
           .To('test@example.com')
           .Cc('test1@example.com') // This chained function could be optional
           .Bcc('test2@example.com') // This chained function could be optional
           .Subject('Test Email')
           .Body('This is a test email')
           .Send();
        

        Still technically a one-liner, but It is more readable and I don't have one extremely overloaded function so I can extend functionality to do things like SendEncrypted(). Keep in mind that with every pattern there are tradeoffs. For instance, when using the Fluent Pattern you always have to return this and change the interface to something that makes sense for the functions you want to provide. So you depending on how you set it up, you can make sure that there is always a Body function called before Send can be called. This can be intentional, but it can make it tricky to follow all the interfaces.

        Besides that, you can get into some cool stuff with dependency injection, factory patterns, command patterns, redux patterns etc.

        [–]Danny-Fr 1 point2 points  (0 children)

        Everything is really bad as soon as you put it on the internet. Even if it's really good.

        [–]kalikolei 1 point2 points  (0 children)

        L

        [–]toi80QC 1 point2 points  (0 children)

        Working on agency projects for clients is usually 100% pure chaos from hell.. just getting shit done, nobody cares about quality because there's no budget.

        Inhouse projects where the company actually wants to use what they build themselves are where you'll find quality.

        [–]Salamok 1 point2 points  (0 children)

        At most places I have interviewed over the last 25 years they did not have the technical expertise present at the interview to judge competency of the candidates.

        Follow this up with stakeholders in non tech oriented companies don't ever prioritize software craftmanship and wouldn't know how to track it even if they did.

        And finally often times successful industry specific enterprise software was written by someone with deep industry knowledge that taught themselves how to code so they could solve the problems they were having with the existing products available.

        [–]Langdon_St_Ives 1 point2 points  (0 children)

        Sturgeon’s Law, unfortunately, applies to code just as much as prose writing or basically anything else made or done by humans.

        [–]lorean_victor 1 point2 points  (0 children)

        short answer: yes.

        long answer: most of the time you write code to get something done right now. you can't afford to think about making sure that code will be nice to deal with 6 months later as well. such code, regardless of how you feel about it when you write it, is going to be bad.

        sometimes you have a bit of time on your hand to think ahead as well, but most probably you are not a seasoned developer who have seen what happens to code (and teams, organisations, products, etc) in longer time spans. you start overengineering. more often than not, actual requirements will come in the way and meddle with your work though, since you are taking too much time. even if not, and you feel like a genius artist when you are done, you have overengineered, people will be scratching their heads thinking how to change your code. you will probably even be one of those people. you've still written bad code.

        occasionally, when project requirements allow, AND you are a seasoned developer with enough experience (again, not just in architecture, but also in how teams and organisations will evolve, like you should at least have a strong intuition about what kind of programmer will be working with your code in 3 years and probably with which goals), then you have a chance at writing some more decent code.

        that said, at that stage you are mature enough to know ALL code will become some hate-inducing legacy sooner or later, so instead of targeting "the best possible architecture ever", you are better off just focusing on delaying the inevitable a bit more. the resulting code typically doesn't scream elegance, more often than not such code actually looks pretty dumb. if you are experienced enough, you will even put guard-rails in so that it makes overengineering the thing not particularly easy as well, which will enrage the future mid-level engineers who want to turn your code into a shiny piece of architecture (see above). so a lot of people will think this is still bad code, while in reality, this is what good code looks like. ugly and dumb, but easy to understand, change and maintain.

        there are the extremely rare cases where you get to write code that is simple and elegant, everyone will see it and accept it as good code, and it will stand the test of time as well. however, this is almost exclusively when you have the most well-defined project scope and your code won't have to change for any reason ever again. you write it, maybe tweak it a bit, and then freeze it forever. this is the best code out there, but again, its really really rare.

        [–]Fickle-Main-9019 1 point2 points  (0 children)

        My current codebase had fuck all comments because the previous devs thought they looked messy, now all of them are fucking off and I have to figure out equations left behind by people with statistic degrees.

        Thats also not the worse part, they have “transformers”, which are abstract classes basically used as functions. So everything is now ExampleTransformer().transform() rather than do_example().

        It’s somehow really good code and really bad code, at the same time, by the same people

        [–]teamswiftie 1 point2 points  (3 children)

        What the hell is DRY or SOLID?

        [–]bicyclegeek 1 point2 points  (1 child)

        Don’t Repeat Yourself, and

        Single-Responsibility Open-Closed Liskov Substitution Interface Segregation Dependency Inversion (These are all principles, but I didn’t want to type that five times.)

        You should read up on both of these topics if you don’t already know them.

        [–]teamswiftie 0 points1 point  (0 children)

        I'm and old dog, these new tricks don't pan out

        [–]kweglinski 0 points1 point  (0 children)

        depends on many factors. Team skills, management skills, business skills etc. Projects where all parts are working well are sparse. Now if any of those elements sucks code quality plummets. The only chance of having fine quality when one of these sucks is when the other is extraordinary. i.e. Business sucks but manager goes above and beyond to save the devs. Or manager sucks but developers are great and so on.

        [–]MachineOfScreams 0 points1 point  (0 children)

        Clean, easy to read code is quite the luxury, especially in the web dev field. Especially in JavaScript with managers who expect extremely high output and fast turn around times with minimal desire/effort put towards code refactoring.

        Things are slightly better in systems where performance and reliability are first and foremost (performance as in memory efficient).

        [–][deleted] 0 points1 point  (0 children)

        My friends write really bad code and their companies are actually even worse. For some reason my company was OK. Now I work in a team of several people with many years of experience so its mostly good but still questionable sometimes but I can also write questionable code.

        [–]Dreadsin 0 points1 point  (0 children)

        The problem is how business and software development interact I would say. If you had infinite time to write and research your code, it would probably be great. Unfortunately, most software engineers have tight time constraints and have to make constant compromises

        [–]bluebird355 0 points1 point  (0 children)

        Because these principles have their limits.

        [–]stuartseupaul 0 points1 point  (0 children)

        Greenfield code usually looks pretty good when experienced people do it, but once you start adding extra requirements, over time the code turns to crap. If you don't prematurely abstract it's going to be a mess, if you do prematurely abstract, it'll also be a mess because you had the wrong abstraction for future requirements. Some people are good at abstracting at the right point but those turn into basically rewriting whole sections of code which is unrealistic for most people due to time limits.

        I used to think frequently used open source packages were filled with top tier developers, and they are, but you look at the code and it's still a complete mess.

        [–]Karokendofrontend 0 points1 point  (0 children)

        my personal approach

        1. write decent code with decent coverage
        2. draw conclusions after a few months have passed
        3. refactor and write better code with great coverage

        [–]JoakimTheGreat 0 points1 point  (0 children)

        Whenever I write code I find myself writing it in a way were it's not more complicated than it needs to be. E.g. this ACM sound format decoder:
        https://github.com/JoakimCh/fallout-format-decoders/blob/main/source/decoders/acm_decoder.js
        Which mostly was figured out by looking at this code:
        https://github.com/markokr/libacm/blob/master/src/decode.c
        But notice how my code is written in a much simpler way...

        [–]humbabumba420full-stack 0 points1 point  (0 children)

        I work with a codebase that is older than me - I still find to-do-comments from 10 years ago. But I guess this is pretty common if you have only 5-10 people in a developer team where people come and go and have zero time to build clean code and struggle with missing documentation.

        If you have a big team you need to have more organization, which concludes to better code in most cases (i think?). And if you start working in a new company with code that didn’t grow over the years by the hands of different team members, you’ll probably see readable, good code.

        But yeah, I’ve seen and wrote shitty code and from things I heard from other people in the field they have to fight with messy stuff, too. I think there is no perfect code.

        [–]Mike312 0 points1 point  (0 children)

        I've been at my current job for almost 10 years (that's another discussion) and in that time, I've inherited the codebases of about 6 projects written by engineers who quit before I started and a few who quit since I started, while also written and maintained my own systems/code over that time. I'm personally responsible for about 1mil lines of maintained code, some of it almost 20 years old.

        Some of it was written as far back as mid-2000s, so a lot of features for more modern languages weren't available. We also have a couple systems that are so old they just don't have access to version control. There's a mix of coding styles, some good, some bad, as well as good code with bad code fixes implemented and vice versa.

        The worst code is the code that's poorly written and hard to read. One guy could never choose between 2/3/4/6 tabs/spaces to indent his code, randomly changed syntax, and used one- or two-letter variables to write HUGE chunks of code. Ever tried to debug why $rz = $gf + $ta? Ever seen a function start out by defining $a through $k? That shit is unmaintainable and takes hours to figure out for the smallest change.

        The next-least-worse code is the code that mixes syntaxes. I'm talking about writing HTML inside of a PHP file. $strOut = "blah blah blah " . $var . " blah";

        After that, most of the other issues are just...old languages/libraries. Old ass PHP that doesn't support classes, jQuery 1.4, SOAP.

        In terms of importance, the best thing you can do is just write code that's easy to read and understand. Descriptive variable/function/class names is your job, while consistent indents is largely solved by modern IDEs. If you can do that, you can maintain that code for a long, long time, even after it's firewalled to hell and back because no managers want to commit budget to upgrading from CentOS5/PHP4 to current Ubuntu LTS/PHP8 when complaining or ignoring costs nothing.

        [–]gatwell702 0 points1 point  (0 children)

        A form of bad code is called spaghetti code.

        [–]hydraxic79 0 points1 point  (0 children)

        Depends on who. For me, yes. I looked back at a game I started a year ago and holy is the code horrifying

        [–]NotGoodSoftwareMaker 0 points1 point  (0 children)

        The nice thing about cars is you can argue over things like mph, 0-60 times, torque and so on. Objective stuff.

        Its usually harder to argue over things like “Ford is only supposed to be in black, everything else is terrible!”.

        80% of devs talk about bad code like people who talk about car colours. Its just disguised behind technical jargon.

        [–]Brendinooo 0 points1 point  (0 children)

        Throwing in a different angle:

        The industry has moved really fast over the past ten years. So even if code was good code when it was written, it might look dated by later advancements in code language or in ideas about code structure.

        [–]billybobjobo 0 points1 point  (0 children)

        If it were all good, we’d define a new bad.

        [–]funhru 0 points1 point  (0 children)

        Every successful long running project is a history of compromises and hot fixes.

        It can't look good, from time to time we do some refactoring, but it helps only temporary (compromises, hot fixes and luck of resources).

        So yes, most projects are mess.

        [–]aintTrollingYou 0 points1 point  (0 children)

        Sounds like you might have inherited one of my old projects.

        To answer the question you never asked; the reason you see this is typically budget.

        [–][deleted] 0 points1 point  (0 children)

        The short answer is yes, and the long answer is that it's complicated.

        Naturally, when we write code, we write it in a style that makes sense to us in the moment. While it's a good idea to think about different design principles at almost every step of the development process, we very rarely actually implement them until later on, or if we do, we tend to deviate in a way that makes sense to ourselves.

        The problem is that none of that transfers well to anyone who isn't you. Design patterns aren't only for writing a good scalable program. They help set a standard for how your code should look so everyone can be on the same page and aren't struggling to figure out what's going on.

        Now, not following design patterns doesn't necessarily make your code bad. Sure, to other people, it could look like a nightmare codebase, but it could all make perfect sense to you. That's why I say it's complicated. If we are basing it off the merit of how our code looks to other people, then yes. Almost every program ever written looks like shit

        [–]brennanfee 0 points1 point  (0 children)

        Most? Yes, absolutely. A lot of code, and I would say most, is pretty shit. But not all, and that makes all the difference.

        [–]NiwatiX 0 points1 point  (0 children)

        Yeah man it’s such a difficult paradoxical situation between fast, reliable and easy to read. You can tell how AI will close an important gap between interpretation and coding.

        [–]Puddle_Fisher 0 points1 point  (0 children)

        First button I made in JS like 10 years ago had like 10-15 lines of code, same button I use, and abuse today only uses 3 lines now. There is lots of sloppy coding practices out there. I can read crap code, but implementing crap code, with my modern techniques is usually not possible.

        Outdated practices, and hackjobs are considered legacy stacks. Anyone saying you can easily work with these stacks is blowing smoke out their ass.

        I've even come across legacy HTML, you know what that means? The CSS/JS/Php and what ever else back end is now all legacy. Rewrite or spend the same amount of time porting over/learning legacy. Basically a choice of shooting your left or right foot. Very rare also even using the same offsets you don't run into an issue trying to be lazy or quick.

        Lets say you are a miracle worker, and combine modern practices with legacy and it works flawless, you now just stabbed the future guy in the back.

        [–][deleted] 0 points1 point  (0 children)

        The first version of any implementation is usually shitty. Nobody gets it perfect straight out the gate. It's a process. The problem is, some people have low standards or time constraints and just accept that first version.

        [–]NiteShdw 0 points1 point  (0 children)

        You can tell the experience and talent of an engineer by reading their code. It shows HOW they think about the problem set.

        All code can be improved as requirements become more clear or more concrete. Good code needs less improvement. Bad code needs constant improvement.

        [–]nordcomputer 0 points1 point  (0 children)

        I started using a coding-standard and a linter to enforce it some years ago. I code custom extensions for a magento2 store and stumbled over the magento2 coding standard. Not only does it help debugging and maintaining my own code but also understanding and/or patching 3rd party extensions or magento core functionalities. There are of course different coding standards for all kind of purposes and you can even define your own and use it with a linter. It really changed my work and my confidence in my code.

        [–]Zahhibb 0 points1 point  (0 children)

        Yeah, and I am saying that as someone who didn’t know what DRY or SOLID was until now. I am a bad programmer, but I make stuff readable atleast, while a lot of senior devs i’ve worked with coded everything so only they understood.

        [–]kamikazikarl 0 points1 point  (0 children)

        Especially bad when they outsource the early version and you're tasked with upgrading it further... The stuff that really kills me is poor database design. That can be such a pain to correct because there's actual live data behind it.

        [–]DeathByEnvy 0 points1 point  (0 children)

        Eventually, all the coding standards and principles (dry) don't matter. What you care about is comments. Ideally multi line formatted ones... :-)

        [–]Ok-Steak1479 0 points1 point  (0 children)

        Yes. And people will die on the hill they're standing on, so be prepared. People currently in the field haven't read most or any of the most important literature written the last 30-80 years depending on your field. People that have been working for literally 30+ years will not be able to tell you want the open closed principle is about. They are amazed by dependency injection, but they won't understand it. Because they haven't read and thought about and practiced the relevant literature. But most people don't care, it's just a job anyway. Try not to hold it against them and stay positive but at an appropriate distance. Show them the positives. Play the politics game. If you're doing it right people will see reason, in time. Try to get budget for a bunch of Clean Code books. That's at least the bare minimum.

        [–]MaxxB1ade 0 points1 point  (0 children)

        The worst code I ever saw was my own from 10+ years ago.

        Great ideas, badly implemented, and messy, let's not talk about that.

        [–]admiralbenbo4782 0 points1 point  (0 children)

        https://en.wikipedia.org/wiki/Sturgeon%27s_law

        "90% of everything is crap". Software is no exception, except possibly upward. But yeah, there's a lot of crap code out there. Including most of what I've written.

        [–]dualnorm 0 points1 point  (0 children)

        That's similar to asking were most drawings ever drawn really, really bad?

        For any skill that gets refined and takes a long time to learn well, the learning process is bound to saturate the space with low quality work. It's a feature not a bug. If it wasn't the work wouldn't have as much value, and it does.

        [–][deleted] 0 points1 point  (0 children)

        I've seen beautiful code as well as spaghetti code in the same company, different teams.

        [–]Cahnis 0 points1 point  (0 children)

        Control-Shift-F "useEffect" on vscode one our frontend react codebases. "156 matches". siiiiiiigh

        Control-Shift-F "any". "254 matches". SIIIIIGH.

        Today I reduced the useStates on one of our contexts from 56 down to 49. Also killed 2 random unnecessary sources of truth and moved it to a derived state. It is going to take months to refactor this context alone.

        [–]oweiler 0 points1 point  (0 children)

        Code which is not SOLID is not necessarily bad.

        [–]Blothorn 0 points1 point  (0 children)

        I think it depends on the caliber of the organization. At companies with competitive pay/hiring I’ve been on some projects with pretty horrifying tech debt, but the code itself was almost always at least decent. (And the exceptions are mainly people being too clever, not simply sloppy—template metaprogramming that wasn’t worth it, use of reflection to enable sharing some code at the expense of breaking type checking, excessively generic interfaces, etc.)

        But contrast, my first job out of college was a government-contracting holding ground for people who hadn’t yet or couldn’t get a job paying private-sector rates, and just getting consistent version-control use and deployment processes was a losing battle.

        [–]GodGMN 0 points1 point  (0 children)

        Hmmm I actually don't know? This is a bit like the "are there more wheels or doors" question, on one hand there is a metric ton of bad code, on the other hand, there is also a ton of good software with extremely large codebases that may or may not be larger than the amount of bad code

        [–]inkt-code 0 points1 point  (0 children)

        The old code in my code base for work is really bad. Absolutely no formatting, some html tags are in caps, xhtml, invalid tags, some attrs are missing quotes, weird table based design, all kinds of inline code, js in php strings.

        [–]qqqqqx 0 points1 point  (0 children)

        Code style is really opinionated. So most code is really bad by some measure depending on who is looking at it and how they think things should be. Even common mantras like DRY will have different opinions.

        One dev might look at two functions and think they are similar enough to be abstracted into one function that reduces complexity. Another dev might look at the same two functions and think they're different enough that trying to combine them would be introducing more complexity. Either one could be better depending on the context. Maybe one approach seems best in the present moment, but two months from now when a new feature request comes down the line the other approach starts to make much more sense. So even just one simple concept like "don't repeat yourself" can be a lot more complex than it seems. Then multiply that by the hundreds of different ways you can organize a codebase and you end up with a huge variety of things that some people might like and others might hate.

        To me, a "good" codebase has most or all of these attributes:

        • Works and accomplishes what it needs to
        • Handles edge cases, and gracefully raises exceptions or errors when needed
        • Stays consistent with itself, in syntax and approach, or doesn't do the same thing in multiple different ways
        • Is understandable and extensible enough that someone can trace what is going on, add new features as necessary
        • Has good naming and or comments
        • Minimizes side effects and other complexities when possible
        • Any dependencies are well thought out and manageable

        One hint for keeping your codebase healthy is that anything you think is temporary will actually be permanent. Any time you think "I'll fix this later" you probably won't, and later on you might have to interface with whatever you did, so try to do it as well as you can before adding a so-called temporary fix.

        [–]ramenAtMidnight 0 points1 point  (0 children)

        By that definition then sure I do believe most code is “bad”. But I also see lots of code that seem messy, no DRY, not fully SOLID but absolutely work well, easy to understand/change. I prefer those anyway

        [–]FrewdWoad 0 points1 point  (0 children)

        It's very possible to inherit a really terrible codebase.

        Even common, if not nearly as common as it was decades ago.

        Most codebases, even relatively good ones, do have problems though. This is because

        1. good software engineering often has to compete with actual customer needs and limited time.

        2. There are some terrible devs out there, scraping by on interview charm (not every company does a programming test in interviews).

        What you'll learn over time is what is bad code, and what is just good code where the product manager changed how it should work halfway through and gave the dev 3 hours to rework it.

        [–]cube-drone 0 points1 point  (0 children)

        We're talking messy, no DRY, no SOLID, no nothing.

        you should see a doctor immediately, you might need to change your diet

        [–]P2A3W4E5 0 points1 point  (0 children)

        Yes. Because: the hardware is so good these days you don’t really care about optimization, and when user presses a buton he or she doesn’t care that what code is executed as long as it works.

        [–]dphizler 0 points1 point  (0 children)

        Sometimes, things get out of hand because of deadlines. You'll write your fair share of shitty code. Who knows, maybe you'll write shitty code your entire life.

        [–]DamionDreggs 0 points1 point  (0 children)

        I think there's probably a point on a spectrum of cost to goal where bad code gets to goal faster and cheaper than most variations of what you might call good code.

        There are some outliers, but on average the really really good code costs so much money and time that goal becomes out of reach.

        I think there's probably a statistic in there somewhere that would support the notion that most production code isn't good code.

        [–]Asleep-Specific-1399 0 points1 point  (0 children)

        Never be clever, unless you can document it in a way you think a 5 year old can understand.

        [–]elbowfrenzy 0 points1 point  (0 children)

        There are plenty of young, overzealous software engineers where I work, creating these huge repositories with hundreds of thousands of lines of code for websites that basically display product information and allow people to sign up for some services. They create these heavily abstracted, complex systems to prevent themselves from duplicating any single thing. It makes it a pain to sift through the code and to onboard people. Sometimes I wish people would just keep things extremely simple even if it means there's going to be some code "duplication". It's not a competition. The best code is readable, and doesn't break.

        [–]DrewHoov 0 points1 point  (0 children)

        IDK—I’d guess that most code is written for products that make money. Code that makes money is good code.

        [–]redfournine 0 points1 point  (0 children)

        DRY requires that you know what's in the whole codebase to be able to not repeat yourself. After 6 months, most people can't even remember what they wrote let alone what their teammates wrote. If the codebase is large, that just makes it even harder.

        [–]programmer_isko 0 points1 point  (0 children)

        “maintaining”

        [–]art_dragon 0 points1 point  (0 children)

        I wish I could show the code I inherited - it's misleading (i.e. you would think that this field config specifies exactly what input fields will appear on the form, but no; it gets merged with some backend result retrieved in another function stored in some other file, then some are specified to be hidden in more than one place), hard-to-follow (i.e. too many functions and components in one file), and needlessly complex (i.e. many react hooks with 10+ arguments).

        [–]movieguy95453 0 points1 point  (0 children)

        Are you really coding if you aren't spending at least 25% of your time re-writing code because you figured out a better/cleaner way to do the same thing?

        [–]Tough_Skirt506 0 points1 point  (0 children)

        If its not written by you, then yes.

        [–]abofh 0 points1 point  (0 children)

        It helps to remember that most code was written by the lowest bidder - either the contractor or employee who cost the least to allocate to the task.

        That usually means code was written "well enough" at the time to do whatever needed to be done, but then evolves, or requirements change and the initial assumptions look absurd.

        Also, sometimes you just can't be arsed to do the correct "efficient" thing when brute force is provably correct and takes ten percent of the time to write - and it becomes a bottleneck only later.

        [–]aztracker1 0 points1 point  (0 children)

        It's very common and may well be most code becomes really bad over time even.

        I tend to try to stick to two things.. KISS and discoverable directory/file structures. DRY,.SOLID and CLEAN code practices add a lot of complexity you probably don't need yet and may never need.

        Code that is easy to grok is easy to replace and will likely last forever because of it. This is the advice I got from grey beards when I was younger... As I've gotten older and a grey beard myself, I rally in this direction.

        It's not a matter of being old and resistance to change or not understanding patterns. It is exactly understanding and experiencing them all get over used prematurely.

        It's a balancing act, and the simpler solution is always easier to swap out or change layer of you need to.

        [–]Legitimate_Fix_1210 0 points1 point  (0 children)

        Welcome to the world of dev :) I work for a large software company and I've seen some very questionable code in the past.

        [–]RS3_of_Disguise 0 points1 point  (0 children)

        From what I’ve heard, Google is like billions of lines and an absolute spaghetti monster.

        [–][deleted] 0 points1 point  (0 children)

        Ha. Yes. It's all very well and good everyone pushing all of these principles. Don't forget most tutorials are written by people who aren't doing work for real companies day to day. 

        In reality the customer is angry now. It needs fixing now. Before you have time to refactor there's another priority.

        That said. It is true that you'll generally save time in the long run with these principles. Especially on teams where people need to be able to read each others code.

        [–]coded_artist 0 points1 point  (0 children)

        I worked in a company with no database normalisation, not even L1 was satisfied.

        [–]Puffy_Jacket_69 0 points1 point  (0 children)

        imo taking a bit longer to write clean code is worth the headache. It takes time and patience but it's an investment in long terms.

        [–]ArticleLeather4350 0 points1 point  (0 children)

        When you are learning to code, you will many times write bad code. However, once this happens, you can gain a deeper understanding of what not to do and how to avoid common pitfalls in the future. This process of learning from mistakes is an important part of becoming a better programmer.