What are the Slack Archives?
Itβs a history of our time together in the Slack Community! Thereβs a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.
Because this space is not active, you wonβt be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..
Hi all, just a dumb question: why do we prefix the module name to all the classnames in Spryker ? Do
Hi all,
just a dumb question: why do we prefix the module name to all the classnames in Spryker ? Don't we have namespaces for that ?
Comments
-
Namespaces are to prevent naming collisions. The naming pattern in Spryker is required for the
Locator
to automatically find relating objects and allow for dynamic replacement of objects by having a lookup order and therefore precedence.0 -
You can imagine it being Smalltalk Message Passing via stringly typed lookups.
0 -
As in: The message (interface) matters, not the recipient.
0 -
tbh I was afraid, that the locator (or in detail the
ClassResolver
) is the reason for this naming convension π0 -
The reason for the convention is the design of Spryker that allows for ducktyping in a rigid type system essentially. You need a common denominator and the lowest one is the name. It's the same in Spring btw. π
0 -
thx Thomas for your insights. Will try to get my head around it π
0 -
(although I don't see why we cannot utilize the namespace as the common denominator as well)
0 -
Because it will be different. You have a lookup order of namespaces...
Let's say we have namespaces A, B and Vendor.
Our lookup Order is from A -> Vendor.
That way, the upper layers can overwrite or extend modules from the bottom layers without disturbing each other or causing tight coupling. It is necessary for a loosely coupled, lately bound system.0 -
just imagine, how neat this classname could look like:
class MerchantRelationshipSalesOrderThresholdGuiDependencyProvider
π0 -
In my example above you can also replace A with and B with Pyz π
0 -
(and Vendor with Spryker and SprykerEco of course)
0 -
And btw: It's not a dumb question, it's a rather important one as it defines what Spryker really is and how things plug together - at least how I understand it. I'm not a Spryker employee but I actually love that part about Spryker a lot.
0 -
but this hierarchy is reflected in the namespace, right?
why not having:
Spryker\Zed\MerchantRelationshipSalesOrderThresholdGui\DependencyProvider Pyz\Zed\MerchantRelationshipSalesOrderThresholdGui\DependencyProvider FooBar\Zed\MerchantRelationshipSalesOrderThresholdGui\DependencyProvider
I don't really get, why we need the Modulename as a prefix
0 -
You are right - one could implement that by Module lookup... I just think it was chosen that way for more clarity. That way you don't have to alias everything and it's more convenient for a class level scan - but that's just wild speculation.
0 -
(plus it's easier to navigate the project)
0 -
guess that goes down to personal taste... for me, those long class names are driving me nuts π
0 -
Just name your module in a short an sweet fashion.
0 -
A & B π
0 -
DiscountDependencyProvider
isn't half bad π0 -
there are just cases where finding a concise name can be difficult so we get these monsters...
0 -
That won't help if you do a module scan anyway, since instead of searching for
MerchantRelationshipSalesOrderThresholdGuiDependencyProvider
you now need to search forMerchantRelationshipSalesOrderThresholdGui\DependencyProvider
It's even one character more!
0 -
PHPstorm supports camelCase search on namespace.
you can type "MeRSaDePr" and it will resolve it π0 -
(if you meant that by "module scan")
0 -
What you mean is called "fuzzy search" and would work for either scenario π So no savings there, either.
0 -
I remember in old times it was not really convenient in PHPStorm working with the files with the same name. Just two tabs would have the same name then. Now itβs better, but still, having prefixes helps a lot to avoid mistakes
0 -
I just think it was chosen that way for more clarity
I was there in the very beginning of the Spryker journey, when we migrated from a Zend/PEAR Naming (thatβs one of the reasons it was named Zed) application to Silex and had to migrate all namespaces too.
Essentially we had a pretty hard time finding the right Facade if it was not prefixed with the bundle name so the class name was prefixed with the bundle instead of relaying only on the namespace.
Back in 2014 when the migration happened (or maybe early 2015) PHPStorm had the already mentioned drawback to only show the classname in the tab title which made it also a lot more convenient to prefix the important class names with the bundle and the layer name (e.g.: FooBusinessFactory).0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 77 Spryker News
- 938 Developer Corner
- 795 Spryker Development
- 90 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 27 Job Opportunities
- 3.2K π Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 33 Product & Business Questions
- 69 Spryker Safari Questions
- 50 Random