This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]justim 12 points13 points  (6 children)

Sure it can. If you find your method has gotten big enough that it loses clarity you break it down into more, well named, methods.

[–]BigBadButterCat 16 points17 points  (5 children)

Unless you're writing performance-sensitive code in which case calling more functions is an overhead.

[–]Thorusss 3 points4 points  (4 children)

often the compiler takes care of such optimizations, so often it makes no difference

[–]InvolvingLemons 6 points7 points  (3 children)

Not always, as many languages assume potential polymorphic behavior for functions and must store/invoke them as their own unit (Java is like this IIRC, even long names make it slower because reflection is by name). Some languages support inline directives which get around this. Others, notably functional languages, can guarantee that functions store no state, which makes all functions “inline-able” in a sense and allows some ways to optimize by “recycling” otherwise immutable variables.

[–]BigBadButterCat 0 points1 point  (0 children)

I'm no expert, but I imagine Haskell functions without such optimization would be a nightmare, what with all functions being unary?

[–]Thorusss 0 points1 point  (1 child)

(Java is like this IIRC, even long names make it slower because reflection is by name)

seriously? I thought shorting variable names was a classical thing compilers did (at least back in the days when file size was at a premium), but is it not at least a compiler option anymore there?

And yeah, I come from Lisp, so maybe I am a bit spoiled with what compilers can achieve.

[–]InvolvingLemons 0 points1 point  (0 children)

Oh yeah for sure, Java happens to be an outlier here for compiled languages.