Class names: Context by Suffix vs Context by Namespace

I’m working on a project at the moment that uses Zend/ Laminas having come from more of a Symfony background. For the most part I really like it but one thing that has stuck out massively for me is that the team don’t like using suffixes on class names at all where context can be derived from the namespace. So rather than having a class called AppRepositoryBlogPostRepository you name your class AppRepositoryBlogPost. In practice they are almost always aliasing their class imports. The result is that during a single pull request you might be committing 6 files all with exactly the same name. I took a look around the Zend/Laminas code base and this does seem to be the convention in that community. I don’t like it because:

  • Code doesn’t make any sense without aliasing
  • Cannot use quick import feature in the IDE without hitting issues with classes having the same name and having to create aliases
  • Heavy reliance on aliases to make the code make sense opens up the risk of inconsistencies in language
  • I have already got stuck multiple times on issues that turned out to be that I had imported the wrong class from clicking the wrong shortcut in the IDE (eg. was injecting FactoryBlogPost instead of RepositoryBlogPost etc.)
  • Pull requests are harder to read because lots of the files have the same name

I can see the reason for this, I’ve lamented the naming of classes like AbstractIterableCategorisedEntityRepositoryAdapterFactory but surely the answer is just to apply a little common sense? Does anyone prefer to name classes this way? What am I missing?

submitted by /u/WArslett
[link] [comments]