-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2836 cage stackoverflow #2879
2836 cage stackoverflow #2879
Conversation
@maxonfjvipon could you please review |
@yegor256 please check |
@volodya-lombrozo please, review this one |
* @param supplier Ordinary way to get attribute. | ||
* @return The {@link Attr} if there is no StackOverflow case. | ||
*/ | ||
private Attr getAttrSafely(final Supplier<Attr> supplier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levBagryansky What do you think if we rename this method to attrTraced
or tracedAttr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo attrTraced
looks like we return traced attribute, but it is not. Maybe getAttrWithTracingTheCage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levBagryansky ok, maybe just attr
then? Since the signature is different, we can easily overload this method.
I don't like getAttrWithTracingTheCage
because of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo this post is about variables. attr
is very bad name because you need to read documentation to understand what the method does. Ideally, our code should be understandable without documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levBagryansky Here you can read about methods:
Here is a simple principle for naming methods in OOP, which I’m trying to follow in my code: it’s a verb if it manipulates, it’s a noun if it builds. That’s it. Nothing in between. Methods like saveFile() or getTitle() don’t fit and must be renamed and refactored.
As for this:
Ideally, our code should be understandable without documentation.
You are absolutely right. attr
- is a method which returns attribute, that is. A reader don't need to know "how" it was created. If I need to know "how" - I will read the method body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo reader don't need to know "how" it traces. If I need to know "how" - I will read the method body. Significant that it traces.
It is obvious that it gets from its signature. Again, to get is responsibility of supplier. Responsibility of the method is to trace that supplier does.
Again, the idea of method is in tracing. It can trace by plural ways, and how it traces is written in implementation. Here the name say you that it not just gets it but traces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yegor256 please help. What option is cleaner?
@Override
public Attr attr(final String name) {
return this.getAttrWithTracing(() -> this.enclosure.attr(name));
}
or
@Override
public Attr attr(final String name) {
return this.attr(() -> this.enclosure.attr(name));
}
There is also an option to make the the callee generic in order to hoghlight its goal:
@Override
public Attr attr(final String name) {
return this.getItWithTracing(() -> this.enclosure.attr(name));
}
private <T> T getItWithTracing(final Supplier<T> supplier) {
if (EOcage.PhTracedEnclosure.DATAIZING_CAGES.contains(this.cage)) {
throw new ExFailure("The cage %s is already dataizing", this.cage);
}
EOcage.PhTracedEnclosure.DATAIZING_CAGES.add(this.cage);
final T ret = supplier.get();
EOcage.PhTracedEnclosure.DATAIZING_CAGES.remove(this.cage);
return ret;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yegor256 please check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levBagryansky First, using the word get
for method names which are not "getters" is an anti-pattern: https://stackoverflow.com/questions/46139501/should-getters-from-domain-classes-not-be-prefixed-with-get-in-ddd-and-why Because of this, getItWithTracing
is not a good option.
Second, the ...WithTracing
part is an indicator of temporal coupling between statements inside the method, which is also an anti-pattern: https://blog.ploeh.dk/2011/05/24/DesignSmellTemporalCoupling/
A better and more object-oriented design would be to use... guess what, a decorator. You have a Supplier
and you want to turn it into another Supplier
, which does something when its get()
method is called. Make it this way:
@Override
public Attr attr(final String name) {
return TracingWhileGetting(() -> this.enclosure.attr(name));
}
Here, the TracingWhileGetting
is the Supplier
that does the "tracing" you need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yegor256 Looks like overengineering to me. We use this method only in this class and in the single place. I would agree if we used this TracingWhileGetting
in other Phi
classes, but we do not do it. Moreover, Tracing
and Getting
are participles (a participle is a verb form.) But according with the Java specification:
Class names should be nouns, in mixed case with the first letter of each internal word capitalized.
Nouns (not adjectives or verbs.) Maybe it's better to name the method attr
? In this case we won't add extra code and will avoid the all convention violations which you mentioned before. What do you think?
* @param supplier Ordinary way to get attribute. | ||
* @return The {@link Attr} if there is no StackOverflow case. | ||
*/ | ||
private Attr getAttrSafely(final Supplier<Attr> supplier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levBagryansky ok, maybe just attr
then? Since the signature is different, we can easily overload this method.
I don't like getAttrWithTracingTheCage
because of this.
@volodya-lombrozo WDYT about separating |
@levBagryansky I don't think we need it. Since it is placed inside the class It indicates that |
@volodya-lombrozo |
@levBagryansky I agree then, it makes sense to move it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levBagryansky Looks good to me. Thank you.
@yegor256 please check |
1 similar comment
@yegor256 please check |
Closes #2836
PR-Codex overview
This PR introduces a new
PhTracedEnclosure
class to track recursion in dataization process. It also updatesEOcage
to usePhTracedEnclosure
.Detailed summary
PhTracedEnclosure
class to trace recursion in dataizationEOcage
to usePhTracedEnclosure
for enclosure handling