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..
Hello again 🙂, in spryker i noticed several times, that instead of giving null
Hello again 🙂,
in spryker i noticed several times, that instead of giving null or an exception, the implementation gives back an empty transfer object anyway. For example the method getCustomerOrderByOrderReference()
in SalesFacadeInterface
will always return an OrderTransfer
even it is has not found a corresponding entity in the database… does this have a deeper meaning? Is the transfer object also responsible for representing the abscent of the data by just omitting the data?
I ask because i never found a counter example that returns null instead. For me its a bit misleading when asking a client or what else for data that can be abscent in fact but the corresponding method will in any case return a transfer object but it is empty. The clients “client” has to look now if the data in it is empty instead of just checking that the return value was null … i could imagine that some developer is not aware of that. Is there a spryker convention on that that we can/should follow?
Best regards
Comments
-
Hi Ingo,
The method you’re mentioning is serving (only) to the GatewayController. Communication between Zed and Yves (RPC) works in a way that the request/response must always be a Transfer object of the expected type. It is not really a GLUE restful API where you can return a status code and empty response. I think this is the reason.0 -
Regarding conventions, it is mostly:
• method name starts with “get…” assumes that the object is there, in case of collections an empty collection can be returned. Otherwise Exception is thrown
• method name starts with “find…” assumes that object may not be found, in that case null is returned0 -
Hi Andriy. Thanks for your response. That makes sense to me at all. But one thing: if there is no value found that can be used for the collection, it makes anyway no sense to return the empty collection. For example “getActiveStores” … if there is no store, the exception is the only logical option here since there MUST be at least one store in this collection (“No active stores found which is a serious problem now”, otherwise it would be findActiveStores() as mentioned, which then should return null for “no active store found but it is okay”). As conclusion: empty collections should never appear in my eyes, or do i miss something? 🤔
0 -
Or is it just because of the PHP language which expect return values anyway even if you prevent return by throwing exceptions?
0 -
the collection is kind-off an array. So empty array - is a valid value here. Whether there is “Exception” to be thrown after “getActiveStores” - is for client code to decide, depending on what it does, I would say.
0 -
regarding get / find - it applies to singular methods
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 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
- 26 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
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random