15 ms·
Attitudes That Lead to Maintainable Code
- spunker540 10y agoWhen I first started working after college I had a lot to learn. For some of the first bug fixes or small feature enhancements I had, I remember fixing it with a one line change, and consequently being so frustrated with the senior code reviewer who would recommend I do some major refactoring instead. I now see that it's not about doing things minimally, but doing things as correctly and clearly as possible. And one should never be afraid to refactor! (Obviously there are cases where single line changes are the correct solution; but back then my mindset was "how can I do this with as little change as possible" and it should have been "as clearly as possible")
- amelius 10y agoIt makes me wonder why programming languages (and/or their development environments) are not designed for refactoring. Refactoring should be as simple as possible.
- caseymarquis 10y agoIn what way are they not designed as such? The biggest issue I can think of regarding major refactoring is coordinating across the team and ensuring you're collectively at a good point to start changing things. That's not really a language/tooling issue.
- fstephany 10y agoFor everyday operations and refactoring, I find the tools to be the limiting factor. I've just finished a contract where we had to deal with legacy code on iOS and Android (yes, it exists. Let two junior programmers not very keen to learn from the outside during 5 years working on the app and see with what you end up). Refactoring the Android code to a healthy state was greatly facilitated by Android Studio and the whole IntelliJ suite. We were not afraid to move things around and could always see the light at the end of the tunnel. On the other side, XCode has been a pain in the ass for the whole project. We had ObjC and Swift coode. Good luck with that. Even the pure Swift was hard to refactor. SourceKit is great and should help to get a top notch IDE that can resonate about source code but somehow Apple does not seem to care about the tools. Sorry, I get passionate when talking about refactoring and tools. Another example is how the Pharo Project (http://pharo.org/ http://pharo.org/) is refactoring the Squeak source (http://squeak.org/ http://squeak.org/) code/architecture. They developed custom tools for this purpose and their code cleaning is quite impressive when you know where they are coming from.
- js8 10y agoActually, I believe refactoring should be done by computers. But people will hate it when we will have that capability.
- crdoconnor 10y agoCleaning up code requires way too much human judgment for that to be possible any time soon.
- js8 10y agoWell, I have this idea that, pretty much, smaller programs (in the sense of Kolmogorov complexity) are well-written and thus maintainable. More precise argument is as follows: You take a very simple functional language, like say, Haskell Core. Let's consider a large and representative enough (finite) set of programs in this language. We find the smallest possible (or very small) representation of this set. This will involve definition of some commonly used functions. Let's call all the functions that are in this representation "the basic library". Then, for a new program, we can try to find shortest possible (among those you're able to consider) representation, such that, using the functions from the basic library comes for free (so you don't count the size of functions in the basic library towards the total size of the new program). So if we can write a program that would be able to find smaller representation using definitions (functions) that we already generated in that representative set, I think it would essentially automatically refactor code to be more readable and maintainable.
- crdoconnor 10y agoThis might get you the shortest code but it wouldn't necessarily get you the cleanest code. There's often a trade off between coupling and terseness which requires (human) judgement in order to balance the competing concerns correctly. There's also the matter of using appropriate metaphors. I have a feeling that a "cleaner" optimized like this would get you a program full of the equivalent of perl one liners, assuming it's even possible.
- 10y ago
- hasbot 10y agoIntelliJ is designed for refactoring. I'm not sure how a programming language could be designed for refactoring. What would that look like?
- AstralStorm 10y agoSaid language would make contracts easy to write and first class citizens. It would help you formalize parts of the typically non-formal programming, allowing automated or semi-automated formal verification. The language would allow you to bypass accidental hard restrictions imposed by type system - essentially duck typed but only if formal requirements are met on the types. Hey, I've described Isabelle/HOL; another language that is pretty close but more typical looking is Pyret.
- pythonaut_16 10y agoI know easy refactoring is an explicit goal of the Elm programming language. http://elm-lang.org/ http://elm-lang.org/
- AstralStorm 10y agoSemantic versioning is nice but not fine grained enough, and does not help the programmer who is deriving the new version at all.
- Cthulhu_ 10y agoI prefer to split functional changes and refactorings in separate pull requests. First do a round of cleanup and refactoring, which is almost always necessary for any code older than what you wrote five minutes ago. Then in a separate PR, do the actual work. Mind you, this is also in part due to traceability; I want to be able to point to a PR and go 'this is where this functionality was changed', with all the details. That makes it easier for the reviewer too, easier to find and review the actual change if it's the only change in a PR than when it's hidden in the diff alongside a major refactoring. I've also seen another open source project that said "please, no refactoring PRs". I can see the value in that one too - code is never perfect, and you can continuously polish but it won't actually achieve much, besides causing a lot of churn in your codebase.
- jalfresi 10y agoI've seen this expressed as "make the change easy; then make the easy change"
- blowski 10y agoThe three rules that I most frequently quote: 1. Code to an interface, not an implementation. Think about the essence of the class, without which, it would be a different class. Then build an API for that essence, then implement the API. 2. Program into a language, not in a language. Work out first what you want to achieve, then figure the best way of achieving that in the language. 3. Tell, don't ask. Don't expect client systems to know how your system works. When the state of your domain has changed, tell other systems, don't wait for them to ask. The "Factorio" game is one of the best explanations of good programming I've ever come across. Build components that do one thing well, then build components that use those components, and keep growing the system in that way. When you want to keep the relationship between two components more flexible, push values from the first component onto a 'conveyor belt' and have the second component pick up values off that belt. Service oriented architecture in game form.
- untoreh 10y agothis is a very lenghty way of saying program top-down, not bottom-up, unless your are targeting the metal :)
- buserror 10y agoI don't agree fully to that (1). I used to do it, because it sounds like a great idea... However, the implementation of your use case is often too subtle to get the API right to start with, and you end up having to play around and 'adjust' your API. ie, maintaining it even tho it doesn't even exists yet! My method is now to implement a 'dirty' integration, without any care of structure or cleanliness, then when it's in place and working only then do I sit down and look at the API I would have liked to have, and implement this by mostly refactoring what is already working. With that method, you end up with something that is clean, and more importantly does exactly what is needed an no more. There is no bits 'that could be useful later' and are never implemented, or used, or tested, and the model fits the job.
- blowski 10y agoThere's definitely a difference between what I preach, and what I frequently do in practice. It really depends what I'm building, and how well-defined are the requirements.
- rkangel 10y ago> Comments should be reserved for the rare bits of code that are influenced by factors beyond the code itself (for example, a customer requirement or a bit of historical context) This statement may be true in language domains the author is used to, but is certainly not true across the full spectrum. Also - there are two sorts of comments: 'what' comments, and 'why' comments. 'What' comments tell you what the code is doing. A lot of the time, in a lot of languages, if you code clearly these are needed only rarely, if at all. They are telling you what the code is doing, mostly as a convenience - they can always be replaced by spending time reading the code to see what it's doing. There are a number of situations where they are useful though, mostly obviously in languages like C or even Assembly where code often cannot be made easily readable. The 'what' comments allow you to quickly parse code to build up understanding of what's going on. Good assembly has a very high comment to code ratio - you are mostly reading the comments rather than the code to grok it. Occasional 'what' comments on a bit of C pointer arithmetic allow you to understand the authors intention and check against that 'specification'. I agree that in more expressive languages, these sort of comments become rarer and rarer. 'Why' comments are irreplacable in every language, and are what the author seems to be referring to in the above quote. "I have chosen to do this like this here because...". Because otherwise X unforseen bug, because otherwise Y performance issue, because Z client requirement. However expressive your code, that extra context is never going to be communicated by the code itself.
- charles-salvia 10y agoI agree with the comment about assembly of course, but ironically I find myself spending more time writing comments when programming in high level languages like Python, rather than in C. The reason most of the time seems to be that many high level scripting languages (like Python) are dynamically typed languages. So things like function definitions contain no information (other than the variable name) that explains what the inputs/arguments might actually be. I often find myself having to write comments to make it clear what the parameters are supposed to be so someone reading the code instantly understands what needs to be passed to the function, whereas in a language like C or C++ that has static typing, the type would make it obvious.
- 10y ago
- grabcocque 10y agoThe most maintainable line of code is the one which you don't write. Remember the cardinal virtues: Laziness Impatience Hubris Back when I was a Java dev, judiciously following the SOLID principles was a vital part of keeping code maintainable. They're still as true today as they ever were. * a class should have only a single responsibility * software entities should be open for extension, but closed for modification * objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program. * many client-specific interfaces are better than one general-purpose interface. * depend upon abstractions, not concretions.
- FreezerburnV 10y agoCan you expand a little about how each of these parts of SOLID have influenced how you have written code? I feel like I've heard people say conflicting things to some degree on at least some of these (e.g.: single responsibility) and my own experience feels somewhat like following some of them to their natural conclusion can end up with code that is more complex and harder to maintain. Again, for example, the S seems to imply needing a larger number of classes that would have to be searched through to find a specific implementation or bug, and D feels like it would shove the code that actually does something down a layer and be harder to find. That could be my inexperience talking or just not knowing how to employ the ideas properly, though. I guess a decent amount of what I'm feeling comes from my current job, which breaks a decent number of those rules. (S, O, I at least, possibly D but I don't think so) But despite that, code generally seems to be pretty easy to read through, so I'm a bit conflicted.
- AstralStorm 10y agoI find SOLID to be less reliable than applying ages old principles of contract-oriented programming. S is matter of taste, you can define it to be "show the whole GUI" or "show a text label in given position". Depending upon abstractions directly is much less reliable than depending upon contract (which is usually not explicit in the abstraction) and preferably also verifying it as both preconditions and postconditions. The other letters are important, though software should be designed for easy modification instead of being closed to it. Otherwise you end up with abstraction forests and deprecated code. Many interfaces is typically a smell, as the developer now has to juggle multiple balls in his head. There is good medium ground out there - making the interface maximize usefulness while not sacrificing too much of Liskov substitution capability is key.
- js8 10y agoThere is one attitude that's missing from the list: Change jobs frequently, and avoid old legacy code. Then you will always write the new code and it will be, by definition, maintainable (of course, who in their right mind would intentionally write an unmaintainable code?).
- usrusr 10y agoSo that you will never see wether the code is actually maintainable or not? You have described a strategy to avoid having to deal with bad maintainability, not a strategy to avoid creating bad maintainability.
- barryhoodlum 10y agoThat's the joke!
- js8 10y agoQuite clearly, I was being sarcastic. In fact, on three different points: 1. I see "unmaintainable" as mostly a factor of time (or age of the codebase), of changing requirements and people working on the code. So giving advice on how to write the code to be maintainable isn't gonna help much. If people turnover quickly, they won't bother, if they turnover slower, they will do their best to keep it maintainable and yet fail. 2. People who follow (intentionally or not) the advice I gave only ever see maintainable code, so from their perspective, it leads to (having to deal with) maintainable code. 3. (= 1. + 2.) Sadly, the people who are the most displeased with the legacy code not being maintainable are the ones who tend to leave quickly (or write something on their own), paradoxically, compounding to the problem of the unmaintainable code in the first place! I don't think there is a good solution to the problem. Maintaining old code is hard work.
- usrusr 10y agoOk, I see it now, but the liberal conflation of "maintainable" and "code that is easy to work on" that is repeated in 2. still hurts my eyes: they don't see maintainable code, they see code that is easy to work on - not because it is maintainable, but because of its position in the code lifecycle. The confusion between these two is exactly your point, sure, but I don't know how to say it better, I think your wording is just too close to subscribing to it yourself. They think they see maintainable code. I know I do, while writing what I will later call a hopeless mess. (Written by someone who has been doing brownfield projects, often bordering on code archeology, at the same employer for far too many years)
- daxfohl 10y agoI'd argue that sometimes you do want to hack things. Sometimes you go way out of your way to avoid that one special case for that one odd requirement, abstracting things out several layers to present a unified framework that encompasses that one oddball. Then the next day you get another oddball thrown at you that completely dorks it up. After a while you don't even remember why you had all the layers. At the end of the day, coding explicitly to the special cases and calling them out as special cases may make for more intuitive code. (Also see "The Wrong Abstraction": https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstracti...)
- falcolas 10y agoFor every rule, there is an exception which helps to prove the rule. Yes, hacking is sometimes necessary and is frequently a more efficient use of your time in the short term, but it should always be asked: "will I understand this hack next year?" Tomorrow's oddball might not happen, after all.
- daxfohl 10y agoSure, I'm just in the process of untangling a huge unnecessary abstraction right now, so when I read the article, I couldn't help but comment.
- hasbot 10y agoThat's where I find a VCS really helpful. If I'm wondering about a particular oddball section of code, I can go back and look at the context in which it was introduced. This is very handy especially for code that was written by multiple people over time.
- bm1362 10y agoFor what it's worth, I agree with you. I think premature abstraction can cost a business a great deal. This article comes across as vapid - there is no silver bullet and it varies from org to org. I went from a big tech co where we had the resources to abstract and deliver ideal solutions, to an existential startup that is hacking features together to win contracts. My biggest frustration is new engineers joining and overcomplicating simple tasks by trying to create generic solutions to every single feature request we get. The worst is that this comes across as 'investment' to management but it hardly ever bears fruit and we're just slowing down delivery to massage the developer's anxieties about technical debt. The reality is that the product may not really need that feature, or the customer may never use it, or it's good-enough, etc. I think in this environment we should ship simple features, that are hacky, until we gather enough data about it's value and use.
- maxxxxx 10y agoBe consistent. Pick one style and use it everywhere. It's nice if you can predict how something will be implemented from previous experience. And don't be fancy.
- AstralStorm 10y agoStyle is overrated. Changing attitudes and requirements force different styles. It is not an accident of nature that generally the nicest languages to use are multi-paradigm, therefore allow multiple styles. Previous experience can be very misleading. It is safest to come at the code and design as a blank slate. Prediction (also known as educated guesses) is worse than actual understanding, especially deep understanding. Sometimes being fancy saves a lot of effort down the road. It is being fancy for its own sake or for purely imagined reasons that is dangerous.
- cousin_it 10y agoI think you can write any program using only advanced concepts from the problem domain, not advanced concepts from programming itself. For example, I'll happily implement a difficult numerical algorithm for inverting a matrix, but I won't write a monad framework in C++ for that. IMO there are almost no projects that call for programming cleverness (as opposed to problem domain cleverness). You can get very far with boring imperative code that any beginner can read, with powerful algorithms introduced only locally and documented clearly.
- verelo 10y agoThis is exactly the attitude I try get into every developers head! Please write maintainable code using common and broadly understood methods. There is no award for surprising me in how fancy your solution is, in fact the opposite.
- klibertp 10y ago> There is no award for surprising me in how fancy your solution is, in fact the opposite. While I can agree with "no award" part, I don't think "the opposite" should be true. How do you know you got surprised because the method was "fancy" instead of because your knowledge was lacking?
- verelo 10y agoWhile I do not go around trying to beat people with a stick when they make things I see as overly complex, I think it's good to have a conversation about it, sit down together to find the simpler solution [or accept the one that is already implemented] and hopefully reach alignment on the path forward. It's totally possible my knowledge is lacking, which is why the conversation is critical. If I just need to be educated on why something I saw as complex was the right decision, so be it, and I look forward / enjoy those opportunities. At the end of the day, I run the tech team and founded this company, while others might come and go, I need to feel ownership over the code, product and most importantly it's shortcomings. If I cannot own that openly, I cannot lead/direct others, and that is when technical teams really start to fall apart imo.
- edw519 10y agoNice post. Short, sweet, and presented to avoid endless debates over particulars. (I know, I have plenty of my own.) I especially like: I’ve found it’s often easier to keep a few broader ideas in mind. Funny, OP doesn't mention the broadest idea of all: ego. I've worked with hundreds of programmers and have sensed an inverse correlation between experience and openness to suggestions about maintainable code. I believe that the main reason is not that the more experienced developers are convinced that their methods are that much better (after all, there are often many acceptable ways), but that their ego won't let them "lose a debate". When I return peer reviewed code to a young developer with suggestions (and reasoning!) about how to make it more maintainable, I often get a big thank you. The same feedback often gets a debate from a more experienced developer. On the other hand, when someone gives me feedback and suggestions, my first reaction is to engage them and explain why they're wrong and I'm right. But as soon as I set my ego aside and think of the code instead of myself, I open myself up to learning. This is vital because what I don't know is always much, much more than what I do.
- js8 10y ago> The same feedback often gets a debate from a more experienced developer Maybe that's because they have the experience they are able to debate it! I think "maintainable" will always be debatable, because we are not using scientific methods to determine what is more maintainable. So we are all subjects to subtle biases like confirmation bias. It would be great if we could use scientific method to determine how to write more maintainable code, but you would need a good definition of "maintainable" first, and that's hard. Personally, I don't see much, if any, hard evidence that today's code (in 30 years to the future) will be more maintainable than the code written 30 years ago. I work on 30+ years old legacy codebase, which is often crazy complicated and effectively not-refactorable. But you can still fix bugs, you can add functionality. It's expensive to do, but not impossible. Would be the accumulated cost lower if people spent more time refactoring it, like today sometimes happens? Not clear at all.
- JamesSwift 10y agoWhile I agree ego and human nature can be hard to suppress, I disagree that this is the driving force here. It seems to me that having more experience necessarily means you are going to have a clearer sense of the 'right way' to do a certain task, and more concrete convictions as to why that is the 'right way'.
- coldcode 10y agoI've always had the attitude that its easy to not put bugs in in the first place than to have to find and fix them later. Whatever you do that makes the code simpler and clearer up front, which might take longer, is always saved in the end when there are fewer things to fix. I started thinking this way 30 years ago and it's always done me well since.
- partycoder 10y agoSome positive sounding concepts that are used to wreck code and software engineering at a large: - "Get it done attitude": Declare something as done while it's still a prototype. - "Fail early": start with prototypes, end with prototypes. ship a prototype to production. - "Knowing the software business": know how to trick non-technical people into buying overpriced prototypes made of spaghetti. - "Product driven", "Feature driven", "Customer driven": implement only what can be sold (features), disregard everything else. e.g: security, scalability, etc. It is becoming a business model to sell prototypes as finished products.
- sidlls 10y agoI'm experiencing this in my current job, and it's a bit demoralizing. It seems "agile" has been internalized to some extent to mean "start writing code on day 1 or else we're basically doing waterfall which sucks," too.
- partycoder 10y agoAgile is often cherry-picked and reduced to only the parts that people like. Burn-down charts are ubiquitous but sprint retrospectives are not. Then some other parts are conveniently misinterpreted. People misunderstand the role of the scrum master and interpret it as the development team leader... confuse points with hours, or try to measure team performance using velocity... which is the same as measuring a truck driver performance by how much gas they're using rather than concrete results. Everyone claims to be doing scrum correctly, just like everyone claims to be doing git-flow correctly. It's not only cool to be agile and use scrum, it's more like a dogmatic cult where scrum is the ultimate truth that solves every problem in every case and cannot be criticized.
- mrweasel 10y agoI really agree with the "Avoid special cases", or the Zen of Python version: "Special cases aren't special enough to break the rules." For large systems it's absolutely critical to be careful around special case, at best avoid them. The hard part of dealing with special cases is to explain to business people that their "It's just ONE special case, how bad can it be" will snowball if allowed.
- yxhuvud 10y agoHow about attitudes that lead to performance code? That page doesn't load properly.
- greenhatman 10y agoIt loaded very fast for me, and I have crappy internet.
- codr4life 10y agoWhat I'm reading is mostly management directives for getting a bunch of code monkeys to produce code in the safest, most generic and repeatable way possible; by enforcing the lowest common denominator. Given a sound team culture, not using the full power of tools and limiting output to dumbed down templates are anti-patterns; it's not like the job isn't difficult enough the way it is.
- hashkb 10y agoAnother tautology filled article about how to write good code you just need to write good code.
- coldtea 10y agoThe article breaks down some things that you need to do to write good code. Proper naming, write self-documenting code, no fancy stuff, have the correct indentation and other formatting, avoid special cases, etc. Which is more than we can say for this dismissal.
- MichaelMoser123 10y agoAvoid special cases. Thats a good idea, unfortunately it's not quite possible if you have to adjust code to changing requirements over a long time...
- AstralStorm 10y agoIt should be rephrased as: design so that many cases can be handled, thus reducing number of special cases. They cannot be avoided, but their impact can be reduced. If you end up drowning in them, it means the design is broken and needs to be rethought.
- golergka 10y agoIt seems down. Google cache link: https://webcache.googleusercontent.com/search?q=cache:sGxWmxEUEfwJ:https://spin.atomicobject.com/2017/03/07/attitudes-maintainable-code/+&cd=1&hl=en&ct=clnk&gl=il https://webcache.googleusercontent.com/search?q=cache:sGxWmx...
- lokeshmalik 10y agoFhdjfuffjfkxfjrhidudufuegehe
- quadcore 10y ago"Attitudes That Lead to Maintainable Code" Well that assumes the code is the problem and not the programmer. The code might be perfectly maintainable but the programmer lack skills to do just that. I've only seen very rarely really-hard-to-maintain code, and there were of two sorts: 1) over-engineered pseudo-senior object-oriented spaghetti plate -- generally resulting from methods that supposedly make the code more maintainable. 2) logically-wrong over logically-wrong spaghetti plate -- the kind of code that programmers hate to admit they do: simply logically-wrong code. On the other hand, I've seen plenty of beginners making critics about a code that is supposely hard-to-maintain whereas the problem was them because: 1) they don't know how to read and learn a code base. They typically start working on a projets and they don't read the codebase. They jump on a task. They actually never read the codebase, but only piece of it. 2) they think the code is "obfuscated" whereas it is, well, just not. The programmer is just a beginner that needs to learn how to read a boolen expression for example (typically: var ok = cond1 && !cond2 || cond3 -- omg the code is obfuscated!).
- yawz 10y agoWe write code to be read by humans, and not by computers.
- taeric 10y agoThe number one attitude that leads to maintainable code for me, is to not worry about problems I don't actually have. That is, solve the problem I am trying to solve. Do not go out of the way to solve other problems. They will have their time, or they were not important. Obviously, it took some time to get so that I could write code that wasn't a disaster on its own. I would argue I haven't gotten past that point, actually. Which is all the more reason that the less I touch to solve a problem, the better.
- a-priori 10y agoThere's a line to tread here: solving future problems isn't a good idea, as you say, but neither is closing off future options by being too specific about your current needs. You don't want to create extra problems for future you to solve.
- taeric 10y agoAgreed. This is what I was referring to with my code not being a problem on its own. Ideally, you don't write things that wall you off from future options. But, neither should you try to anticipate all things.
- pklausler 10y agoDisagree. You don't want to solve just the specific problem at hand in a way that will be hard/expensive/buggy to extend. And you don't want to implement the most general conceivable solution library, either. The best solutions are in the middle ground, viz. those that solve the immediate problem in a way that anticipates and facilitates the future as well.
- taeric 10y agoIf something puts itself in the way of the work I am doing already, then I will attempt to solve it. But, you have to exercise caution and prioritize. Otherwise, you'll just find yourself in the "Hal fixing a lightbulb"[1] cycle. [1] https://www.youtube.com/watch?v=RHpJFROEOmg https://www.youtube.com/watch?v=RHpJFROEOmg
- _pmf_ 10y agoSomehow, a lot of people seem to write maintainable code, but everybody always ends up having to maintain unmaintainable code. A strange thing, this.
- chousuke 10y agoI think this applies to more than just coding. Being a sysadmin, code that I write tends to be in the form of puppet manifests, and these things do apply. There's one more rule of thumb I use to determine how I should approach building systems. Basically, I think that shortcuts are not (usually) worth the trouble. What I mean by this is that usually the least-effort, fastest (or "obvious") solution to a particular problem is not worth the time saved, when compared to just spending the time figuring out how to do things "properly". There is a continuous cost-benefit analysis where you keep asking yourself whether you will save you enough time taking the shortcut that potentially having to re-do it later (or fix potential issues caused by it) will still end up less "expensive". When you do choose to take things slow, though, you usually end up having a better understanding of the problem as well as the solution, which naturally leads to a better result.
- weaksauce 10y agoI like the alternate quote from the article: There are only two hard things in computer science: cache invalidation, naming things, and off by one errors.
- mooneater 10y agoThe biggest factors to me: use appropriate, future proof (insofar as possible) reliable tools and frameworks. Favour popular established libraries over custom code. This can dramatically reduce surface area you need to maintain, and simplify the code that remains. Simple but often neglected.
- keithnz 10y agoIf we are talking attitudes, then what's really needed is to care about code you write. I don't think you want terribly many hard and fast rules, but a considered approach to everything. Cleverness is great when appropriate. Things shouldn't be used just because you want to use them, things get used because they enhance the engineering. I think the greatest danger is probably having too many rigid ideas about coding.
- randyrand 10y agoAnother big one. For Object oriented code. Composition over inheritance. It's hard to overstate how important this is. Many people know this but still don't do it enough. Don't make large classes that implement many features. Split those features/responsibilities into smaller classes and then have a class that calls to the smaller ones. A good way to think about this is your classes should have as few member variables as possible.
- collyw 10y agoThe documentation for the application I maintain is scattered with similar buzzwords. Unfortunately the database design is crap leading to way more code than is necessary. It also includes important information that has been pickled and stored in a field, so its a nightmare to debug. It's done in Django but he has used a "fat controllers thin models philosophy" - the opposite of Django best practices, so it doesn't take advantage of many of Django's features such as lazy loading and doesn't run quickly as a result.
- JCDenton2052 10y agoYAGNI. Not being an abstraction freak. Not implementing hundreds of features in the hope that they may be useful one day. I have been going through the code of a well-known document database... I am horrified to discover over 400 classes in their abstractions project, including some very clever stuff, which I then try to find examples of in the rest of the code, only to come up with nothing.
- galdosdi 10y agoThe HN comments on this are a lot more interesting than the article itself. Just a couple of platitudes we've all heard and repeated and lived by. "You can write more maintainable code if you think about making it easier to maintain!" OK, duh.