Clear questions and runnable code
get the best and fastest answer
Diary of a Zydeco experiment - E03 - Errors for fun and successby Smonff (Scribe)
|on Sep 22, 2020 at 19:29 UTC||Need Help??|
So today for the third episode of this diary, and after Diary of a Zydeco experiment - E02 - History, I would like to share a nice error message that I encountered while working on the modeling of my project. It can look strange to be happy about encountering an error message, but this one made my life really easier. It is still not about Zydeco directly but about one of the stable technology it relies on. Please don't look too deeply at the examples, they are mostly sarcastic but not very well structured on the OO side for now.
So we have this role, that summarize very naively what a Buyer can do:
There is also an Exhibit role, that I will show only for the fun, but it is mostly distraction at this point:
Then we have a Gallerist class, that consumes the Buyer role. You will maybe notice that there is a tiny mistake in this class (we'll come back a bit later on the mistake so don't look too much):
Let's run it! But it won't go very well.
What I want to focus on is the Can't apply Art::Buyer to Art::Gallery - missing money part.
The error message is launched by a croak call in the _check_requires() method of Role::Tiny.
Once we add the right attribut to the Gallery class, everything goes well:
And we run the tests again:
We actually don't even need to check the attributes in details.
What I found amazing is how the error message makes sense. It just tells what should be done to fix the problem: adding a money attribute to the Gallery class. But more than that, it have a deeper meaning, that is exactly the point og this project. I mean you wouldn't have an art gallery with zero money would you? This is what I call efficient and reliable object oriented programming thanks Zydeco making a great use of the stable technologies it is built on (like Role::Tiny).
So far, my overall use of Zydeco is very satisfactory during the application modeling phase. Some could say that I could draw some class diagrams and not coding, but the Zydeco use is so easy and non-verbose that it really make possible to focus ont the modeling and not on the coding: focusing on listing attributes, methods, roles and their relationship, not on the implementation.
Next episode is mostly news from the brand new 2021 year...