Cohesion and Coupling in Large Projects(blog.architexa.com) |
Cohesion and Coupling in Large Projects(blog.architexa.com) |
Well, you know, duh.
A reason there are such problems with code is not that developers don't quite know what they should be doing (though that is sometimes the case), but that many things that are easy to state in words are far from easy to do in practice.
What, exactly, is "intuitive"? Intuitive to whom? How exactly do you decide when things are closely related? By what measure?
OK, but that's fraught with peril. You first have to know what the method or class is supposed to do now and in the future, and code has a tendency to mutate out from under you. The trouble is that the change can be slow and subtle, and then one day it strikes you (or, more likely, another developer) that the class has become kind of gnarly. The absence of fairly clear-cut guidelines means you're winging it all along.
"Also I am sure you must have some idea of how you can group code modules your project."
Things go together until the don't. Over time the behavior some code creeps over to some new realm, and one day you find the code a bit tangled. I'm wondering to what extent there are, or can be, applicable rules to alert you before your gut kicks in.
"Moreover looking at types of cohesion can give a decent idea of what elements can be grouped together."
True, understanding the different ways things can be associated can help. But there's quite a bit of subjectivity. Maybe that's unavoidable, but the article (and perhaps most similar articles) don't go far enough in discussion concrete, repeatable practices to deal with this, or discussing why this may not even be possible.
It is very much like design articles that advocate being "simple" without offering a compelling definition of simple or how you actually achieve it.
But that's the hard part.
(Also, I have to wonder to what extent this is more a problem with OOP and less with FP. )
Personally I haven't come across a set of guidelines having more in-depth solution than what I have tried to mentioned here which works in all cases. It is a question quite dependent on the type of project you are working on. I think the best person who can properly direct you is the Architect or somebody with experience who knows the project thoroughly.
"There are only two hard problems in Computer Science:
cache invalidation and naming things."
-- Phil Karlton
Coupling and coherence are essentially about naming things, about identifying the core nature of something.