Inspection for Law of demeter
What do you think: Would such an inspection be useful?
Bas, do you think it's feasible?
The only references I found so far is an old issue in Jira, that's somewhat
related
http://www.jetbrains.net/jira/browse/IDEABKL-760
plus some remarks from Dave that he thought of implementing this for the
metrics plugin.
(If you really haven't heard of it yet, get a copy of 'Pragmatic Programmer',
there's no excuse not to read this book.)
Please sign in to leave a comment.
Just some history, Law of Demeter was considered for inclusion in InspectionGadgets, but was deferred for a variety of reasons
1)It's somewhat controversial. Google for the full description, but the short beef is that following it too closely leads to code with too much delegation and increased diffusion of responsibility and lessened code-time navigability.
2)It's a real pain to implement, requiring some really quite tricky dataflow calculations.
3)I'm not convinced that an inspection wouldn't result in too many false positives. That is to say, patterns of code which are generally thought to be "good", but strictly violate Demeter.
4)No competing product I found implements it.
That said, if anyone wants to take a run at implementing it, I would argue that it's certainly worthy of inclusion.
--Dave Griffith
I would definitely be willing to implement it and see if it's useful.
Initially without a quick fix probably, but to make this inspection
really useful a quick fix or probably even a refactoring is needed. It
should also have some option to ignore library calls, I think.
Could you submit a request for the inspection?
Bas
Stephen Kelvin wrote:
Thanks for the quick reply.
See http://www.jetbrains.net/jira/browse/IDEA-4921
The option to ignore library calls is a little tricky: It should probably
ignore calls to strangers iff the receiver object has been obtained from
a library call, rather than ignore calls to objects that are in a library.
Bas Leijdekkers wrote:
Thanks for the info.
Yes, it's controversial and I am not absolutely convinced myself.
An inspection would help me a lot to evaluate the usefullness, though.
If no competing product implements it, isn't that in fact a reason to
include it? (At least now that InspectionGadgets outshines competing
products on all basic and not-so-basic inspections.)
I can imagine the pain to implement it and consider myself lucky
that someone else will have a try at it ;)
Dave Griffith wrote:
Stephen Kelvin wrote:
Let's also implement inspection for "Class starts with uppercase letter" because
no other product includes it :)
Keith Lea wrote:
>> If no competing product implements it, isn't that in fact a reason to
>> include it? (At least now that InspectionGadgets outshines competing
>> products on all basic and not-so-basic inspections.)
Already there, see the "Class naming convention" inspection :)
Bas