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

Resource API: constructors suffice for the Create API #191

Conversation

toumorokoshi
Copy link
Member

As many programming languages are object-oriented, a constructor can satisfy
the requirements of a Create function. Calling that out in the spec would
be helpful to clarify.

I spoke to @carlosalberto briefly about this, and he clarified. I figured it would be great to clarify.

As many programming languages are object-oriented, a constructor can satisfy
the requirements of a Create function. Calling that out in the spec would
be helpful to clarify.
@songy23
Copy link
Member

songy23 commented Jul 23, 2019

Please sign the CLA.

@toumorokoshi
Copy link
Member Author

toumorokoshi commented Jul 23, 2019

I just signed it, thanks for the reminder!

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

LGTM after signing the CLA, but a better solution might be to follow #165 and describe the behavior instead of the implementation. I.e. not say either "static" or "constructor".

Copy link
Member

@arminru arminru left a comment

Choose a reason for hiding this comment

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

LGTM but I'd prefer #165 like @c24t mentioned.

@@ -42,7 +42,7 @@ labels"](../semantic-conventions.md) that have prescribed semantic meanings.
### Create

Creates a new `Resource` out of the collection of labels. This is a static
method.
method. For object-oriented languages, a constructor is also valid.
Copy link
Member

Choose a reason for hiding this comment

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

It is a benefit for APIs to use static factory methods instead of ctor. See this article about java (also I think applies to other object-oriented languages) https://javarevisited.blogspot.com/2017/02/5-difference-between-constructor-and-factory-method-in-java.html

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the link! I think that does provide great arguments for why a factory method works well.

What's the best way to add this insight to the spec? should we explicitly call out some of the advantage / disadvantages, or defer to a larger document discouraging constructors?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we shouldn't enforce factory methods usage - recommending them should be fine though.

(I get the advantages of factory methods, but I'd prefer to offer some flexibility here, honestly)

Copy link
Member

Choose a reason for hiding this comment

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

Not saying that we should enforce that, but I want everyone to understand the tradeoffs when they make a language specific decision. May be good to say that:
"we recommend factory method for these reasons a, b, c, but a direct constructor can be also used."

Copy link
Member

Choose a reason for hiding this comment

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

This argument can be a generic comment that applies to all the ctor/static factory method (methods to create object in general), and in this specific way I would just say:

API MUST allow users to create a new Resource from a collection of labels.

Copy link
Contributor

Choose a reason for hiding this comment

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

"we recommend factory method for these reasons a, b, c, but a direct constructor can be also used."

This would be fine, yes ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think given the focus on capabilities, it might be more productive to have a PR around using a capabilities tone, although I plan on incorporating all the feedback from here.

I'll close this PR and start another one up around adhering to #165.

toumorokoshi added a commit to toumorokoshi/opentelemetry-specification that referenced this pull request Jul 27, 2019
A focus of the specification on the capabilities that should be
afforded rather than strict requirements around implementation
enable better flexibility to ensure libraries are compatible with
the idioms of their corresponding languages.

This commit incorporates feedback discussed in open-telemetry#191.
toumorokoshi added a commit to toumorokoshi/opentelemetry-specification that referenced this pull request Jul 27, 2019
A focus of the specification on the capabilities that should be
afforded rather than strict requirements around implementation
enable better flexibility to ensure libraries are compatible with
the idioms of their corresponding languages.

This commit incorporates feedback discussed in open-telemetry#191.
carlosalberto pushed a commit that referenced this pull request Jul 31, 2019
A focus of the specification on the capabilities that should be
afforded rather than strict requirements around implementation
enable better flexibility to ensure libraries are compatible with
the idioms of their corresponding languages.

This commit incorporates feedback discussed in #191.
SergeyKanzhelev pushed a commit to SergeyKanzhelev/opentelemetry-specification that referenced this pull request Feb 18, 2020
…metry#196)

A focus of the specification on the capabilities that should be
afforded rather than strict requirements around implementation
enable better flexibility to ensure libraries are compatible with
the idioms of their corresponding languages.

This commit incorporates feedback discussed in open-telemetry#191.
TuckTuckFloof pushed a commit to TuckTuckFloof/opentelemetry-specification that referenced this pull request Oct 15, 2020
carlosalberto pushed a commit to carlosalberto/opentelemetry-specification that referenced this pull request Oct 31, 2024
…metry#196)

A focus of the specification on the capabilities that should be
afforded rather than strict requirements around implementation
enable better flexibility to ensure libraries are compatible with
the idioms of their corresponding languages.

This commit incorporates feedback discussed in open-telemetry#191.
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.

6 participants