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

JLBP: Declare all dependencies #1767

Merged
merged 7 commits into from
Mar 4, 2021
Merged

JLBP: Declare all dependencies #1767

merged 7 commits into from
Mar 4, 2021

Conversation

elharo
Copy link
Contributor

@elharo elharo commented Oct 29, 2020

@elharo elharo requested a review from suztomo October 29, 2020 15:43
@google-cla google-cla bot added the cla: yes label Oct 29, 2020
docs/JLBP-0022.md Outdated Show resolved Hide resolved
Code should not call methods, reference fields, or instantiate classes from _indirect_ dependencies. These are dependencies of the declared dependencies. Projects that rely on indirect dependencies have an annoying habit of breaking in unexpected ways when direct dependencies are upgraded.

For example, your project might declare a dependency on the
Google HTTP Java Client which
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Google HTTP Java Client which
Google HTTP Java Client, which

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a restrictive clause, but it's arguable.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it were restrictive, that would mean that there are several Google HTTP Java Clients, only one of which depends on Apache HTTP Components. Is that the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's one way of identifying restrictive subordinate clauses, but a little more generally, "A restrictive adjective clause, on the other hand, is essential to a sentence and should not be set off by commas" https://www.thoughtco.com/restrictive-and-nonrestrictive-adjective-clauses-1689689

I think this clause is indeed essential to the sentence.

A better reference than that will have to wait until I get back to the office to retrieve my Chicago Manual of Style. :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

The content of the clause is important to the meaning of the paragraph, but not essential to the sentence.

"For example, your project might declare a dependency on the Google HTTP Java Client."

That doesn't change the reader's understanding of what you mean by "the Google HTTP Java Client", although it leaves out an important detail about why you're talking about it.

Compare to your sentence above: "Projects that rely on indirect dependencies have an annoying habit of breaking in unexpected ways when direct dependencies are upgraded." If you got rid of the restrictive clause and changed it to "Projects have an annoying habit of breaking in unexpected ways when direct dependencies are upgraded", the reader wouldn't know which projects you were talking about.

Anyway, it's your document.

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 it needs a comma for the reason David explained:

If it were restrictive, that would mean that there are several Google HTTP Java Clients, only one of which depends on Apache HTTP Components

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point is "essential to a sentence," which clause this is. It is not whether it is essential to the meaning of the modified noun or noun phrase.

docs/JLBP-0022.md Outdated Show resolved Hide resolved
docs/JLBP-0022.md Outdated Show resolved Hide resolved
explicitly declaring a dependency on Apache HTTP Components. However, you should
add the dependency anyway. This way if a future version of the
Google HTTP Java Client no longer depends on Apache HTTP Components, your code will
still compile and work. Strict dependencies also help static analysis tools better understand a project.
Copy link
Contributor

@netdpb netdpb Oct 29, 2020

Choose a reason for hiding this comment

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

I think you could start a new paragraph with "Strict dependencies...." It's starting a new idea.


# Declare all dependencies

If your code references a class—for example, by invoking a method in that class—declare a dependency that includes that class in your pom.xml, build.gradle,
Copy link
Contributor

Choose a reason for hiding this comment

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

The varying line lengths make this hard to review. Can you run mdformat?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-bash: mdformat: command not found

still compile and work. Strict dependencies also help static analysis tools better understand a project.

This doesn't only happen when a project itself is upgraded. It can also
happen when dependency mediation selects a different version of a library's dependency
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe give examples of when dependency mediation might change versions other than when you change your declared dependency versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm hesitant to have a single sentence paragraph.


# Declare all dependencies

If your code references a class—for example, by invoking a method in that class—declare a dependency that includes that class in your pom.xml, build.gradle,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a formatting practice for referring to files? Should this be pom.xml or pom.xml?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we've chosen one yet. Might be worth checking general google style and general cleanup.

permalink: /JLBP-22
---

# Declare all dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this refer explicitly to direct dependencies somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, done

@suztomo
Copy link
Contributor

suztomo commented Oct 29, 2020

"https://jlbp.dev/JLBP-1 Minimize Dependencies" discusses the number of dependencies but in a different direction. I think it's better to combine the two into one such as "Declare optimal number of dependencies". What do you think?

@elharo
Copy link
Contributor Author

elharo commented Oct 29, 2020

JLBP-1 is not the same. That's about whether to depend on something. This is about how to declare the dependencies you have.

Code should not call methods, reference fields, or instantiate classes from _indirect_ dependencies. These are dependencies of the declared dependencies. Projects that rely on indirect dependencies have an annoying habit of breaking in unexpected ways when direct dependencies are upgraded.

For example, your project might declare a dependency on the
Google HTTP Java Client which
Copy link
Contributor

Choose a reason for hiding this comment

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

If it were restrictive, that would mean that there are several Google HTTP Java Clients, only one of which depends on Apache HTTP Components. Is that the case?

docs/JLBP-0022.md Show resolved Hide resolved
Code should not call methods, reference fields, or instantiate classes from _indirect_ dependencies. These are dependencies of the declared dependencies. Projects that rely on indirect dependencies have an annoying habit of breaking in unexpected ways when direct dependencies are upgraded.

For example, your project might declare a dependency on the
Google HTTP Java Client which
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 it needs a comma for the reason David explained:

If it were restrictive, that would mean that there are several Google HTTP Java Clients, only one of which depends on Apache HTTP Components

docs/JLBP-0022.md Outdated Show resolved Hide resolved
explicitly declaring a dependency on Apache HTTP Components. However, you should
add the dependency anyway. This way if a future version of the
Google HTTP Java Client no longer depends on Apache HTTP Components, your code
still compiles. Strict dependencies also help static analysis tools better understand a project.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you add names of these static analysis tools you have in mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not needed

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm asked from somebody about this static analysis tools, I cannot answer it. Would you help me in this regard?

explicitly declaring a dependency on Apache HTTP Components. However, you should
add the dependency anyway. This way if a future version of the
Google HTTP Java Client no longer depends on Apache HTTP Components, your code
still compiles. Strict dependencies also help static analysis tools better understand a project.
Copy link
Contributor

@suztomo suztomo Oct 30, 2020

Choose a reason for hiding this comment

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

"Strict deps" appears in a previous paragraph, but 'Strict dependencies" does not. Would you pick one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bazel does call it "strict deps" bit otherwise we try not to abbreviate

Copy link
Contributor

Choose a reason for hiding this comment

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

Bazel call it in that way, but this document does not name this practice.

docs/JLBP-0022.md Outdated Show resolved Hide resolved
docs/JLBP-0022.md Outdated Show resolved Hide resolved
docs/JLBP-0022.md Show resolved Hide resolved
@elharo elharo changed the title Declare all dependencies JLBP: Declare all dependencies Oct 30, 2020
@elharo elharo merged commit befe78c into master Mar 4, 2021
@elharo elharo deleted the i1542 branch March 4, 2021 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JLBP: strict java deps
3 participants