Skip to content
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

Merged
merged 18 commits into from
Feb 22, 2024

Conversation

levBagryansky
Copy link
Member

@levBagryansky levBagryansky commented Feb 15, 2024

Closes #2836


PR-Codex overview

This PR introduces a new PhTracedEnclosure class to track recursion in dataization process. It also updates EOcage to use PhTracedEnclosure.

Detailed summary

  • Added PhTracedEnclosure class to trace recursion in dataization
  • Updated EOcage to use PhTracedEnclosure for enclosure handling
  • Added a test for exception throwing when recursion occurs

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@levBagryansky
Copy link
Member Author

@maxonfjvipon could you please review

@levBagryansky
Copy link
Member Author

@yegor256 please check

@yegor256
Copy link
Member

@volodya-lombrozo please, review this one

@volodya-lombrozo volodya-lombrozo self-requested a review February 19, 2024 09:01
* @param supplier Ordinary way to get attribute.
* @return The {@link Attr} if there is no StackOverflow case.
*/
private Attr getAttrSafely(final Supplier<Attr> supplier) {
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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;
        }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yegor256 please check

Copy link
Member

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.

Copy link
Member

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) {
Copy link
Member

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.

levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 19, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 19, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 20, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 20, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 20, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 20, 2024
c71n93 added a commit to levBagryansky/eo that referenced this pull request Feb 20, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 20, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 20, 2024
c71n93 added a commit to levBagryansky/eo that referenced this pull request Feb 20, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 20, 2024
@levBagryansky
Copy link
Member Author

@volodya-lombrozo WDYT about separating private static final class PhTracedEnclosure to separate file?

@volodya-lombrozo
Copy link
Member

@volodya-lombrozo WDYT about separating private static final class PhTracedEnclosure to separate file?

@levBagryansky I don't think we need it. Since it is placed inside the class It indicates that PhTracedEnclosure is used only in the single place.

@levBagryansky
Copy link
Member Author

@volodya-lombrozo EOcage becomes too large and ugly as for me.

@volodya-lombrozo
Copy link
Member

@levBagryansky I agree then, it makes sense to move it.

Copy link
Member

@volodya-lombrozo volodya-lombrozo left a 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.

@levBagryansky
Copy link
Member Author

@yegor256 please check

1 similar comment
@levBagryansky
Copy link
Member Author

@yegor256 please check

@yegor256 yegor256 merged commit 7b604a8 into objectionary:master Feb 22, 2024
15 checks passed
@levBagryansky levBagryansky deleted the 2836_cage-stackoverflow branch February 22, 2024 08:19
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 22, 2024
levBagryansky added a commit to levBagryansky/eo that referenced this pull request Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cage.eo:62-66: Make up with an idea how to prevent...
3 participants