The problem with questions like these is in regards to the fact that you're talking about coding style and NOT about code itself; there's nothing inherently wrong with this type of question (I've had debates with colleagues on 'proper' style for years), but it gets into the realm of 'how should I name my functions to best clarify to the user what they do' .. THAT is completely up to you the programmer. It's completely possible to have an object (in the OO realm) that makes since to have both a Print
and PrintDocument
(maybe the Print
function handles some simple stuff for you that PrintDocument
does not, or maybe Print
prints something to the screen instead of printer). The point is that naming guidelines are just that, guidelines.
Where these kind of naming conventions really make a difference is in the procedural world (non-OO) and more specifically the C
language, which, as one user already pointed out, does not support function overloads (i.e. having 2 functions named the same but with different parameters, ex: void Print(void)
and void Print(int)
would fail in C
). In this case where the language itself inhibits you from doing such things it make since to follow some sort of convention. Also, when you're dealing with object oriented programming, you're usually talking about objects with state, at which point functions usually become verbs to the object (i.e. I have an Image
object, I would like to print it, so I call img.Print()
which acts on the Image
object I have .. OO and non-OO aren't that different because the same could be said for PrintImage(Image)
), style guidelines are more about HOW the code you're writing is conveyed to the user and that's usually part of the 'design' process in the SDLC.
I've been in both the Linux/Unix kernels, embedded and cloud environments, Java and .NET and I have NEVER seen a single style that makes since. It ALWAYS depends on the scope of project, the team, the language, the intent and IMHO if the developer had enough sleep the night before :) And while you can't always rely on documentation, I do find that if it's available it can give a better understanding of what a function is supposed to do than the function name itself (kernel code and API names can be VERY confusing if you're only going off of the names).
I hope that can help
Print()
that accept two unrelated types of arguments. stackoverflow.com/questions/479207/function-overloading-in-c – rwong Dec 19 '13 at 18:08