Hacker News new | comments | show | ask | jobs | submit login
The code culture problem (fraustollc.com)
148 points by frausto 1560 days ago | hide | past | web | favorite | 155 comments



> the code is usually not particularly shit

I'm sorry, but yes, it usually is. I've been in this business for over 25 years, and I'm one of the few people that actually enjoys the challenge of dealing with legacy code.

But most of the code I've seen is shit. The answer to the question "could it have been done better" is usually "yes, if it had been done by someone who understood the basic principles of the paradigm they were developing in and the tools they were using to do it, and actually gave crap".

The difference between shit code written by shit coders and less than optimal code written by good coders dealing with constraints is quite clear.

I completely agree with the point the author is trying to make about the attitude problem, especially amongst coworkers, but let's not gloss over the fact that halfway decent code written by competent developers is still very, very rare.

Most code out there is shit code. Denying it is not going to help either.


>I've been in this business for over 25 years [...] The difference between shit code written by shit coders and less than optimal code written by good coders dealing with constraints is quite clear. [...] Most code out there is shit code. Denying it is not going to help either.

I'm sorry, I respect your experience but this post is completely uninformative. It's much more specific on how awesome you are than on how to distinguish between "shit code written by shit coders" and "less than optimal code written by good coders"; not to mention dealing with and improving either.

It's possible to spend a long time in an industry and accumulate much unfounded prejudice along with solid knowledge. As long as the appreciation of "shit code" and "shit coders" remains subjective, it's virtually certain you'll also be considered one someday, when the prevailing paradigms and fashions change again.


As a coder the best compliment I've ever gotten was from a consultant. It was basically something like, "Hey, you're the [my initials] that wrote a big chunk of [system]? I can really tell the parts you wrote from the rest, it's so much easier to follow and understand." I had written the original code for that project solo and then it was passed on to another team for maintenance. That, to me, is the best thing a fellow coder can say, that my code was easy for them to maintain.

Conversely, I've seen code written in Java where instead of using objects the original coders used hashmaps with key/value pairs for fields. Sometimes they used some public static strings or an enumeration for the keys but often times they're just randomly hard coded throughout the program with string literals for field keys.

In another system I've worked on the coders did not understand objects/collections at all. So rather than having an array of type Person you had the Persons object that looked like this:

Persons { String[] first_name; String[] last_name; String[] address; }

While it's true that good vs bad code is somewhat subjective... code like the examples I provided above is pretty horrible by the standards of all but the worst coders.


Persons { String[] first_name; String[] last_name; String[] address; }

Are you sure they didn't do it for performance? That is a well-known pattern for getting better data locality ("structure of arrays" vs. "array of structures").


I was thinking the same thing; in such a case a // coded this way for cache coherence goes a long way.


I think it's a bad case of "dislike due to knowledge".

It's stark in the arts, but it applies to almost every human endeavor. As an example in the arts, I dance, and I'm good at it according to almost everyone who sees me dance. But I see myself as a terrible dancer. If I make a video of me dancing, others see every part that's well executed. I'm accustomed to them, and I tend to ignore those parts in favor of every part that's sloppy, every part that just doesn't look right.

And it's no different for code. You know what one of the marks for good code is? If the guy writing it is tearing it apart in the comments. Where do you see /* This is a dirty hack I'm ashamed of */? Usually right next to stuff that's a stroke of genius, or at the very least really good code.

It's strange that the more you know about something, the less comfortable you get with your knowledge, but it seems almost universal that "Ignorance is bliss", or rather the corollary "The more you know, the less you think you know".


I do like code which has comments which describe the level of confidence the author has in some sections (I feel a happier refactoring code which is marked as being suboptimal).

But in my experience those comments are usually found above cases where it's possible to make a fix in one line rather than one hundred. (sleeping a thread for 0ms rather than re-architecting a gigantic callback structure).


If I can open a project and refactor some piece of code to be 1/10th of it's former size, while making it both more readable and more efficient without changing what it does than it's shit. In such cases I honestly don't care how good the original coder was supposed to be or what excuses he has. And yes, if I write code that can be optimized that way, I will be the first to admit that it's shit.


It's easier to refactor something that has already been created than to create that thing. This is why refactoring is such a good thing. It doesn't mean the original creation was "shit", it just means that it was massively improved by refactoring, which is sort of the point.


That's like saying, hey that rough draft of my essay is just fine to use. Not it's not, it's a rough draft, clean it up (refactor your code).


That's not a very good analogy, and doesn't really address the point I was making. Note that my comment was very favorable to refactoring.


It is amazing how many software developers think they are awesome. And then of course think everyone else is shit.

Unfortunately that pretty much means everyone is shit relative to someone else.

So its important to remember, you are shit too.


Let's admit that while there is code that could be cleaned up and made more efficient, which isn't "shit," there remains code that is riddled with antipatterns, latent bugs, is undocumented, untested and otherwise ostensibly terrible. This is what should fall under the "shit" category.


You're probably right, what do I know I've only been programming professionally for 3 years.

However, I find that it's more helpful to have a positive attitude when reading code I didn't write. "Why did he write it this weird way?" taught me so much more than "this is shit, let me rewrite it the way I'm familiar with".

I'm not denying that I found seriously bad code running in production. And I'm not denying that it's more common that I would've believed. But the moment I start treating every piece of foreign code as shit, I'll miss out on interesting insightful techniques.

The point of this article is a reminder that it's easy to get sucked in the "this is shit" culture.


"Why did he write it this weird way?" taught me so much more than "this is shit, let me rewrite it the way I'm familiar with". ---------------------

You're 3 years in. In another 3-5 years (maybe more), this 'positive attitude' will (and should) go away. You'll have a much better understanding of the 'weird' ways, and will be able to tell 'quick hacks' from 'crap code' as the OP was referring to.

You will have learned most of what you need to know by investigating the 'weird way', and you'll see the patterns, and you'll be at this for 15 years, and you'll be seeing the majority of stuff coming out being crap code by younger developers. It's the way of the world.


I'd much prefer to have GP on my team than you, frankly. I think companies are much more productive when they have people willing to learn from and teach one another rather than bringing negativity.


The last few years, I've primarily been working freelance going in to companies and dealing with crap cleanup left by people who were "positive" about their own abilities, gave a pass to everyone else on the team who could get something to run without too many obvious errors, then left.

So... you can call it negative, I call it realistic. I'm pleasantly surprised when I discover good, well-written code, and it means my estimates can be revised downward - something everyone enjoys. Hoping for the best and getting the worst is horrible - expecting "meh" and getting a positive shock is great, but doesn't happen all that often.

I'd have loved to be at a company where people learned from each other and taught one another - imo, it's extremely rare. I've seen it a couple times in the past 15 years, but more often than not, politics and/or ineptitude takes over, and the 'learning/teaching' thing goes out the window.

As a developer, I had a technical manager over me who'd never coded. I've had a colleague who was hired to 'fix bugs', and has to watch the people who wrote the bugs go rewrite everything in to a 'version 2', rewriting exactly the same problems, because "they've been here longer".

So... yeah, companies that foster teaching/learning environments might be nice, but it takes a LOT of work to get right.


"rather than bringing negativity"

That seems like a false dichotomy. Someone who's a pollyanna even about horrendous abominations is a problem in one way, someone who's indiscriminately contemptuous of reasonably useful code is a problem in another way. Software projects (or teams, or companies) can bog down or die in more than one way. Driving off people who are doing reasonably good work is one way, tolerating unreasonably low standards is another.

And also, correct criticism is not particularly "bringing" negativity. If there is something unacceptably technically bad, and you want to point to the person or people who brought the negativity, you'd do better to point to the original creators and/or the chain of people who have signed off on it since then, rather than pointing to the person who criticizes the problem. The irreverent child did not bring the negativity to the Emperor's famous tailoring fiasco.

Someone who reasonably reliably distinguishes between good and bad is useful. Making the distinction correctly is generally much more important than the style of expression. It's easy to hire pollyannas (or, indeed, to err in the opposite direction by hiring hard-driving abrasive jerks) who don't have the tech skills to make the distinction correctly and just fall back to emoting in their preferred style. It works better to hire the smaller fraction of people who can do a good job, and who can recognize a good job. When you do that, it doesn't solve all style-related abrasiveness problems, but it does help mitigate them. By the time you've worked with someone for a while you learn to translate A's "this is unacceptable" as synonymous with B's "this is flaming rancid goat barf". (And axiomatic though it seems to be to you, in my experience saying "flaming rancid goat barf" is not useful evidence of unwillingness to learn and teach.) Both A and B are useful as long as they're reasonably reliably correct. Much bigger problems are C who says "this is a good effort" about everything, and D who flips between praise and condemnation based on issues other than technical quality (randomness, politics, mood swings, whatever).


My dichotomy was between the parent and the grandparent.

I totally agree that not addressing issues and not bring (constructive!) criticism is a poor strategy. But your persons A and B have the same problem: they're critical without being providing any actual information. Person B just compounds it by also being a jerk.

As a programmer/businessperson, I'm not interested in making people feel good about poor quality work. I'm interested in people who want to improve themselves and the overall product, and ideally, enjoy the process. I just don't see how insulting code or people helps. I think it's perfectly possible to hold high standards on code and respectful conduct, and it's perfectly possible for people to rise to those standards, guided by constructive criticism.


I've been programming professionally for over 10 years, and when I see some weird code, I still try to figure out who wrote it and ask him before I change it. Often he admits it's shit and needs to be changed, or he just doesn't know anymore, but sometimes there was actually a very good reason for doing it like that.

Those few times make it worth to never judge too early.

Blindly assuming you know better is arrogant and will inevitably lead to problems. Discussing the underlying reasons will almost always teach you something.


Needed to add on to this - without knowing what good code is, you can't learn much from bad code, and likely won't be able to identify it.


Exactly, that "Why did he write it this weird way?" helps you understand the programmer who wrote it (his level of expertise) and gives the opportunity to analyse the tradeoffs he made. This helps discern between real shit and unpleasant code that had to be written/structured that way.


So what exactly is the point you are trying to make here other than that you are the smartest guy?

The article is not about the existence of shit code, the amout of shit code produced per year or how much shit code the average developer will see in his career.

It is about teamwork, and what kind of culture poisons the atmosphere in a company.

Not about shit code, which by the way everyone here has produced at some point or to be more realistic about it (since usually developers look at their old code and think it is bad) - is still producing on a daily basis.


The first step to solving a problem is admitting that there is one. I remember debugging some AJAX code once which was racing with itself. It took a lot of mental effort to work out what the existing code was meant to be doing and what it was actually doing, both of which were wrong. At it's core was a simple jQuery AJAX call with a success callback (no error callback, of course), but interleaved through it was a mess of global variables ("finished_yet", "time_last_checked", etc.), busy-loops, manual timeouts, state-rollback functions, etc. What I would call shit code.

Once I finally understood what it was doing enough to refactor it I managed to delete most of the file and replace it with a "latest_id" counter which incremented on each call, with the success handler skipping if its ID wasn't the latest. Simple.

I approached the developer responsible for the original, to show him what I'd done and explain how Javascript's scope let each call have its own ID. His response was that I'm using obscure language hacks which nobody is going to understand when they have to maintain it, that I should stop trying to force everything into a few lines and that he doesn't need to learn about Javascript's scope because he can already program so learning anything else is a waste of time that could be spent coding.

I got told a similar thing during a code review as well, since I'd used map on an array. Needless to say, I didn't stay there long.

Now that is a cultural problem, which can only be solved by pointing out shit code (although in a more polite way). Some people are so stuck in their ways that they don't care about improvement because they see their stuff as 'good enough'. In those cases, they need to be shown that no, it's not good enough, because XYZ.

I wasn't trying to gain points on anyone; I was just frustrated at the utter lack of care about the codebase we all had to work on. Whenever I spotted anything particularly WTF I'd send out a "Code of the day" email. My favourite is still this one:

    <td>
      blah blah blah
    </td style="....." id="foo" class="bar baz">


Yes. I understand the OP point about not fostering a culture of negativity - that makes a lot of sense. But I've never seen negativity take down a product, just make it a bit more unpleasant working environment. The culture of 'good enough' is far more damaging, in my experience.

FWIW: when I was fresh out of school my logic was sometimes pretty twisted, to put it kindly. Lots of deeply nested if statements, global variables used to maintain state (in the state machine sense) that sort of thing. That is unworkable, I recognized it, and I learned from my peers, from books, from good code, from myself (reality is a wonderful instructor. Work til midnight fighting a bad piece of code you wrote, well, you should learn something from that). That's not ego, that is learning your discipline.

This is all testable in the marketplace - not in products sold, but the marketplace inside your development lab. Are you the programmer with endless bugs, or the one that generates nearly bug free code. Are you a 10x programmer, or not? Are you the one that everyone asks questions of (to learn from you, or get your opinion on a design), or not? Do people seek you out for code reviews, or not? Do people need to come to you endlessly to try to figure out what your code is doing, or not? Does your code have a disproportionate number of bugs written against it? If there is a bug in your code, do the rest of your team members assign it to you because they can't begin to understand your code? And so on. There's no ego in any of that, but it is all reality(what I called the marketplace) telling you the quality of your code, in the measurable form of understand-ability, maintainability, bugginess, and so on.


> So what exactly is the point you are trying to make here other than that you are the smartest guy?

He took the one thing he could make an easy, pedantic point about and posted it. It's easier to do that and get free karma that actually be mindful. It's low hanging fruit. Just like I could find errors in his comment that would serve no purpose.

At issue is, while his point might be technically correct, it serves nothing other than to encourage "Me too" replies. This happens frequently on HN. I encourage you to down vote such posts.


The point can be that the team can do it BETTER. If you run Sonar on a codebase and get 10K serious findings... then the code certainly is not optimal. There is no upper limit on how optimial it can be, but you'll certainly have an easier life and a better end product if you've followed best practices as opposed to "just getting it done" by the most junior, lowest payed code monkeys possible.


Then by all means improve or replace bad code and create an environment that will encourage devs to learn from previous mistakes and improve.

All I am saying (and I think the author tries to make that point) is that it is questionable that you are going to create such an environment by pointing fingers and treating devs bad.

My very limited experience (I am the mobile lead in a company) has taught me, having done all of that myself in the beginning, that I wont achieve anything this way.

What I saw is that people got defensive by default, protective about their work (so no one can attack them for errors they made), the company started bleeding talent (what person is going to like working in such an environment?) and so called "code monkeys" never improved, because they didn't believe that they could achieve anything meaningful by themselves.

For some companies this might work in a way that I can't understand, but I changed, because frankly I didn't like to work in such an environment myself, and it did have to some degree positive effects.

People share more information, there's less pressure generally and there is more trust in general that everyone is doing their best, and if unable to complete some task, will ask for help.

By the way, here's a Google I/O talk from 2010 about engineering leadership that covers the problems mentioned in the article - I cannot recommend it enough: http://www.youtube.com/watch?v=skD1fjxSRog


If the majority of code is shit, then it's not really a very useful observation to make repeatedly. So I think this goes back to the author's point that this is really a cultural or attitude issue.

It's like the friend who complains about everything all the time: constantly complaining about traffic, about the weather, about how the city is losing its charm, about his job, about his classes, about his parents, about his car, about his apartment, about politics, about how stupid people are, etc. etc., with nothing positive to say. Maybe it's all correct from some perspective, but it's not a very useful perspective and it's definitely an annoying one to be around.


There is at least one useful implication to the observation, and that's that most (or all) software is shit. Yet people still use and buy it. The implication is a nice three-edged sword. You're guarded against crippling perfectionism, you're striving to get out of the shit as much as you can, and for developers you will always prefer having the source if you want to fix some shit. This article made me remember this from my quotes file:

"All software sucks, be it open-source [or] proprietary. The only question is what can be done with particular instance of suckage, and that's where having the source matters." --viro


That is not my experience. There is a ton of good to extremely good code out there. I'm rather dismayed by the amount of "well, what can you do" hands-thrown-up attitude here.

I've always found clean code to be faster to develop. I find that developers that produce lower quality code tend to spend their days debugging, fighting their code, reading and trying to figure out what they wrote 5 months ago, and so on. They are just not very productive. There are the outliers - people that have instant recall of all their code and elaborate mental models of really poorly structured code - but by and large I find that people that generate low quality code are quite slow performers.

I've worked in very good code bases, and very bad ones. In the good ones you can easily figure out what is going on, quickly make changes, confident that you aren't breaking 5 things because things are decoupled. You can produce new code quickly because you aren't fiddling with code nested 6 if statements deep, which is just about impossible to model correctly in your head. You aren't in endless compile/run/debug (or REPL/run/debug) cycles because your first try is usually just about right, because you can understand the surrounding code. I recently requested a simple feature, and was told it would take a week. I was dubious. Then I looked at the code, and decided that they were being conservative, if anything... for something I thought would reasonably take a few hours.

This is just an impassioned plea, not to Jach, but to the profession, to cast a critical eye on code. You can produce high quality code quickly. Not "nuclear reactor" quality, but pretty close. Bad code always costs you. Always. Don't write that way, don't allow it in your code base, or in your teammates.


I'm just going to ask the question...

What do you think makes your code good?

I bet the next guy that comes around in 15 years and reads your legacy code (Grats on having code actually runs for 15 years!) will think it's the worst piece of shit ever created and are sure to think you are one of the worst developers in the world.


Why would you bet that?

We have a broad understanding of how to structure and write software. These ideas have been collected together in books. I refer to books like Code Complete, Debugging the Development Process, Clean Code, Refactoring, Programming Pearls, Beautiful Code, and so on. Then there are the language specific books. I don't believe you can craft well written C++ without reading Scott Meyers' books (or having absorbed the same knowledge from others), for example. Even the much maligned Design Patterns, which has been turned into the truly dreadful design by pattern, helps us to think about how to structure code.

I can't type it all in a post. But we are talking about modularity and extensibility. Decoupled code, so you can make changes here that don't break something over there, and so you can easily move code from one project to another. Well commented code - where 'well' means the author takes the use of the code into account - some deeply internal function named ComputeAverageSalary probably doesn't need much in the way of extra comments, anda top level api call to a framework being used by thousands needs a lot of documentation. Well structured code. The if statements make sense. They are not deeply nested. logic is not duplicated, or contradicted when it is nested, because that always leaves you scratching your head as to the purpose of the author(s), and clueless as to how to add code.

So, back to the question, why would you bet that? I've opened plenty of 15 year old code that is good to beautiful. This is not an arbitrary judgement of "oh, OO good/bad", nor an reactionary "it wasn't written by me, so it must be bad".

I do consider myself a pretty clean programmer, but I learned it by observing the code of others, reading a lot of books, and relentlessly applying a critical eye on everything I write and others write. All borne not on some arbitrary judgement, but from recognition of how quickly/slowly I can grok a piece of code, how easy it is to find and fix bugs, how easy to add features, and so on. In some code bases that is all fairly straightforward, and in others it is impossible - any fix or change has so many side effects that you need to add 50 if statements strewn about 50 files, in code already filled with if statements, and your if statement break about 15 undocumented assumptions about the behavior of the tightly coupled code.... that, my friends, is shit.


> relentlessly applying a critical eye on everything I write and others write

Honestly, I believe that this is one of the best habits I've developed at my current workplace. We use Code Collaborator (a code review tool) for about 90% of all commits; I like using to get at least one pair of eyes on my code, but even further, I only even send out a review after I've gone through my own diff with a fine-toothed comb.


> What do you think makes your code good?

Answering for myself: (1) it's short. Often significantly shorter than my colleagues'. (2) it has few bugs, if our bug tracker is to be believed (I reckon I'm not very confident about that one).

On the other hand, I tend to be slower, especially when I have to write against less than optimal APIs.


But short code isn't necessarily a garrant for good code. I went through a teenage phase where I would strive to write the shortest code possible.

It's cringe worthy, and working my back into it seems scarce impossible. If you drew out the program logic, it'd look like an Eldridge terror. It just isn't good code.

But yes, if you're writing War and Peace in order to parse XML, it's unlikely you're writing good code.


I try to write the simplest code possible. It always end up being shorter than if I didn't.

Also, of two okay-looking pieces of code, I noticed that the shortest is almost always the simplest. Which makes size a pretty good metric.


My job is "first level support". I have to analyse problems reported by users and often to read source code to find bugs. I have seen a lot of shitty code and a lot of very clean code, but most of the problems come from shitty specifications. When the requirements reflect a poor understanding of the users need (or a poor sense of logic), whatever the qualities of the developer, the resulting code will always be a maintenance nightmare.


The developers should be able to push back on some of that - and at least document in the code that certain logical inconsistencies were raised but glossed over.

Simply understanding that something will be a maintenance nightmare should inform a developer enough so that they, at the very least, leave useful info/docs about what corners were cut and why. Until you've had to deal with mountains of various legacy projects completely undocumented, you won't even know this is something you should be doing.


I always thought 80% of coding (solving anything really) is understanding the problem.

The other 50% is implementation.


There's also the issue that most enterprise code is shitty by design. Tight deadlines and budgets, no time to write tests, project scope too large, too many features, too many developers on the same project, too many meetings and standups, poorly described requirements from Product, UML written by business analysts, overuse of patterns, Spring and other overkill frameworks, etc.

To err is human; to really screw up takes a committee.


"Most code out there is shit code."

semantic point. if you're saying 'most code' is shit, aren't you saying average code is shit?

Kind of like saying a 6 min mile is shit because it's not a 4 min mile.


No, a 6 min mile is not average. And yes the average of most things is shit. Shit isn't bad (unless it is), it is the output of useful work usually. It just needs to be covered up and stayed away from.


This reminds me of how pretty much everyone believes they're a better than average driver. Everyone also thinks other drivers are terrible. Both claims cannot be true.

I'd say its appropriate to call 'most/typical code' average code, not shit.


Exactly the analogy I went with.

"Everyone is a shit driver" claims almost universally come from terrible drivers: When you have no situational awareness and aren't actively predicting the behaviors of drivers around you, and you don't have confident control of the tools at your disposal, every move that other drivers make seems dangerous and scary, needing panicked reactionary responses. Every trip is a perilous journey with tales of imminent death.

I honestly feel the same about people who walk around declaring all code shit. People who aren't competent with their development tools, can't naturally trace code and truly understand functionality, and can't adapt to different styles and era of code tend to be the ones, in my experience, that declare all code shit.


> Shit isn't bad

I would suggest that this indicates that your figurative use of "shit" is not the common figurative use of the term in the phrase "shit code", which is impairing communication.


True, I was making a facetious statement that everything that eats produces shit and that the "shit code" is just another by product of a living organism (team, business, coders). Something can be not-good and still be not-bad. I would say my figurative use of the world shit in this context is near neutral but flawed quality. Like dollar store tools.

Most of my code is shit probably by everyones definition. So I try and write as little as possible to solve the problem. If I spent the time required to make all of my code non-shit (not good, but non-shit) then I would get very little done.

It would be nice if google wave didn't tank, or this discussion board was scriptable by the end users because I would love a sidebar where we could agree on the definitions of terms under discussion.

Due to the lack of attention, willful or otherwise, most conversations online end up talking _past_ or _at_ each other and not to.


Agreed. Hell, most of my code lately has unit tests and UI automation tests and goes through code review and adaptions for a week after writing and it is still pretty shitty and needs to be tweaked later and will always be a crappy code by committee result by the end. Just getting it into production is a grueling battle that sucks out the most idealistic souls and makes most into code monkeys just trying to hack something out. But hey, if I was coding for a startup lately all of my code would be shit because of long hours and no tests since most of the time we're just writing experiments we'll throw out later so why test?


Shit is useless, destructive and smelly. Unrefined code by an unrefined developer often works, but not as well as it can and is usually difficult to work with. Big difference. Just like most of the stuff reddit calls "epic" or "mind blowing" is often simply 'neat', most of the code you call "shit" often simply 'could be better'. The tendency to call unrefined code "shit" intimidates new coders and disincentivizes people from contributing to community projects.


For me, the tell-tale sign is a demonstrated lack of understanding of type theory. Like calling toString on string objects. Or even worse, calling parseInt on a string that was created by calling toString on an integer!

Also, comments-used-as-source-control. If I see one more gigantic block of code commented out with a set of initials and a date "this was removed by/on". Use the source control to do that, dammit.


In my experience, shit code tends to start with a competent developer solving a problem in a way that seemed reasonable at the time, and then requirements changing, new features getting added, and everything is in a hurry so it never gets refactored.

Well, sometimes I do see code that's really very bad and I can't imagine how someone was ever able to type something like that, but that's rare. Usually it's competent people with the best of intentions but as lack of ability to predict the future.


It depends on what you mean by shit code.

Is code that was written on time and on budget - but has a few hacks in it shit?

Is code that is beautiful and easily maintainable, but was £1m and six months over budget not shit?


Shit code is the third option: Code which was late, over budget and completely unfit for purpose, requiring an army of temp workers to process everything manually while another team come in and spend months on a death march trying to fix it, while the business is hemorrhaging money via lawsuits from pissed off clients with violated contracts.


You're assuming all code is written in a vacuum. Sometimes developers are forced to write code under unrealistic time constraints, or they were told to prototype it quickly b/c we'll replace it later (but they never get the time to), and so on.


Sure, there is some really bad code out there. But even pretty good code looks really bad to a lot of developers, because of the "This is shit" mentality the article describes.


Most code out there is shit code. Denying it is not going to help either.

So you do it "right" then, I assume. What do you think the next guy is going to say about your code? Do you really think they're going to praise the excellent code quality? Or will they declare to all around that it all needs to be rewritten because it doesn't conform to the newest flavor of the month?

I absolutely and unequivocally agree with the author: People declare everything around them as shit to prop themselves up, and the explain their own inadequacies in advance. There is shit code, granted, but by some measure of shit all code is shit. A viewer can destroy code as over or under engineered, over or under built, over or under abstracted, over or under object-oriented, over or under functional, and on forever, and anyone who thinks there is an actual right way in any reasonably complex system is demonstrating profound naivety.

The one thing that I will disagree with in the submission is the notion that this is a new or increasing pattern. It isn't, and has been the norm for decades. This is what developers do, especially those who are weak at reading code: Declare it shit in advance and just write your own.


Maybe I haven't been entirely clear.

I'm not talking about a mismatch between approach (over- or under- whatever) and goal. I'm not talking about quick hacks that were never refactored (because of course, there never is time). I'm not talking about code that has gone through many cycles of unpredicted change and has acquired many layers of cruft. I'm not talking about code made by inexperienced developers who still have a lot to learn.

I've seen all that. I've written all that. I've left code behind I would be embarrassed to show in public. I'm shocked some of it is still in use, and I'm sure people who have to maintain it will curse my name. That is part of the job.

What I'm talking about is pure, unadulterated shit code. No structure, no logic, no consistency and barely functioning only under very limited conditions. Utterly incomprehensible unless you immerse yourself deep into the mind of the author like an FBI profiler and a serial killer.

No, there is no one "right" way of writing code, but boy there are an awful lot of "wrong" ways.


I know what this guy is talking about. It's the sort of code where the programmers spend 80 lines copying key-value pairs from one Perl hash to another Perl hash instead of doing it in 3-4 lines with a loop, because they don't know any better. coughibmcough

(Of course, this is among the least of their offenses.)

I try not to work at places like this.


I thoroughly agree that there is a difference between hacky code and shit code. I've seen far too much code which isn't even attempting to solve the right problem, but is so buggy that its myriad problems compound to make it sometimes appear that the original problem is solved. Things which takes weeks to understand, and only went unnoticed due to an extraordinary unlikely coincidence of errors at all levels of the stack which Rube Goldberg would be proud of.


I would suspect that such practices are more prevalent in the web development world. Enterprise software and embedded development (my focus area) suffers far less from the pure unadulterated "shit" code pattern.

Mostly I suspect that is because the software development practices such as code reviews and coding standards are actually enforced.


I would hope that embedded is better. But the "Enterprise software" that I have seen is generally horrible.


I once was responsible for maintaining code like this:

There were 3 client-side javascript files. They were named something like this:

foo.js foo2.js foo-z.js

Each file was about 4,000 lines long. All 3 were nearly line-for-line identical, save for about 500 lines of differences each, strewn wantonly about. For some of the URLs the app would use foo.js, for some other URLs it would use foo2.js, and for yet more of the URLs it would use foo-z.js.

There were 4 files on the server like this which did the same thing - copied line for line and then changed in various places.

After refactoring these files together and eliminating the duplicate code, I ended up deleting something like 8,000 lines of code. I quit soon after - by then I was already looking for another job.

That code was shit. There is no question about it.


Have you never seen a piece of code that sucked so much that you could shrink it by a factor of at least 2?

You lucky swine… Much (possibly most) code I have had to deal with was that ugly.


Almost all code except the stuff written by the Masters of Succinctness can be shrunk by a factor of 2. Order of magnitude reduction is the only impressive metric.


I talk about code that I can shrink by a factor of 2. Most often without even understanding what the code does, just applying local correctness-preserving transformations.

I'm talking about horrors such as (this was real, production code):

  bool flag = true;
  if (var1 == const1)
  {
    if (var2 == const2)
    {
      // quite a lot of code
      flag = false;
    }
  }
  if (flag == true)
  {
    // a little piece of code.
  }
Clearly, someone forgot to clean up their code. It doesn't take a Master of Succinctness to realize that

  if (var1 != const1 ||
      var2 != const2)
  {
    // a little piece of code
  }
  else
  {
    // quite a lot of code
  }
is much better (the code represented by the comments didn't touch the flag). Plus, such simplifications tend to compound. After a first pass, I often see more possible reductions that can be used for a second, sometimes a third pass.


I don't know whether code verbosity is a measure of shit (indeed, that is one of those arguable points where one guy likes the single line ultra-functional version, and the other likes the same split into 20 lines).

I'm not disagreeing on the notion that there is some shit code in the world. Of course there is. But if anyone thinks that all or most code is shit, it often says more about the speaker. And I don't mean this as a personal attack on anyone, as it is possible that someone is in particularly dire code straights, but by and large the people who I've known who think all code is shit tend to be of questionable talent.

I have a friend who is constantly regaling the horrors they meet on the roadways because, in their opinion, everyone is a shit driver. Only it's my friend who is the shit driver, and their reactionary, panicked driving technique puts them in such constant peril that they can only imagine that everyone else is to blame.


I like your driving analogy. It's very true. Those who talk the most shit often are shit, like how some men call women bad drivers even though women are actually less costly to insure.

Bad driver stereotypes piss me off because they often work under the assumption that cautious drivers are bad drivers and aggressive drivers are good drivers. Hell I bet Asian women are really the safest drivers.


There are a number of experiments that suggest that overall, the best predictor of shit (mostly, cost and bugs) is size. Once you account for size, almost every other predictor tend to be more noise than signal.

So, while there are ways to make code so short that it becomes incomprehensible (code golf?), most of the time, less code is almost always a good thing. A case in point would be the factorial in Haskell:

  fac i = product [1..i]


A factor I think the article doesn't point out clearly enough is how the main attraction of dissing code is that it serves as an ego-defense mechanism. Understanding code is, almost without exception, challenging. It's much easier on our self image if we believe the code is to blame, rather than us.

An unfortunate side effect is that this perceived badness of the code is then often used as an excuse to not really try and understand it at all ("let's rewrite!" or "we don't touch that anymore").


A good assessment in my opinion.

As a junior coder earlier in my career I found exactly the situation described. A co-worker was always griping loudly about how bad the code and architectural decisions of certain people supposedly were - all except his own, of course.

At first I was too diffident to form an opinion and considered whether he might be right. When I gained more experience, and finally got a look at what he was ranting about, it seemed to me that this guy's targets were not so bad and that his own output was hardly more impressive.

Eventually I saw other examples of this pattern and realized something: those who bluster in this way tend to be middle-range developers who are trying to cover up their own insecurities - while those who are really superior tend to be quieter, more businesslike and basically getting things done, and well, while those described above are going on in their "BS" sessions.

I don't claim to qualify for the latter group to the degree I would like, but when I hear the denigration, I ask what are the specific problems and what do we propose to do about them. And I try to promote a positive atmosphere, and really learn the code rather than just looking for where to put more duct tape.


> all except his own, of course.

yeah, if you're going to talk bad about anyone's code, start with your own. not even the things you wrote a few months ago, but like even today, writing xml schemas for a rest api, the whole time i'm thinking about all the ways the decisions i'm making are going to come back and bite me in the ass. not because i'm inexperienced but because i've written and worked with schemas and specs for interprocess communication before and know that any changes to the schema will require edits to multiple codebases and the time and effort to make some of those changes can be frightening.

i guess this is what fred brooks calls "the second system effect." it'll probably turn out that there's some other more terrible problem with the current system that i'm not even seeing because i'm overly concerned about the communication protocol on top and not the databases underneath or concurrency off to the side somewhere.

how many systems of some particular type does one have to build before not writing shit on the first pass? because, like, yes, the code freely available to anyone with a quick `apt-get source` is often of much higher quality than some things hidden in multinational corporations' private repos. so everyone can have some idea of what good code looks like now, but i am personally finding creating much more difficult than verifying and fear that it's going to take a lot of time to narrow that gap.

is it really necessary to work on like 8 processors before doing what someone like ivan godard does? maybe just 4 or 5 projects (which translates into about a decade, mind you) is enough before the "i'm fucking shit up" jitters pass for any particular type of system?


Yeah, I can agree with this. For me the scenario starts with reading somebody else's code and thinking it's horrendous. I'll then get this nagging feeling that the problem may instead be me not comprehending the code well enough, or not seeing the greater context in which the supposedly bad code is meant to sit. Frequently, after further investigation, the code turns out to be not as bad as I originally thought. It's almost like a judgement without all the facts / can't see the florist for the flowers kind of thing. I'm looking at that small piece of code through an aperture that blurs the bigger picture, if you widen it a little further you may see that the code was written in a certain way in order to coalesce with the rest of the code base. Or widen it further still and see that it was written poorly because it needed to be done quickly, but that poorly written code may have facilitated the first 1000 sales of the product. I won't listen to someone who trash talks another coder or a former employee for their work. It happened the other day at my job, the new guy trash talked some ops work belonging to the guy he replaced. That work has been keeping our site available for the past five years, still waiting for the new guy's road tested commits.


If the code really is shit then the best course of action is to work at understanding it and then refactor like crazy.


Well said. My most important development as a programmer has been my skill in reading other people's code. I've noticed that I think a lot less code is 'bad' nowadays. A lot of the time, it's not how I'd write it if it were me, but that's not the same as it being shit.


Some years ago I was doing paid for code reviews. I learned many things but one particularly relevant to this article is: You can only tell if code is shit after you have dug through it for at least a few days.

Sure there are the obvious mistakes like non-idiomatic code style. But that's easy to spot. But for anything that is related to the problem domain and not the language itself you need to dig deeper. Because there might be a very good reason why something is done the way it is done. And later you might think: Hey, that's actually a pretty good solution.

Wading through piles of code by dozens of different developers made me humble and nowadays I think twice before calling something bad.


Indeed, I came across a last_day_of_the_month SQL implementation today that I showed my colleague who's instinct was that it was shit, but upon closer inspection, it seems quite clever.


Checking the history of the file can also be quite revealing. First version usually looks good. Later, most commits are just trying to squeeze in new functionality by changing as little as possible of the existing code. 20 check-ins later the original design is no longer relevant and mostly consists of exceptions because nobody was brave enough to refactor. Getting refactoring approved could also be hard by in certain cultures and organizations because "why change something that is proven to work in production"


Behold, the aftermath of the brogrammer.

What was seen here is a particularly insidious, caustic and ultimately, demoralizing and self-defeating attitude from your colleague (and something I've seen routinely on HN). I don't particularly think he was in any way truly convinced that it was deserving of it, however it must be thrashed in accordance with a self selected pecking order in order to assert his dominance.

This "politeness is rubbish" attitude which also applies to common niceties in communication will one day be the death of us all.[1]

There is truly awful code out there and it doesn't deserve commentary or any other sort of attention. Just a yanking and replacement with good code.

[1] Politeness devoid of sincerity is not politeness. It is in fact the worst of all forms of rudeness.


I don't see how this has anything to do with the brogrammer fad (as annoying as that was/is). People have been talking this way about code for a lot longer. I'll throw out one of Linus' gems as an example [1].

[1] http://staefcraeft.blogspot.com/2013/07/linus-torvalds-there...


Dated "13 Jul 2013". I'm curious what Linus was like before he created Linux.


At least in the message that introduces Linux, he's much more congenial.

https://www.cs.cmu.edu/~awb/linux.history.html


"Brogrammer" is ill-defined. It's silly to blame something on an ill-defined concept.

http://gizmodo.com/5910824/theres-no-such-thing-as-a-brogram...


How about a culture of "stop fucking up". (I admit I stole this from Ted Dziuba, but it has stuck with me.) People who are willing to call things "shit" instead of being nicey-nice at least give a shit. But it is important to be intellectually honest, and not be egotistical about one's own code, which could be shit just like anyone else's.


"Stop fucking up" quickly ends up with "stop taking risks" and "design by committee", which may be a good idea if you write avionics or banking software, but perhaps not in other markets.


> "stop taking risks" and "design by committee",

Those are both fuck ups. So, I respectfully disagree that "stop fucking up" leads to those ever and suggest you don't understand what fucking up entails.


Those are more subtle fuck ups that the company might not notice for a long time, usually when you're eclipsed by the competition and upper management has been replaced.

A better slogan might be "always make new mistakes".


I don't like Dziuba's harshness sometimes, but I agree with this sentiment. Code doesn't care about your feelings, and you shouldn't either. Just write good stuff that works, and if it's not good, don't blunt the message. If you think code and programmers should respect your feelings, you'll get slow code with many bugs, and few people willing to do anything about it in order not to hurt other people's feelings.

Straight up honesty is the best medicine when it comes to software. If you have a problem with this kind of honesty, find something else to do.


>> People who are willing to call things "shit" instead of being nicey-nice at least give a shit.

Or they're just adhering to the culture of calling all imperfect code shit because that's what they see others doing.

>> But it is important to be intellectually honest, and not be egotistical about one's own code, which could be shit just like anyone else's.

Well said.


If someone's "fucking up" repeatedly, either constructively work to remediate them or replace them. But simply being a jerk does not prove or disprove that you "give a shit". It just means you're not very good at articulating what's actually bothering you or separating the actual problem from your frustration.


Point taken - it's very easy to feel like someone else's code is bad if it's hard to understand or does something in a way you think isn't the best, or even good. Maybe being nice is helpful sometimes.

On the other hand, sometimes code really is just shit. Being positive and saying "this is a good start, let's go through it and see if we can improve upon it" might be a massive waste of time if it's really shit. Sometimes holding people to high standards is necessary so the whole team doesn't get held back.


I can't imagine any reason to not be positive and constructive, no matter how bad the code is.

If the code is bad, then improve or replace it, and do your best to help that developer improve his own skills, so this wont happen again.

If code output is constantly bad, then fire the developer, but there's also no reason to be condescending here.

I just can't see that treating a developer (or anyone else) like shit is going to have any positive outcome considering the current market for developers, where demand is much higher than supply.


That is a fair point. And to be clear I'm not saying there is not shit code out there, because there is. I'm arguing against a type of culture that praises negativity rather than contributions.


I would take your point forward and say if the code is hard too read then is it shit.

There is a reason that you are reading it: you are maintaining it, adding a feature or trying to fix a bug. If it is not easy to read then it makes this harder and that makes code bad and increases the chances of the editor making a mistake and breaking the system. (Or just making your day bad).


Is it hard to read or hard to understand ? Generally when we say "hard to read" we mean both. Especially because as you said, you read the code for a purpose, and that purpose is very often business related rather than purely aesthetic.

Making the code easy to read is simply a technical matter, an intrinsic quality of the code. However, your code cannot be easier to understand than the business it models.

To convince yourself, have a look at some (good) framework like a HTTP Server, ORM, or browser, ... Their code is generally miles away from what you expect and hard to read if you do not dedicate days or weeks to them. But it is not due to bad code but due to the fact that you are aware of only a tiny fraction of the problem they solve.

EDIT: (I realise I didn't make a point) My point is that it is not a hard rule. If you are experimented with the business, familiar (a bit) with the code and it is still hard to read that is the sign of trouble.


If a man does 5 pushups of asked 20, is he full of shit?


...when I asked my coworker to explain...why is the code shit, I couldn't get a straight answer.

Maybe because there are only so many straight answers and we get tired of repeating them so often...

Class A: It's too difficult for the next programmer to understand this

  - poor (or horrible) variable naming
  - poor (or horrible) function naming
  - repeated repeated repeated repeated code
  - comments don't match code
  - comments needed but not there
  - comments needed by unintelligible
  - unbalanced structure
  - poor (or horrible) choices for iterations
  - poor (or horrible) choices for conditionals
  - poor (or horrible) choices for data design/storage
  - poorly maintained by Programmers #2 thru x, who didn't understand it
  - etc., etc., etc.
Class B: Poor machine performance, not by 10%, but by 10000%, because of extremely poor design and development choices.

Class C: It's broken. Insufficiently tested & broken in production.


In my time as a professional programmer I've come to notice a trend. It's true that there is a lot of bad code in the world and much of it is worthy of derision. That said, time after time I've noticed that when confronted with a smelly codebase junior and/or less-skilled programmers are quick to blame the code and the person who wrote it while more senior and/or highly-skilled programmers will start by placing the blame on their own lack of understanding.


Junior programmers aren't aware that reading code is hard, since they've never really been forced to read much code (AFAIK there's no point in a CS course where "scour this 500KLOC non-didactic codebase for the cause of this bug and fix it" is assigned.) Because they aren't aware that reading code is hard, they think that code that's hard to read is a code smell, whether the complexity comes from obfuscation, or just the inherent complexity of the problem domain.

They also don't know that they don't know this, because they've seen code that's comparatively easy to read -- why, they've written it themselves! Their implementation of only the minimal requirements of the domain is much clearer than someone else's complete solution with all its required business-warts. As such, obviously, throwing out the previous complete solution, and filling in the gap with their own minimal reimplementation, is an improvement. (They don't notice that after fixing the ensuing regression bugs, their version now bears a much stronger resemblance to the previous one....)

Eventually, you read enough code that you get used to that particular "smell," and you realize that it's not really pungent in the way the other smells are. The "complex problem-domain, completely expressed" smell becomes the grease on the equipment[1] -- the sign of a well-patched and long-running system.

---

[1] http://www.joelonsoftware.com/articles/Wrong.html


It sounds like junior devs are applying an attribution error: http://en.wikipedia.org/wiki/Fundamental_attribution_error


I've always tried to go the opposite route when reading code from others. I'm the first (well maybe not the first but I'm at least close enough up the front of the line to see the first) to admit when I don't understand it, and when I go ask the guys who wrote it, I make this clear.

Usually I find talking like this helps people admit when code is just bad or they try to clarify it. I've found it makes asking whether it's ok to do complete rewrites a lot simpler.


I still love it when you find some "shit" code, just to realize you wrote it yourself ages ago.


This is a sign of progress, actually. If you cannot find faults in the code you wrote ages ago and think it is awesome, time to find and fix some deep problems.


Not necessarily... it's only progress if you wouldn't do the same thing again.

It's one thing to be able to recognize shitty code in hindsight or in another developer's work. It's quite another to be able to catch yourself before you write shitty code and do better.


I think the problem is an unwillingness(don't want to insult a co worker's code) or inability to form real criticism. If you can't pull the code base apart and say "this worked well" and "this part made too many assumptions to ever work right" or "is overly complicated for the task at hand" then you haven't taken enough time to understand the code in front of you.

This hits at one of my least favorite memes around here. The whole all the code I wrote six month ago is shit, and I will think that about the code I am writing now in six months. Yep, if you haven't developed the skills to determine what is good or bad about the code you wrote six months ago then A) It probably was middling code B) You aren't getting any better because you are unwilling to honestly critique your own work to look for areas that need improvement.


This is similar to the discussion around "legacy code", which in many ways is corporate speak for "shit code". In his book "Working Effectively with Legacy Code", Michael Feathers provides an interesting definition of legacy code. He defines legacy code as code that is not under test. The idea is that if code is under test then it is easier to improve/refactor.

Maybe instead of saying that code is "shitty", we should retrain ourselves to say that "this code has no tests." It's more productive and points us to a direction out of the situation and prevents us from getting in the situation to begin with.

I suppose some might argue that shit code is not necessarily legacy code or vice-versa. Perhaps, but in either case the first step in improving it is to get it under test.


I think "shit code" usually falls into two broad categories (or both). Either the developer has a poor understanding of the problem they're trying to solve and comes up with something that is a massive hack/barely works (see: workaround oriented programming) or it was written in a style that the person reading the code considers "stupid" or "outdated" (this would fall into the legacy code category).


Now the question is, who's smarter, some punk kid, or the guy who wrote some code that is still running, still doing its job, still making money for the firm, 20 or 30 years later?

Because that's what "legacy" code is, if it wasn't doing something vitally important, it could just be deleted. It's not shit, it's the family heirlooms!


I imagine anyone who's been around for long at all has written what someone would call "shit code."

Hindsight is 20/20. Imagine auto makers comparing product today with those from 50 years ago? That's about how far we've progressed in 10-15 years in this industry. Were those guys whose contemporaries were able to send people to the moon on CNC-less machine tools and computers with 4K RAM somehow doing "shit engineering?"

Imagine if what someone sees as "shit code" ultimately made yesterday's coder $1000/line because it got done while there was an opportunity to sell it. Is it still "shit code?" You're not being asked to be a music critic here. Most code is written as part of a business.

That said, code reviews are a great way to learn from and align with your team!


Good point, but writing software in PHP or Java is voluntary retardation. You're holding back the advancement of our trade.


> Java

I call bull. Java has plenty of issues, but plenty of plus points too, particularly for large-scale development on teams that experience employee turnover.

- Reasonably fast, considering the ease of development.

- Genuinely fantastic tooling.

- Generally discourages 'fancy' programming techniques. Obviously doesn't stop shit code getting produced, but at least tends to be relatively easy for maintenance programmers who weren't heavily involved in original development to understand.

I have to use Java for some of my work, and with the correct tooling it's really not that bad. Sometimes it's fantastic - when you're maintaining someone else's code, the ability to trivially (and exhaustively) find out what code calls this code, safely refactor and so on is invaluable. Of languages in its general class, C# is significantly superior, but tied to MS if you want a full-speed VM.

I'm not saying that you're likely to produce the most beautiful code of your life in Java, but compared to many other languages (+ toolchains) I find working on other people's code is rather easy.


A toilet that doesn't flush correctly isn't a reason to complain if you're a plumber; it's your raison d'etre. And, although many don't want to recognize it, a good number of software developers are modern day plumbers.

For many developers, imperfect code, which is often more likely to be result of circumstances beyond the control of the person who wrote it than downright incompetence, is the gift that keeps on giving. If business and functional requirements were always well-defined and never evolved, clients/business stakeholders completely sane, deadlines realistic, resources plentiful and "scope creep" a rare phenomenon, a lot of software developers would be unemployed, and employed ones would be more frequently undervalued.


As developers we might need to work on not taking bugs and criticism of our code too personal. I know I feel that way sometimes, when bugs or bad design is found in my work it is easy to get defensive and take it is a personal attack - which usually is not a constructive approach.


The other, darker side of this culture is that you're not calling the code shit, you're actually calling out the author of that code as shit.

Sometimes, it is not really in the code or in the design. Some people are just downright evil.


Ugh. Another "let's-act-like-everything-is-happiness-and-rainbows" post.

In my experience, most of the time someone says "this is shit", it actually is, and it's indicative of serious failures in the hiring/training/code-review/management process.

The only ways that companies improve at those processes are by pointing out the shit, calling it by its name, and figuring out the best ways to keep it from happening again.

Having a "this is shit" culture can be GOOD -- it can hold people accountable and promote a culture of excellence.

> In the end it is a culture that values negativity rather than focus on solutions.

That doesn't follow. Call it shit, and then fix it.

> Start by understanding the code, and then find ways to improve upon it.

That means that, instead of fixing the underlying problem and making people accountable for their work, you take on the burden of cleaning after other people's shit? I don't think so.

The author is correct when they say:

> Don't blurt out negative assessments of others code for no reason, and with no understanding. ...Start by understanding the code

But that goes without saying. Don't be too quick to judge when you don't have the facts. But once you're sure the code is shit, it's ultimately counterproductive to hide that. Most employees will only start writing better code once they're expected to, and strongly held accountable -- like most people's performance in any job.

PS: To be clear, I'm not talking about disagreements over coding styles, etc. I'm talking about code with obtuse function names and no comments. I'm talking about CSS that is hack upon hack upon hack filled with negative margins and !important's. I'm talking about JavaScript that pollutes the global namespace by programmers who refuse to use "var". Or CSS declarations like "div div span div span tr td span {color:red;}". And there's a tremendous amount of this stuff out there. Stuff that there's never an excuse for.


No way "while bool.toString().getLength() > 4" can be a shit code! It works, what else do you need? Learn to understand first.


The shitty truth begins to appear when you've — way too many times, might I add — read the old code, thinking it makes sense and then feeling the pain of naivete shifting out as the code eventually turns out to make no sense.

Then begin to recognize potentially shit earlier in the process and while you do enough many rounds of that, confirming your expectations, you can just look at the code and say "this is shit" and be quite confident that you're right.

That's not to say that there wouldn't be a similar process working towards recognizing "When to rewrite this shit?" There is and the answer it gives is "Rarely".

A seasoned programmer will balance between "this is shit" and "not rewriting this shit". And there's nothing wrong with shit, because the shit is shipping and mostly works unlike the ultimate refactoring that nobody has time to write.

So it's the programmer's job to fix shit, and occasionally write new stuff that shall be deemed shit by a later fellow colleague.

Instead of pointing at the vague shitty attitudes towards shit, the author should probably just roll up his sleeves and start fixing the shit.


Kind of reminds me of a story from today. I have about a 70 page design document, laying out exactly how a new system i'm building will work. I've built something very similar in the past at a previous company, so this design is coming from a few years of learning what doesn't work.

As I was trying to explain some of my, well non conventional ideas, another coworker pokes his head over the cube, and calls the design crap. This of course is nothing new, its almost a game for this particular engineer. In the end, I walked away trying to avoid the conversation. It felt emotional though, and frankly hurt my confidence (while probably inflating his own)

It kind of made me think of the phrase "no one ever got fired for choosing IBM" I could have chosen the obvious design, and gone forward. No one would have debated it. However I've done that in the past, and I've seen the terrible problems that come from it. My new design is an attempt to avoid those problems. The attitude really pisses me off though, and I find it extremely counter productive.


I think you can use the co-worker to your advantage. One thing we must all learn is how to defend and justify our decisions. This can either be done before or after implementation, which is what I believe the post is talking about. That is, people criticising others' implementation decisions with limited context. Most of us have read stories of Gates or Jobs dressing down employees that are unprepared. You could consult your co-worker before presenting in the future; assuming you can develop your relationship with him to the point where there is no malice in such an interaction.

On the other hand, I do also recognise that some people just like to mess with others. In such circumstances, if there are no other political concerns, I would simply ask the person the come up with an alternative solution, then argue the alternative on its merits vs. what you have designed. Given your 70 pages of documentation, a simple pros vs cons list that takes into account goals of the project for various timeframes and scales should result in a clear winner. Or should both designs be of similar value, then there is little point in changing your documentation anyway.


"Psychological projection was conceptualized by Sigmund Freud in the 1890s as a defense mechanism in which a person unconsciously rejects his or her own unacceptable attributes by ascribing them to objects or persons in the outside world."

In other words, we think out own code is "shit" so instead of dealing with that, psychologically, we just attack others.


Actually when I say "code is shit" I usually just mean the code. Often times I find it's my code when I look back, it's still shit though.


I don't see how you can make that conclusion from the quote.


Relevant (not-XKCD) comic: http://www.osnews.com/story/19266/WTFs_m

I'm not opposed to calling out shit, even in my own work, but you ought to be able to explain the smell, even if it's something silly like curly brace location. (Ideally it's shit for a better reason... there usually is.) Besides if a rant doesn't immediately follow the declaration, you can't really claim to care all that much. If you're working on the Linux kernel and get flamed by Linus consider yourself lucky! It's because he cares. (And thinks there's still hope for you to do better.) I don't mind the rantless half-hearted calls of bullshit either; rather than leading to everyone feeling bad and trying to feel less bad by trying to make other people feel bad, I think it would sooner lead to more cynicism with insults and less taking offense and feeling bad.


asking people to be very specific is the first thing that should be done in any technical environment. "shit" is going down all over the place, please emphasize.

asking people to be nicer in a technical environment would require similar levels of education and understanding of the tools involved. you seem to be a person that makes other people get stomack aches from bad code, so maybe you should reconsider your abilities.

if you write overall good code it's inherently easier to find a bug in it than if you just stitch shit together. if you solve your problems with stackoverflow and/or huge books like "how to... in 21 days" you should maybe reconsider your career choices.

in code the attention to detail is always more important than the overall intention, so why not leave it at that?


    $query = "SELECT " + $_POST["foo"] + "...";
    db_run_whatever($query);
What you call that depends on what you know about the situation and the bigger picture.

It doesn't change what it is, or what it implies.


In my experience average code quality has considerably improved in the last, say, 20 years, I'd guess because of open source and the internet spreading higher standards, hardware and systems improvement relaxing efficiency constraints, and better education that just takes time to spread. When I started my job after college, the first day they handed me a 20-page DOS batch file to modify, and yes, part of that's my career trajectory, but I think there's more to it. I didn't say so, but in my own head "this is shit" was among my reactions, and shit these days has to work to measure up.


It is a problem if programmers cannot give a reason why the code is shit. But most of the time they give reason, the reason is not good enough. However, I still think it is necessary to say "this is shit code".


I totally agree, somehow our alpha macho instinct likes to come up and show everyone else how much we know better. Worst of all, this attitude is well rewarded on some circles.

The above said, sometimes code is really shit!


If code is not clean we should be able to state for at least two reasons why. e.g. It breaks SRP, lacks dependency injection, not enough abstraction. Saying something is "st" usually means we lack the verbiage to describe it. Clean code is a continual process one that needs curation with care. There are times when we are reading code and it's just terrible to understand. No care was put into it. My frustration comes to when I don't see care in code. Code is not inheritedly careful. We have to make it that way.


There are also many other factors that come into play when developing code, particularly if it's as part of a team working to a schedule, that have nothing to do with technical competence. In agile development you always prize something working over something pretty and the business need is firmly in the former camp so the pressure to improve code existing is alway balanced against adding 'value'. None of which is visible when you are confronted by a snapshot of the code.

However, sometimes code is just shit.


Except usually the code is shit, and that's ok. Sometimes I'm even talking about my own code and that's ok too.

The first step to fixing a problem is admitting the problem exists. Attempting to cover it up it with words like, "well I'm sure there is a good reason for that" or "Hrm that could be better but I know we had crazy deadlines." Are just excuses and don't really help.

If looks like shit and smells like shit... well it's probably shit.

We are all big kids here, no need to sugar coat things.


Shit code is shit code no matter the circumstances surrounding its creation. The way I see it, the author got the solution to the problem all wrong. You should be able to criticize bad code, and if the criticism insults you, you should just swallow your pride. You aren't your code.

The problem, if any, isn't the criticism itself, but the lack of explanation. If you can argue for why a piece of code is shit in a way that will help other developers, please do!


I'd say most code is shit. However, I'm sure people don't deliver shit code by pure choice. Unclear function purposes, time constrains, bad days, etc. Or just the plain old, "quick hack it together" to get back to the code you where really working on. We should just not feel insulted about the fact we write shit code, this doesn't mean you are a shit programmer.


Programmers are critical thinkers, that's why we are good at what we do. That's why no code anyone writes including our own 4 or 5 years down the line meets even our own standards. You have to be a critical thinker to get coding, to want to do it. The only down side is so much critical thinking wears us down over time. If anything, we should force ourselves to take more vacations.


I don't see it as a code culture problem, or hell, even a problem in itself. It's a dude issue. Dudes can be judgmental, and if not held back by some corporate culture, if not applying filters of courteousness and being the better man, or by simply being in a certain environment where certain behaviour is frowned upon, things like this will appear.

On the one side, it's a bad thing. On the other, it's stereotypical dudely behavior, and should be made fun of. "This is shit!" is, from my point of view, a way to observe that code 'feels' off, and an exclamation of frustration in that the reader can't understand it right away - and apparently doesn't have or can't take the time needed to dig in and understand it deeper.

I often go for gut feelings in judging code (this is shit!) too, so I can understand. I can understand the frustration too when one can't spend the time to understand and fix it - besides, someone else wrote it, someone else should fix it.

tl;dr, it's complicated. If someone exclaims "this is shit", go and investigate. Sit / pair with the person, walk through the code - or even better, if possible, find the person that wrote it - and either make it unshit, or make the person making the observation understand why it's not shit.


A lot of is an age thing. I vaguely remember feeling like that but that was soo long ago. Of course there is a lot of truly crappy code but you're only allowed to complain about it if you write flawless code each time, every time out of the gate, e.g. never.

Also, whatever your favorite "technology" is today is probably a bad joke to the next guy.


I just give newish developers this link:

http://en.wikipedia.org/wiki/Code_smell

And magically the number of "this is shit" comments decrease dramatically. The problem is that people don't like seeing easy to spot problems, but instead of giving people a guide, they complain.


I almost never look at somebodys code and think it's shit. Sometimes I think some ideas are not the best possible ones in given context. But I almost exclusively think "this is shit" while I'm looking at my own code. And I agree that that feeling is a problem as it often destroys my motivation to finish what I started.


> it often destroys my motivation to finish what I started

Shit code, mine or others, highly motivates me. To refactor/fix it. To the point I have a really hard time making targeted, single purpose commits.

Because I have pride in my work, concern for the dev who has to maintain this shit after me, and understand costs of technical debt.


Good article, couldn't agree more. Its about time someone spoke up about the extreme negativity that has become coding culture. I've worked in companies with very negative developer culture and more positive developer culture and found the latter to produce far superior software (on time, in budget, less bugs etc.).


60% shit removal! A review removes 60-80% shit, to remove more than 80% use compounded shit removal. Compound requirements, design and code reviews to get 99%+ shit removal. finding 60% shit is not hard, every time you spot a little shit spend 3mins thinking about how to create better next ti


It's not simply a code culture problem; there are tools like Programming Mess Detector, PHP Mess Detector, Findbugs etc that can quantifiably show just how crappy a lot of code is. See http://pmd.sourceforge.net/


From my personal experience, individuals who say "this code is shit" are often far removed from the process of writing code in the first place.

I wonder where the whole "Worse is Better" paradigm fits into the universe with good code, acceptable code, and "shit code".


This also seems like something you could get fired for. You are not just disrespecting your teammate's judgement but also your boss's judgement in hiring your teammate. Therefore you are not a team player and maybe shouldn't be on the team.


I think this is just a general reflection of modern (internet) culture. It's easier to get "internet points" (read: facebook likes, twitter retweets, etc) by being snarky than it is by being positive.


This piece reminds me of Linus Torvalds. He's the kind of guy that lives these truths. Always respectful and constructive, never saying code is shit, etc etc. We need more developers like him.


Torvalds is BDFL. If you wrote it, it's widely acknowledged to be good, and people want to add code to it, you're entitled to tell people their contributions are unwanted.

If no one other than the 6 people you're working with have ever read the code and nobody wants to add code to it, you need to really spend some time reading the code before you make a judgement call. At that point, it's better to make the code not shit than simply call it shit.

In software, if you can articulate why it's bad, you can fix it. If you can't articulate why it's bad, keep it to yourself.


Great reply, I agree.


Are you kidding? Read this, it's a commit by Linus Torvalds:

https://lkml.org/lkml/2013/7/13/132

We need more developers like Torvalds - not because he's nice, but because he's terrifyingly experienced and completely honest in his feedback. I couldn't think of a better mentor.


Just because Linus can get away with treating people like crap, doesn't mean everyone can get away with treating people like crap.


"If a tree falls in a forest" comes to mind.

If shit code is performant, correctly solves the intended problem, is well-tested and bug-free, is it really shit code?


my first instinct is to laugh this off because its talking about web developers... obviously all of the code is shit because its not hand optimised assembler!

not sure why i hold onto this 20 years out of date mentality..


see a great Dilbert cartoon about a similar subject http://tinyurl.com/av3ennj


You can't polish a turd.


Ultimately, code is like farts. It does stink, but passes with time. Also, stretching the fart analogy a bit more, as developers we always find the output of others (farts and code) to stink more than our own. Some even seem to like their own.


This article is shi*t




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: