Slashdot is powered by your submissions, so send in your scoop


Forgot your password?
Programming Software

Dr. Dobb's Calls BS On Obsession With Simple Code 381

theodp writes "Over at Dr. Dobb's, Editor-in-Chief Andrew Binstock has a nice rant on The Misplaced Obsession with Simplicity. 'Any idiot can write complex code,' goes the old maxim, 'the true art is writing simple code.' Right, Andrew? Wrong (mostly). Binstock explains, 'It's not true that any idiot can write complex code. Complex code is difficult, often very difficult, to write. It's entirely true that it's more difficult to maintain, too. But that's the nature of complexity. Some things are intensely difficult to express in code and they require complexity, simply because they're not inherently simple.' After citing the complex-but-necessarily-so code of Al Aho and sometimes-misguided reverence for cyclomatic complexity limits to help make his point, Binstock concludes, 'My view of simplicity is unemotional and free of idolatry because I define it with respect to complexity, rather than the other way around: Simplicity is the quality of code that is no more complex than required to express the underlying complexity. In this way, simple code can be intensely complex. There is no inherent good/bad dichotomy.'"
This discussion has been archived. No new comments can be posted.

Dr. Dobb's Calls BS On Obsession With Simple Code

Comments Filter:
  • To quote Einstein (Score:5, Insightful)

    by BenSchuarmer ( 922752 ) on Thursday June 27, 2013 @01:05PM (#44123497)
    Everything should be made as simple as possible, but not simpler.
    • by invid ( 163714 )
      Everything should be as complicated as it needs to be, and no more complex.
      • by lgw ( 121541 ) on Thursday June 27, 2013 @01:24PM (#44123773) Journal

        Arguing against stupid "complexity metrics" is fair. A programmers job is to game the system. Give him a metric other than making the customer happy, and it will not end well.

        But I've seen far too much code that was simply far more complex than it needed to be. Stop tripling the size of your code for use-cases that no one has asked for, people!

        If you can make assumptions that significantly simplify your code, and those assumptions fit within the actual, stated requirements of the work (ignoring requirements that exist only in your head), for goodness sake make those assumptions.

        • by internerdj ( 1319281 ) on Thursday June 27, 2013 @01:36PM (#44123925)
          Not all customers are smart enough to know to ask for everything. Even a smart customer may not be able to give you a real answer for what happens in X cornercase. Presumably you (or someone like you) are being paid to hash out all the hidden requirements and assumptions to achieve the customer-stated requirements.
          • by Zalbik ( 308903 ) on Thursday June 27, 2013 @02:06PM (#44124293)

            Presumably you (or someone like you) are being paid to hash out all the hidden requirements and assumptions to achieve the customer-stated requirements.

            Yes, but this should be done prior to code writing.

            Far too often I've seen extremely complicated code designed to handle "what-if" scenarios that never happen.

            Developer: "I wrote that configuration module in case they ever need to change the parameters of X"

            Me: "Did you ask if X would ever need to be reconfigured?"

            Developer: "Of course! And the client said that sure, if I could make it configurable, go ahead and do so"

            Me: "And did you ask how likely it would be that X would need reconfiguration? Or under what circumstances X would need to be reconfigured? Or what types of 'reconfigurations' they think they would need? We're looking at 2 man-months of code, plus testing, plus implementation time here....was any kind of cost-benefit analysis done to see whether it was worth it to write this?"

            Developer: [blank stare]

            • by lgw ( 121541 )

              Very well put. So much needless code comes from trying to support actions that the customer will never actually care about.

              • by Belial6 ( 794905 )
                That is only if you look at the problem from strictly a developer's point of view. In many environments, new applications mean greater accountability, and often increased workload generated by the software preventing work tasks from getting 'lost'. From a manager's point of view, the greater accountability is good thing, and the employees should have been doing all of the tasks all along. After all, it is hard to argue with a manager that "If we use this software, we will have to do our jobs completely."
            • by ZahrGnosis ( 66741 ) on Thursday June 27, 2013 @02:45PM (#44124725) Homepage

              I think you're confusing feature-creep with a comment that was meant to be about edge-scenarios. Allowing someone to configure parameters that were never spec'ed to be configured is feature-creep (gold plating, extra coding, call it what you will), and I agree should be avoided and adds unnecessary (or not obviously necessary) "complexity".

              Handling an edge criteria that was implied but not explicit in a specification is what is typically meant of "corner case", and is not the same thing you described. Recognizing that the customer asked for something logically impossible (they want two data sets to reconcile, but they are at unexpectedly incompatible cardinalities), or something that, upon investigation while building an app, wasn't precise enough (they asked for this to be their standard green, but their standard list only includes red and blue).

              It's nearly impossible to specify all of those prior to coding, which is why the typical "waterfall" development techniques have fallen out of vogue. You're always going to learn things while coding, and this is one of the main contributors towards apparently unnecessary complexity. If I design version 1 of a program perfectly, and customers have new requirements for version 2, it's unlikely that the "simplest" implementation of version 1 will be the one that is most conducive to an upgrade. You end up with a choice between refactoring completely or sacrificing some efficiency and simplicity to graft the new features onto an otherwise good version 1.

              I think Dr. Dobbs is nitpicking, though. There are definitely many ways to address, measure, or understand simplicity, and I agree that it should not be THE goal in and of itself. But the idea of making code easy to read, easy to understand both in the micro and macro sense, and just generally "simpler", has many merits.

            • Re: (Score:3, Funny)

              by Anonymous Coward

              I've seen extremely complicated code designed to handle "what-if" scenarios that never happen.

              As is usually the case, XKCD covered this [] well. The image title is particularly good:

              I find that when someone's taking time to do something right in the present, they're a perfectionist with no ability to prioritize, whereas when someone took time to do something right in the past, they're a master artisan of great foresight.

            • by Ash-Fox ( 726320 )

              Yes, but this should be done prior to code writing.

              Considering how often clients will sign off on something and then double back on what they signed off on, and ask for changes and sign off on those new changes which then invalidate some requirements that were previously implemented but because they were signed off, it's a requirement... I think expecting these situations to be completely resolved beforehand is wishful thinking.

              Me: "Did you ask if X would ever need to be reconfigured?"

              Developer: "Of course!

        • Re: (Score:3, Interesting)

          by djdanlib ( 732853 )

          Stop tripling the size of your code for use-cases that no one has asked for, people!

          Yeah, just let it throw a bugcheck when something happens outside of the design parameters and let the user sort it out with your support department. /sarcasm

          Security risks. Data corruption. Performance edge cases. Productivity loss. Unexpected bluescreens. Actual damage to physical hardware controlled by the software. You know all that bad stuff could have been easily prevented if the programmer anticipated those situations, and the people hiring that programmer probably expected the software to be well-ma

          • Re:To quote Einstein (Score:5, Interesting)

            by lgw ( 121541 ) on Thursday June 27, 2013 @02:21PM (#44124465) Journal

            Those things aren't part of the formal requirements in your world?

            • Re:To quote Einstein (Score:5, Interesting)

              by gstoddart ( 321705 ) on Thursday June 27, 2013 @02:32PM (#44124567) Homepage

              Those things aren't part of the formal requirements in your world?

              I've never seen formal requirements which detail every edge case I need to account for.

              There's an assumption we'll be writing robust code, and as it gets created we build in as much error checking and handling as we can think of, and over time you usually end up adding more.

              If coders had to be told in writing every error condition to check for, there wouldn't be any -- because the client wouldn't know (especially true when you have to create a library to do some of the work), and the developers would just say "not in the spec".

              Come to think of it, I've never seen formal requirements for much more than the really high-level systems stuff. From my perspective, a system which has been fully designed and spec'd out before anybody writes code is a myth.

              • I work on highly-available systems (telecom equipment, core network stuff). Even there, some parts of the system can be less robust and some parts need to be as robust as possible.

                The design for a given component needs to take into account how robust that component needs to be. Do you check EVERY POSSIBLE error condition and figure out intelligent ways to handle them (can be quite difficult and very time-consuming) or can you just panic the system if you detect something has gone wrong and you don't know

        • by gstoddart ( 321705 ) on Thursday June 27, 2013 @02:17PM (#44124415) Homepage

          Stop tripling the size of your code for use-cases that no one has asked for, people!

          So, we should stop doing any bounds and input checking if the client didn't ask for it explicitly?

          Is this part of Agile Programming or something? Write the most incomplete code you can get away with because it isn't in the spec?

          I once had a co-worker bitch and complain I was checking the result of every single function, including strprintf() -- he said it was unnecessary. Not long thereafter, we spent some time tracking down a problem which turned out to be in his code, because he wasn't checking anything (again, because it was 'unnecessary').

          If you write shitty, incomplete code up front, it's much harder to make it less shitty and incomplete later. If I know from experience there's a bunch of things that can go wrong, I'm going to try to account for as many of those things as possible when I write it.

          Those use-cases nobody asked for can sometimes be the difference between code which collapses at the first unusual inputs, and stuff which can at least tell you WTF went wrong. Because sometimes, even the simplest of things can fail.

          • Is this part of Agile Programming or something? Write the most incomplete code you can get away with because it isn't in the spec?

            Yes. It's part of TDD, where the coder is supposed to write the absolutely smallest set of code that passes said test.

        • I find that this is most often the case when people will use "Enterprise Design Patterns" for small projects that do not inherently need them. Much of the time this makes things more complex with no real benefit.
    • by girlintraining ( 1395911 ) on Thursday June 27, 2013 @01:19PM (#44123701)

      That quote is attributed to Einstein, but you should know by now a great many quotes are attributed to him, but very few can be proven to have been from him. -_-

      "There's no such thing as a correct quote citation on the internet." -- Abraham Lincoln

    • Or as they say with requirements. The best requirement is usually the shortest requirement that is complete and unambiguous (plus a few other things depending on the software level).
    • Indeed. Simplicity is but an ingredient to the main dish that is is not the sole ingredient; too much, and the flavor is ruined; too little, and the inner ideal is never glimpsed.

    • “Perfection is achieved not when there is nothing left to add, but when there is nothing left to take away” – Antoine de Saint-Exupery
  • Meh (Score:5, Insightful)

    by Anrego ( 830717 ) * on Thursday June 27, 2013 @01:07PM (#44123541)

    Interesting article, but this seems an issue of a very pedantic interpretation of a common idiom.

    When I (or I suspect most) whine about pointlessly complex code, it's just that. Code that is more complex than is reasonable for the problem. No one expects a simple solution for a challanging problem. It's an overly complex solution to a simple problem which we complain about...

    • The is a good reason I need a separate class defined to output each character in the string "Hello World!"

    • Re: (Score:2, Insightful)

      by Anonymous Coward

      I think Dr. Dobb's stopped being relevant oh like 10 years ago. Its like a total kids magazine now, nothing like it was years ago. Most articles in it are unreadable.

    • My thought exactly. Binstock is certainly correct, but the tone of the article is as if there is a world-wide problem that needs to be addressed. I don't think so. I think he feels the need to qualify a programmatically philosophical point that everyone implicately understands already. For example, I've never had a manager look at my project and say "It has to be simpler!", meanwhile I'm always questioning my code and looking for stuff I can remove. When I get to a point where I simply can't, I move on.
      • For example, I've never had a manager look at my project and say "It has to be simpler!",

        He probably did have a manager (or some coworkers) who did say that, which is why he was motivated enough to write a rant on the topic.

    • by rwv ( 1636355 )

      It wasn't until the mention of Cyclomatic Complexity that I understood what the summary was saying. It boils down to writing individual functions logically with as many if/else/while/for/switch branches as you need. Oftentimes, breaking up code into multiple functions to satisfy some arbitrary Cyclomatic "Complexity" coding standard makes it MORE COMPLEX. On the other hand, Cyclomatic Complexity can be used to find spaghetti code that would make a good project for refactoring. At the end of the day... h

  • The way I heard it was "Everything should be made as simple as possible, but no simpler." However I have since learned that me be a paraphrase of the actual quote, "It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience."
    • Over on the c2 wiki [] there's a quote somewhere, "Judging things solely on the basis of simplicity is an overly simplistic approach." That seems to be what this guy is getting at, although his thinking isn't very clear.
    • Quote Invesigator (where you likely got your material from) makes a pretty good case [] that the modern quote actually originated from composer Roger Sessions in 1950, and may have been inspired by something Einstein had to say specifically about theories.

  • In databases things get normalised down to their most basic elements, which is neccessary and good. In coding, everything might individually be simple, but the whole might be horrendously complex. Good documentation makes almost anything simple though, and by that I mean docs written intentionally to explain the overall codebase rather than disconnected sections.

  • Your code shouldn't be more complex than it really needs to be. But isn't that the way we thought about simple code all the time?
  • by parallel_prankster ( 1455313 ) on Thursday June 27, 2013 @01:12PM (#44123599)
    I have often noticed that complexity is added to code when it grows over time. Typically, a project starts off very well. We have requirements and we use the best possible design with limited future expansion capabilities and come up with simple code that works well. However, over time, things change and we come across situations that the original code cannot handle. But instead of writing from scratch, we hack it and that is how complexity and subsequently bugs get added. In my experience, the base infrastructure code for any system always looks simplistic and beautiful. The ugly part is often how it has been used over the years.
    • by ADRA ( 37398 )

      Rewrites vs refactoring are all to common and this pattern is surely nothing new. One way is to design for change up front. This can be accomplished in many ways, but can be vastly simplified by cgood coupling/cohesion, as well as avoiding any kind of fixed constants. It may make initial implementation slower, but it'd leave the system in a better state for change in the future. Of course this flexability can itself lead to greater complexity, so buyer beware.

      Ultimately, we all code in different ways at vas

      • Right, but then if you keep writing code for future expansion, you are over designing. A lot of the times, it is really hard to predict what direction this project is going to take. You also end up with pieces of code that are being maintained for future really. You do bring out another interesting point. Code that looks simple to me may not look simple to others.
        • by Tablizer ( 95088 )

          In finance there's the concept of Future Value in which the cost of the present is weighed more heavily than future costs. This also applies more or less to software: we know the here-and-now needs but the future is too murky in terms of product direction or even its very existence.

          One can learn a lot about design choices by studying finance theory because it trains you to better weigh probabilistic options and related costs in your mind. (Game theory has some similarities also.)

          I look for "bargain future-p

  • Writing code Simple or Complex really depends on the Developer and the mindset of the developer at the time.

    Sometimes the Simple Code actually makes it too hard to manage. Say you are given specs and you find it fits nicely in a mathematical function. So you create that function and it works fine, until a new change happens then you function is just wrong and you need to redo it. However if you make your code a bit more complicated, that change might be just a simple if statements, and you are all set ag

  • by Anonymous Coward

    You know what's bad?
    An object with a single 2200 line method that takes 70 parameters

    You know what's also bad?
    300 tightly coupled classes that have no individual use.

    Striking the balance is what is really important and there's no one size fits all metric for that beyond peer review.

    I find myself cringing every time someone comes in and makes a grand sweeping statement about simplicity or density or whatever else because it ignores problems by carpet bombing a philosophy.

    Cyclomatic complexity doesn't mean mu

  • Premise is wrong. (Score:2, Insightful)

    by Anonymous Coward

    Any idiot can write complex code.

    Bzzt, wrong. It's:

    Any idiot can write complicated code.

  • by girlintraining ( 1395911 ) on Thursday June 27, 2013 @01:17PM (#44123671)

    "Simplicity is the ultimate sophistication."
    -- Leonardo da Vinci

    "Plurality should not be assumed without necessity."
    -- William of Ockham, often referred to as Ockham's Razor -- the simplest explanation is usually the right one.

    "Everything should be made as simple as possible, but not simpler."
    -- Attributed to Einstein

    "If you can't explain it to a six year old, you don't understand it yourself."
    -- Albert Einstein (attributed)

    "Truth is ever to be found in the simplicity, and not in the multiplicity and confusion of things." -- Issac Newton

    "Beauty of style and harmony and grace and good rhythm depend on simplicity."
    -- Plato

    "The greatest ideas are the simplest."
    -- William Golding, Lord of the Flies

    "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage to move in the opposite direction."
    -- E.F. Schumacher

    "Those guys are all wrong."
    -- Andrew Binstock, Editor in Chief, Dr. Dobbs

    Choose well, reader...

    • by chthon ( 580889 )

      In anything at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away.

      Antoine de Saint-Exupery (1900 - 1944)

    • "If you can't explain it to a six year old, you don't understand it yourself."
      -- Albert Einstein (attributed)

      Having recently spent time with a friend and her six-year-old daughter, I can honestly, accurately, say that is not true. The kid is really, really smart - for a six-year-old - but, like *all* six-year-old humans, her brain simply isn't developed enough to grasp many - many - concepts. This also applies, to a lesser extent, to gifted kids (my wife was a Gifted Education teacher). In either case, any parents (or Albert Einsteins) who say otherwise are fooling themselves.

  • by dirtyhippie ( 259852 ) on Thursday June 27, 2013 @01:17PM (#44123673) Homepage

    Frankly, I was a little disappointed in this article. His arguments seems a bit - for lack of a better term: simple.

    Is there anyone out there who is arguing that simple solutions to inherently complex problems exist and are a good thing?

  • PEP20 (Score:4, Interesting)

    by RobbieCrash ( 834439 ) * on Thursday June 27, 2013 @01:19PM (#44123709)

    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.

    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren't special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch.
    Now is better than never.
    Although never is often better than *right* now.
    If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea.

    • If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea.

      Those two always bother me though because when it comes to software development it always seems like there is an exception to every rule. Something like Ukkonen's algorithm [] is both hard to explain and a good idea and that's just the first one to come to mind.

      • The concept seems more difficult than the implementation in that case, which I don't think is the point of those lines.

        I always looked at those lines as don't do result = d.x(y + l.u(v[i[m + 4*t.base(vvv)]])) when you can instead spread it out over a few more lines and make it more readable, less Perly. Either way, you're still going to need the logic figured out, but one is easy to explain and figure out at a glance, while the other is a bunch of back and forth and what the fucks.

  • I didn't see any good examples in his article. The only example he had was a switch statement with 35 cases being simplified by using a table which somehow makes it harder to read than scrolling through a 35 case switch statement. I'm not convinced at all. This guy sounds like he could benefit from reading Clean Code by Robert C. Martin.
    • This guy sounds like he could benefit from reading Clean Code by Robert C. Martin.

      I wouldn't be supprised if "Clean Code" is what prompted the article in the first place.

  • Simplicity is word that gets batted around a lot. When it used to mean "the shortest distance to a solution to the immediate problem", you are often trading immediate simplicity for longer term inflexibility.

    I've found the simplest solutions are those which are well designed, which take into account not just the immediate problem at hand, but reasonable future variations of that problem. The up front investment in thought and design and pay off in a big way down the road when new problems can be solved m

  • I see this a lot with the various "on rails" development schemes, where they sweep a tremendous amount of complexity under the rug so users can quickly develop whatever they want. Only later they discover that something is broken or slow with their project and now fixing it requires a herculean effort because they never really understood what was happening before. It's discouraging and many projects just resign themselves to being broken or start to incorporate ugly workarounds to try to avoid the problem
  • I limit it to 1's and 0's

  • by Teckla ( 630646 ) on Thursday June 27, 2013 @01:27PM (#44123799)

    Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?

    -Brian Kernighan

    • by gweihir ( 88907 )

      "As clever as possible" means "as complicated as possible" here, not as "elegant, simple and clear as possible".

  • by Karmashock ( 2415832 ) on Thursday June 27, 2013 @01:28PM (#44123821)

    When you redefine your opposition's argument and then knock it down with your own argument it is called a strawman. That's what he just did there.

    No one is saying in regards to simplicity that all programs should be two line bits of nothing.

    What people are instead saying is that code should be efficient, tight, and achieve the end goal as simply and directly as possible.

    What we are and have always been talking about is efficiency. It goes back to the first computers that had very limited memory. They required VERY efficient code because they simply didn't have the storage or memory to run anything that took up more space. As a result, code for those machines tended to be very very efficient. It was a requirement.

    When we complain about complexity, we are not complaining that the task of the program is too complex. Rather, we're complaining that the program is badly coded. We are complaining that it is inefficient and disorganized.

    So nice try. Try again.

  • I'm afraid software developers will read this article and use it as a lame excuse to write complex code, because it's easier to write complex code than to write simple code, though it's much, much harder to maintain, enhance, and debug complex code.

    Complex code hides bugs. Complex code is generally less robust and reliable. Complex code usually has more security holes.

    Sure, some things have to be complex. But generally, you should strive for small functions (methods) that do one thing, and do it well, and k

    • by gweihir ( 88907 )

      Indeed. And it applies to architecture and design just as well:

      "There are two ways of constructing a software design: One way is to make it
      so simple that there are obviously no deficiencies, and the other way is to
      make it so complicated that there are no obvious deficiencies. The first
      method is far more difficult." --Tony Hoare

      Writing complex code where simple code would be adequate and much clearer is the hallmark
      of incompetence.

  • by dkleinsc ( 563838 ) on Thursday June 27, 2013 @01:33PM (#44123889) Homepage

    Brooks made a big point in "No Silver Bullet" about the difference between what he called accidental complexity (introduced by the developers) and essential complexity (introduced by the reality of the problem). And the key thing is that the accidental complexity needs to be avoided or fixed with tools, but the essential complexity can't be avoided.

    • by gweihir ( 88907 )

      Exactly. And where you face essential complexity, make sure what you do is as clear and well-structured as possible. "Simple" does not mean "simplistic".

      Funny thing is no real engineers have any problems with that idea or are unaware of it. It is just people in IT that seems to still struggle with fundamental engineering concepts.

  • Dr. Dobb's Journal's motto was once "Running light without overbyte." Looks like this valuable maxim is now beyond their ability.

    Sometimes it's a good choice to use more complex code when it provides a substantial speed increase. Sometimes it's good to slap something together just so it will run. But if there's no substantial advantage to code that isn't simple, simple is best.

  • Black is White. Freedom is slavery. Simplicity is bad. Complexity is good. Binstock is +1 Funny.

  • The article is mildly entertaining (especially for the awk bits), but the ending is plain stupid, i.e. flat and inane beyond belief ;-)

    I don't think that a sane person would explain the apparent improvement of newish cars reliability by the increasing number of built-in programmable gadgets with their millions of code lines. If anything, there is an optimum beyond which the cars will start failing in new and spectacular ways...

  • by sl4shd0rk ( 755837 ) on Thursday June 27, 2013 @01:39PM (#44123959)

    "I had incorporated some sophisticated regular expression pattern-matching.."

    So many simple projects turn the corner of complexity, and never look back, right about at that statement.

  • A lot of what makes code ugly and complex is working around bugs and incomplete features in languages, database, etc. Every time I start a new project I try to start with a good clean framework. If never fails that you hit a point where documented features dont work and after waisting many hours of research you find the ugly hack workarounds. These acheive the end result but make you cringe when you maintain the code.

  • "Readability and change-ability by future maintainers" should be the primary goal. Obtaining that goal doesn't necessarily lead to the most simplest (smallest) code.

    However, it's often a difficult goal to codify (describe precisely) because human psychology and physiology are still half-science-half-art subjects. And, every individual is different and thinks and sees better under different circumstances compared to other individuals.

    It's best to get multiple opinions on different styles to try to find a con

  • KISS is not "make it simple". KISS is "keep it as simple as possible while retaining clarity, but not simpler". It is about not adding complexity _unless_ needed. Anybody competent understands that. This "rant" is entirely redundant and shows a lack of understanding of fundamental engineering principles.

  • I've had to debug systems where code was abstracted so much - to make such simple routines that it was nearly impossible to debug. So, though simplification helps - sometimes writing a long routine maybe preferable.
  • My view of simplicity is unemotional and free of idolatry

    Calling your opponents 'idolaters' is the opposite of unemotional. It is an emotionally charged indication that you don't actually understand the other viewpoint.

  • by guttentag ( 313541 ) on Thursday June 27, 2013 @01:48PM (#44124057) Journal
    In journalism school I had a professor who had personally interviewed the Dalai Lama and as a result he often had a very practical outlook on things. When he gave us our first writing assignment (an obituary for a famous person of our choice who was still alive... I decided William Safire had died of a heart attack upon learning that genetic testing proved Hillary Clinton was not, in fact, a congenital liar), someone immediately asked how many column inches he wanted. He replied with a question: "How long is a man's arm?" People started trying to measure their arms against things or guesstimate the average length of a man's arm, asking if that meant he wanted 30 column inches. Finally he quieted everyone and said, "A man's arm is long enough to get the job done. No more. No less." Likewise, the articles we were to write were to be long enough to get the job done. No important things left out, no filler added in. It was an important lesson in judgment.

    I think the same applies to code. It should be just complex enough to get the job done. No more, no less. Sometimes that means you're going to have complex code, but it shouldn't be any more complex than it needs to be.
  • by Hentes ( 2461350 ) on Thursday June 27, 2013 @01:48PM (#44124071)

    "I had incorporated some sophisticated regular expression pattern-matching technology into AWK Brian Kernighan once took a look at the pattern-matching module that I had written and his only addition was putting a comment, 'Abandon all hope, ye who enter here.' As a consequence, neither Kernighan nor Weinberger would touch that part of the code. I was the one who always had to make the bug fixes to that module"

    Even the source he cites admits that complex code is a bitch to maintain.

  • The summary misses (what I consider) his main point, but here it is:

    This brings me to the point that is truly the heart of the matter: It's not simplicity that matters, but readability. Can the code be understood with the least amount of effort given its inherent complexity? That is the true criterion. How readable, or if you prefer, how maintainable is the code with respect to its complexity?

  • The problem is not that the complex code is "bad", but that there are many stupid developers using pretty much complex libraries and modules, and don't forget the copy/paste methodology, and the result is something that is "somehow" working, and extremely complex and hard to read. Well written and maintained code is always pleasure to read, no matter its complexity or the used libraries. One more thing, give an idiot a hammer, and every problem he face would look to him like a nail.
  • This quote from TFA seems to argue *against* complexity:

    "I had incorporated some sophisticated regular expression pattern-matching technology into AWK Brian Kernighan once took a look at the pattern-matching module that I had written and his only addition was putting a comment, 'Abandon all hope, ye who enter here.' As a consequence, neither Kernighan nor Weinberger would touch that part of the code. I was the one who always had to make the bug fixes to that module" (from Masterminds of Programming, p. 103). Complex problems require complex code.

    So he wrote some code that was so complicated that no one besides himself is able maintain it. That sounds like more of an argument *against* complicated code than for it.

    Note that it's not Al Aho that said "Complex problems require complex code". Is awk still using the same code today, or has it been rewritten to be more maintainable?

  • by dickens ( 31040 ) on Thursday June 27, 2013 @02:17PM (#44124407) Homepage

    Even very complex problems can be made to look simple at various levels of abstraction. Hiding complexity inside objects that represent real-world objects is a good way to make the code that uses those objects simpler.

    In development, plan to do at least one major refactoring after the project is feature-complete to move complicatons in and out of abstractions, add new abstractions or collapse old old ones as needed to make things "feel good".

  • by Zaphod The 42nd ( 1205578 ) on Thursday June 27, 2013 @05:33PM (#44126833)
    There already exists a word for "no more complex than required", and that term is ELEGANT.

    Its been around since the beginning of programming. Get with the program. This is a non-story.

To write good code is a worthy challenge, and a source of civilized delight. -- stolen and paraphrased from William Safire