Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • 2
    I just love DRY principle :)
    – artjom
    Commented Jun 12, 2012 at 7:38
  • 1
    @tdammers is it good to have just 2 lines of code inside a function?consider if I have this function doFoo() { print (runQuery("Selct a,b,c from XYZ"));}
    – Shirish11
    Commented Jun 12, 2012 at 10:38
  • 1
    No, the call stack does not increase - each call to runAndPrint pushes one stack frame when you call it, and then pops it back when the function exits. If you call it three times, it will do three push/pop pairs, but the stack never grows by more than one frame at a time. You should only really worry about call stack depth with recursive functions.
    – tdammers
    Commented Jun 12, 2012 at 19:55
  • 3
    And functions with just two lines of code are perfectly fine: if two lines make a logical unit, then two lines it is. I have written plenty of one-liner functions, just to keep some bit of information isolated and in one place.
    – tdammers
    Commented Jun 12, 2012 at 19:56
  • 1
    @JamesAnderson: It's a somewhat contrived example, but it serves to illustrate a point. It's not about how many lines of code you have. It's how many times you state the same fact. That's what DRY is about, as well as the Single Source Of Truth principle, the Thou Shalt Not Copy-Paste rule, etc.
    – tdammers
    Commented Jun 13, 2012 at 19:27