Ask HN: Does anyone distinguish methods names for indirect/direct objects?
There is much advice on naming and many conventions proposed in various languages. However, I am yet to come across any suggestions regarding naming for indirect/direct objects.
It occurs to me that methods of an object should be named in such a way that the method is the verb, and the object is the direct object. The parameters of course would be the indirect objects.
This seems natural to me but I rarely see it. Presumably because it is easier to ignore this restriction. I was curious as to whether there are any guidelines on this, or if anyone else has had any experience of utilising other less common naming conventions.
7 comments
[ 2.9 ms ] story [ 30.3 ms ] threadnewEmployee.adoptBy(department)
newEmployee.join(department)
?
Corresponding OO code:
And objects (in the grammatical sense) with preposition could be understood to correspond to keyword arguments: Now if we introduced cases to a programming language...PS. Cases, I hadn't even considered that. My feeling is that methods should be imperatives. They tend to be anyway. I haven't given much thought though.
On the other hand, a case is a form of the noun-phrase which can be constructed without looking at the predicate. I see a similarity to the address operator in C:
foo(bla, &blub)
means that bla is passed in value-case, whereas blub is passed in reference-case.