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.

6
  • 5
    +1 for the observations that any modern compiler is going to optimize out the intermediate variables, so there's no performance penalty, and that the multiline version is easier to debug. Commented Jul 4, 2013 at 16:02
  • @dodgethesteamroller: Each of those claims seems intuitively obvious, but, don't they sort of contradict each other? I mean, with Java (unlike, say, C++) there aren't usually separate "debug builds" and "release builds"; so if two programs differ in their debuggability, that must be because they were compiled differently. No? Commented Jul 4, 2013 at 17:22
  • 1
    @ruakh: No, because debuggers typically allow you to set a breakpoint on a particular line, but with no finer-grained control than that. In Juann's example, if you are confident that MethodThree is working, but want to step into MethodTwo and examine the code that produces result2, you can set a breakpoint on the second line, run the program, and end up precisely at the problem area. With the single-line version you could still set a breakpoint at that line, but you'd then have to step through the call to MethodThree to end up at the same place—a little more clumsy. Commented Jul 4, 2013 at 18:16
  • for debugging purposes, couldn't you use assertions inside each method to ensure the validity of the method's logic? (c.f. examining the variable that results, and then having to go back and examine the logic) Commented Jul 4, 2013 at 20:52
  • Sure, but if you write an assertion, you have yet another thing that may or may not have a bug. Commented Jul 5, 2013 at 6:59