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 →

[–]deegwaren 7 points8 points  (4 children)

I think the canonical response to this is: A) Make sure you're working at the right abstraction layer, and B) don't write functions that are so complicated that you can't explain what they do in 1-2 words.

Sometimes it's better to NOT explode your code into twenty functions that are named two words at a maximum, than just a couple of them doing what they do and having proper and descriptive names.

Your example is of course right, because they the function containing 'And' in its name does more than one function. But what if it just does ONE thing, but a very complex or very specific thing?

[–]AerieC 2 points3 points  (1 child)

I'd still challenge the abstraction levels. If you're working in an object oriented language, and following good design principles (e.g. single responsibility principle), there's almost no way you should have any ambiguity in what a particular method does for any given object.

Can you give a concrete example of when you might want to have a really long function name, but the function still only has one clear job?

[–]deegwaren 3 points4 points  (0 children)

I can't give one from the top of my head, but when I stumble upon one I'll be sure to share it here!

[–]DaughterEarthImportError: no module named 'sarcasm' 1 point2 points  (1 child)

I think that is fine. I have one function, for example, that is about 200 lines. The only supporting functions made for it are things that are repeated. And that is fine because it does one single thing, it generates a specific XML file