4 ms·
It feels like people are focusing on bad conditions and unreasonable deadlines, and not the idea that in the real world smart people under execellent conditions
by dahart 10y ago
It feels like people are focusing on bad conditions and unreasonable deadlines, and not the idea that in the real world smart people under execellent conditions do this very, very frequently.
I've worked for long periods of time in 3 codebases that were over 2 million loc in my career, all had great conditions, all had very smart people. Those are not huge codebases by any standard, and yet all 3 had people talking about ground up rewrites. All 3 had people complaining about every single example the author used. Two of them undertook the ground up rewrite estimating one year. Both admitted to having made a huge mistake 3-5 years later.
My theory is that all software eventually becomes difficult to maintain and full of warts, regardless of smartness, regardless of conditions. We all have code ideals we believe and talk about that don't work as well in the real world as we imagined. We all have deadlines that are shorter than we want -- it's a universal constant. We all imagine we can write code and fix big problems faster than we really can. And we all fail to fully understand what's working right in a messy large codebase and tend to focus on what's wrong.
I don't know how to fix this, but it's very possible the author ran into thoughtful paradigms he just hadn't seen before and didn't fully understand. Some styles seem messy if you haven't seen them before.
React is an intentional lack of separation of concerns between code and markup. Some projects are required to mix tabs and spaces depending on tools. For that matter, bash scripts alone require mixing tabs and spaces for some features. And so on, it's important to have context for why things are the way they are before jumping to the conclusion that it's bad.
- SatvikBeri 10y ago> My theory is that all software eventually becomes difficult to maintain and full of warts, regardless of smartness, regardless of conditions. I agree. I think there's a lot of emphasis on preventing bad code from existing. But if you believe some bad code is inevitable, then it's more important to make it easy to fix when it happens. By default, good code tends to be modular and easy to replace, while bad code is excessively coupled and hard to get rid of. So bad code has a disproportionate impact on long-lived codebases. I wonder if one way around this is to force modularity, even when it's unnatural. Functional programming seems to be one way of doing this, microservices are another. A related principle would be not to take DRY too seriously, favoring decoupling over deduplication.
- lloeki 10y ago> I agree. I think there's a lot of emphasis on preventing bad code from existing. But if you believe some bad code is inevitable, then it's more important to make it easy to fix when it happens. Indeed, what matters isn't writing bad code, but doing so in a way that affects the whole codebase (whether through coupling or by volume). Accepting that bad code happens helps a lot in locking it down behind containment measures, both in space and time. I can liberally accept bad code as long as it doesn't imply bad architecture, so that it's easily removable and understandable, but I'm hell bent on refusing any form that means we can't dig ourselves out of a hole we've dug ourselves into (this includes slowly drifting yourself into a hellhole by accretion, bad code must come with an expiration date, which means immediately creating an issue in your favourite bug tracker upon commit/merge). Decoupling is key, and duplication is often needed to see the true generalisation patterns emerge, not the ones you expect to be there sometime in the future[0]. [0]: noop-noop-noop maneuver (video+slides) http://www.thedotpost.com/2016/10/katrina-owen-the-scandalous-story-of-the-dreadful-code-written-by-the-best-of-us http://www.thedotpost.com/2016/10/katrina-owen-the-scandalou...
- SatvikBeri 10y agoThis is a great talk. I find that this pattern comes up over and over again: first add new code in a safe way that makes the codebase a bit messier without modifying anything, then move all functionality to the new code and neuter the old stuff, then delete the old stuff. Eg this style of pattern is how to do schema migrations safely.
- dahart 10y ago> I wonder if one way around this is to force modularity, even when it's unnatural. There's probably no denying this is a good idea. :) The most successful very large systems seem to be made of independent modules that each strive to do one thing well. They can also be more easily removed, refactored, or replaced, due to their small size, and perhaps most important you can do one at a time. > I think there's a lot of emphasis on preventing bad code from existing. But if you believe some bad code is inevitable, then it's more important to make it easy to fix when it happens. Yeah, it's true, emphasis at any given moment is on what list of things we want to see, and what list of things we don't want. The author even started with one. Problem is, code styles also change over time. What some people call reasonable or good code, other people call bad; "bad" is subjective. Hire a brilliant engineer to help make your decent application awesome, and her first reaction may be "oooh, this code is pretty bad. let's make some changes". I honestly wouldn't be able to count how many times I've seen the newest member of a project complain about the mess while nobody else seems to mind that much. (And I count myself in that list, I've done it too.)
- dualogy 10y ago> My theory is that all software eventually becomes difficult to maintain and full of warts, regardless of smartness, regardless of conditions. I've come to a similar (intermediate) conclusion for now. Would certainly fit the general pattern of "all things" in this physical universe. I think there's also a lot of subtle human psychology at play at all times in this subject. Identifying and ruminating over such "issues" implicitly elevates oneself (to peers, the community, the boss, the client, the family, to self, etc), materializes potential future employ ("this needs a total overhaul ---by me/us, according to this latest/proven/bla paradigm/methodology/platform --- or the project is doomed, I say, doomed"..), satisfies many a engineer's/programmer's inner yearning for learning to do better, inching a bit closer to perfection, lifting the whole field, etc.. our supreme tendency to fool ourselves (about ourselves and the power of one's mental and aux toolkit) on the daily that probably keeps us going so eagerly in this (frankly for mammals somewhat weird) "activity", it all comes together suspiciously neatly when one looks at others' codebases / current conditions with that "damning-professional's glance"! =)
- superrad 10y ago> My theory is that all software eventually becomes difficult to maintain and full of warts, regardless of smartness, regardless of conditions. If a code base doesn't change too much in side or original intent then architecture and design (if it was good in the first place and is continued to be followed) will probably keep it fairly maintainable. In a lot of cases though codebases slowly grow until they become of a size that requires a different architecture or approach to organising the code, especially if the number of collaborators increases too. It's quite a hard thing to spot and then address while that codebase is still quite active. Rewrites are tempting to be able to apply that architectural change but often you can be quite bound by the implementation specific behaviour of the original system. It might be interesting to look how the linux kernel has changed internally as it moved from a single person project to what it has become today.
- dahart 10y ago> often you can be quite bound by the implementation specific behaviour of the original system Yes, this. Requirements accumulate over time. That is what makes it harder to refactor production code to be cleaner. When you're not bound to your requirements, they can change, but when your requirements start to set in stone, you lose the freedom to change them. Choosing to rewrite already released code is likely to introduce regressions, is more difficult than with unreleased code because you are not allowed to change requirements, and redoes work work that was already done once. If management is paying attention, they will (and should) complain about paying for the engineering again. After all this, there are no guarantees it won't just happen again. Things don't tend to stay magically clean after rewriting. That's assuming the rewrite even finishes cleanly. What often happens is the engineers underestimate the time to rewrite because they didn't understand how well and how many things were working, and it gets cut short by management a third of the way through when the rewrite is obviously over budget. Now the codebase is messier than when it started, even though the engineers had the best of intentions and management gave them large swaths of time to try and fix things.
- BurningFrog 10y agoI've worked on teams that kept the code base clean for years. We did it by focusing hard on just that. Ruthless refactoring, zero bug tolerance, and no deadlines are maybe the biggest factors.
- dahart 10y agoThis is intriguing, and I'd love to hear more context about the team, code, management, and business/product. I really want it to be true and possible in general... I'm going to admit what conclusions I jumped to reading this. I'm admitting my bias, and that I might be wrong, not arguing with you or challenging your experience. My (biased possibly wrong) instinct is to wonder to what degree that was a real world situation. What I mean is that the only times I've had no deadlines and the ability to ruthlessly refactor are the times I've had no managers and no customers. I can see that being easy to pull off in school projects, and on research teams, and in free open source projects, but I have a hard time seeing (and haven't personally witnessed) how that works long term in a healthy functioning business that has revenue where the code is directly related to the product. There are stories of places where this stuff happens, but often you can find people who were there saying the stories are exaggerated or lacking the proper context. So anyway -- any context you want to share that might make it easier to be ruthless and keep code clean under less ideal conditions than yours? Thoughts about how to do it when there are deadlines, since most people (I speculate) do have deadlines?
- BurningFrog 10y agoThese projects were explicitly set up to be XP/Agile projects, and were staffed with people with that experience and expertise. The way the experts say you can turn your environment around to that, is by explaining and showing the advantages of a deadline free process. Your management will - not unreasonably - suspect you're just trying to work less hard. The way out of that is to build trust by constantly delivering quality software. If this sounds hard, it probably is. I've certainly never done it. The easier way is to join a team that already works this way :) It's also worth noting that constant refactoring towards a good design is a difficult skill that not everyone has! It takes a effort and experience to get good at it. For a group of random programmers, it may not be the best way to work.
- edoceo 10y agoWhere does bash require a space in place of a tab? I've got 1000s of lines of scripts that start with #!/bin/bash and 100% use tab to indent.
- dahart 10y agoIndented here-strings.
- edoceo 10y agoNope, those require tabs. See first result on Google for "bash indented here string" as well as bash guide.
- dahart 10y agoYes they do. You must indent the here-string with tabs and not spaces (which sucks for people who prefer spaces). If you want to indent within the here-string, bash requires spaces and not tabs. Mixed spaces and tabs are required to get both kinds of indentation at the same time. A very common use case for this would be help text / usage strings.
- smacktoward 10y agoAgreed, but I would phrase it slightly differently. Moltke the Elder (https://en.wikipedia.org/wiki/Helmuth_von_Moltke_the_Elder https://en.wikipedia.org/wiki/Helmuth_von_Moltke_the_Elder) wrote that to understand military strategy you have to understand two basic things: - No plan survives contact with the enemy - Strategy is a system of expedients In other words, you can make all the plans you want, but as soon as you put them into action they have to take into account the behavior of the enemy, which may or may not go as you predicted. And once events start departing from your predictions, gaps in your plan will appear that you will have to plug with whatever you have at hand, because once shots have been fired you can't un-declare war and start over with a new plan that incorporates what you've learned. You're hip-deep in the muck now, and have to struggle through to the other side as best you can. Something similar could be said about designing software. If no military plan survives contact with the enemy, no software architecture survives contact with actual users. The architecture of a particular piece of software is, at root, a hypothesis: given problem X, here is how one could go about applying a defined set of computing resources to solve it. And at the beginning those architectures are always clean, because they're being applied at a purely theoretical level where things we don't really understand about the problem aren't evident yet. And since it's all theoretical, there's no warts; re-drawing the architecture on the whiteboard doesn't inconvenience anyone, so we can do it boldly and often. But at some point you have to translate that beautiful architecture into working software and put it in front of real people, and that's where the problems start. Because those real people will use the software in ways that surface facets of the problem you didn't appreciate, forcing you to modify it to keep up. And because now making changes means inconveniencing real people and losing actual money instead of just scrubbing off a corner of a whiteboard, those changes will have to be conservative and expedient rather than bold and sweeping. And this is where the warts start creeping in, as you try to drag your original vision into some form that actually fits the real world as quickly and cheaply and non-disruptively as you can. If the architecture is the hypothesis, the software is the experiment. And you may think, after running the experiment once, that if you could just start over with a clean sheet of paper armed with what you know now, this time you'd "get it right". But of course the real world isn't static, so by the time you develop a new hypothesis and are ready to run the experiment again, you often find the ground has moved out from under you. Your hypotheses are chasing a moving target, and so the need to patch them up with duct tape and bailing wire never ends.
- mkalygin 10y agoI agree with you. I think the best we can do as software engineers working on legacy code bases is stop making assumptions about authors of the code and do not think that we are smarter and could do better. Legacy code is not just a text. It's a big amount decisions made for a reason. What we lack is a history of those changes. So if we see something we call "anti-pattern" or "code-smell" we need to think twice is it really the case or we are missing something. Inexperienced programmers tend to simplify things and swear at bad code. They think that they could design this code better and assume million of things about the code and its authors. I think it's unprofessional. We need to avoid making assumptions if we have no real evidence. Be cold-minded. Refactor and improve step by step. And don't rush to rewrite huge code bases from scratch: are we sure we won't end up with the same code mess and we are smarter than authors of legacy code?