Loading ...
Sorry, an error occurred while loading the content.

Re: [hackers-il] DRY vs. KISS

Expand Messages
  • Omer Zak
    On Thu, 2009-11-12 at 19:24 +0200, Shlomi Fish wrote: [... an example was snipped ...] ... I think that more important than DRY, KISS or whatever is the
    Message 1 of 4 , Nov 12, 2009
    • 0 Attachment
      On Thu, 2009-11-12 at 19:24 +0200, Shlomi Fish wrote:
      [... an example was snipped ...]
      > So the question to you is: do you think DRY and KISS can sometimes contradict
      > one another? If so, which one is more important, or that you should just use
      > your reason. I should also note that I've been feeling that less expressive
      > languages sometimes result in being unable to avoid duplicate code or
      > undesirable "patterns" in the code (in accordance to DRY). Possibly the only
      > family of languages that completely avoids duplicate code is Lisp.

      I think that more important than DRY, KISS or whatever is the principle
      of not overloading the memory of whomever is going to read the software.

      You overload his memory if he has to look up elsewhere for definitions
      of variables, functions, closures or whatever constructs you are using.
      According to this criteria, LISP can be very bad.

      If you define another function in order to avoid code repetition at 3
      places in your project, then whomever is reading the code needs to look
      up the new function definition. If it's the only function in the
      statement - OK. But if the statement already invokes 7 functions to
      compute values, return a function pointer to be invoked, and the address
      of the variable to receive the result, then adding 8th function would
      already overflow the reader's short term memory.

      And sometimes when you need to modify all copies of an expression in
      your project, egrep can do good enough work - so no need to make them a
      function to enable code modification at one place. In a way it would be
      "virtual DRY" - the entity which you don't repeat is the egrep pattern.

      Those are vague ideas. I hope that someone would continue the
      conversation and can distill those ideas and find the hidden principle -
      it surely would be a gem!
      --- Omer
      --
      Eli Marmor's Law: netiquette forbids people from replying "I agree with
      you" to messages in mailing lists, skewing discussions in favor of the
      troublemaker type of dissenters.
      My own blog is at http://www.zak.co.il/tddpirate/

      My opinions, as expressed in this E-mail message, are mine alone.
      They do not represent the official policy of any organization with which
      I may be affiliated in any way.
      WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html
    • Shlomi Fish
      ... Interesting. Of course, part of the reason why we have functions is so we can encapsulate a potentially complex function in an easy to digest thing that we
      Message 2 of 4 , Nov 13, 2009
      • 0 Attachment
        On Thursday 12 Nov 2009 20:41:09 Omer Zak wrote:
        > On Thu, 2009-11-12 at 19:24 +0200, Shlomi Fish wrote:
        > [... an example was snipped ...]
        >
        > > So the question to you is: do you think DRY and KISS can sometimes
        > > contradict one another? If so, which one is more important, or that you
        > > should just use your reason. I should also note that I've been feeling
        > > that less expressive languages sometimes result in being unable to avoid
        > > duplicate code or undesirable "patterns" in the code (in accordance to
        > > DRY). Possibly the only family of languages that completely avoids
        > > duplicate code is Lisp.
        >
        > I think that more important than DRY, KISS or whatever is the principle
        > of not overloading the memory of whomever is going to read the software.
        >
        > You overload his memory if he has to look up elsewhere for definitions
        > of variables, functions, closures or whatever constructs you are using.
        > According to this criteria, LISP can be very bad.

        Interesting. Of course, part of the reason why we have functions is so we can
        encapsulate a potentially complex function in an easy to digest thing that we
        know what it does.

        Of course, this may result in a http://en.wikipedia.org/wiki/Leaky_abstraction
        which will require us to understand what the function does and how it does it
        before we can proceed, which will also overload the memory during reading the
        code.

        >
        > If you define another function in order to avoid code repetition at 3
        > places in your project, then whomever is reading the code needs to look
        > up the new function definition. If it's the only function in the
        > statement - OK. But if the statement already invokes 7 functions to
        > compute values, return a function pointer to be invoked, and the address
        > of the variable to receive the result, then adding 8th function would
        > already overflow the reader's short term memory.

        Well, in his book "Refactoring", Martin Fowler advocates very short methods of
        very few statements with simple expressions each, while extracting the more
        complex evaluations to helper methods, and many people seem to agree with him
        (including me to a large extent[Practice]). Of course, this in turn causes
        understanding the code or tracing a bug be more difficult because you have to
        delve several methods deep (which in turn causes a memory overload).

        {{{{{{
        [Practice] - while I agree with it, but often my code, including my open-
        source code does not exhibit this. It's just that I'm too anxious to write
        functional code, that I don't make sure it's properly factored. Normally, I
        only give an external API and do not support any internal APIs, including not
        class-inheriting API, so it's not that critical.
        }}}}}}

        > And sometimes when you need to modify all copies of an expression in
        > your project, egrep can do good enough work - so no need to make them a
        > function to enable code modification at one place. In a way it would be
        > "virtual DRY" - the entity which you don't repeat is the egrep pattern.

        What if someone who is not intimately familiar with the code changes one place
        and not all other places? What if you forget to change them? That's the danger
        of duplicate code.

        Some people may argue that syntactical patterns in the language are not really
        duplicate code, but Lisp purists may disagree.

        >
        > Those are vague ideas. I hope that someone would continue the
        > conversation and can distill those ideas and find the hidden principle -
        > it surely would be a gem!
        > --- Omer
        >

        Regards,

        Shlomi Fish

        --
        -----------------------------------------------------------------
        Shlomi Fish http://www.shlomifish.org/
        My Aphorisms - http://www.shlomifish.org/humour.html

        Chuck Norris read the entire English Wikipedia in 24 hours. Twice.
      • Shlomi Fish
        ... Now that I think of it, it s possible that not overloading memory is one aspect of KISS ( Keep is Simple and Stupid ). But I m not sure of that. Regards,
        Message 3 of 4 , Dec 20, 2009
        • 0 Attachment
          On Thursday 12 Nov 2009 20:41:09 Omer Zak wrote:
          > On Thu, 2009-11-12 at 19:24 +0200, Shlomi Fish wrote:
          > [... an example was snipped ...]
          >
          > > So the question to you is: do you think DRY and KISS can sometimes
          > > contradict one another? If so, which one is more important, or that you
          > > should just use your reason. I should also note that I've been feeling
          > > that less expressive languages sometimes result in being unable to avoid
          > > duplicate code or undesirable "patterns" in the code (in accordance to
          > > DRY). Possibly the only family of languages that completely avoids
          > > duplicate code is Lisp.
          >
          > I think that more important than DRY, KISS or whatever is the principle
          > of not overloading the memory of whomever is going to read the software.
          >
          > You overload his memory if he has to look up elsewhere for definitions
          > of variables, functions, closures or whatever constructs you are using.
          > According to this criteria, LISP can be very bad.
          >

          Now that I think of it, it's possible that not overloading memory is one
          aspect of KISS ("Keep is Simple and Stupid"). But I'm not sure of that.

          Regards,

          Shlomi Fish

          --
          -----------------------------------------------------------------
          Shlomi Fish http://www.shlomifish.org/
          What does "Zionism" mean? - http://shlom.in/def-zionism

          Bzr is slower than Subversion in combination with Sourceforge.
          ( By: http://dazjorz.com/ )
        Your message has been successfully submitted and would be delivered to recipients shortly.