question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Analyzer proposal: Don't use 'public' on members of internal types

See original GitHub issue

Or more generally: “Avoid visibility modifiers that exceed their effect”

Internal types may contain public members if those members implement interfaces. Aside from that case, public members in an internal or private type are in fact not public at all, but internal.

During code reviews seeing an added or changed public member can set off alarm bells to reviewers who are keen to watch the evolution of a library’s public API. It’s an extra load on them to see public on a new member only to later realize that the container itself is internal or private and thus not worth an API review.

An analyzer should prevent liberal use of public where internal would be equivalent.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
sharwellcommented, Jul 10, 2019

I’m concerned the interface implementation limitation would be sufficiently impactful as to undermine the intent of the rule. Other approaches, including but not limited to PublicApiAnalyzer, are superior for tracking changes to the public API surface.

For teams that implement public APIs first as internal types and then move to public types after review, the use of public methods to designate eventual public APIs of the types could be beneficial.

On the other hand, projects that have no public API by design, this has the interesting side effect of becoming a rule that simply reveals interface implementations.

Design questions:

  1. How would this work for members of nested types? For example, members of protected types nested in an internal type would have a maximum accessibility of private protected, which impacts members declared public, internal, and protected.
1reaction
JohanLarssoncommented, Jul 9, 2019

@AArnott wrote it like this: https://github.com/GuOrg/Gu.Analyzers/pull/217 We can move it here if it is decided that there will be a cop rule for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Analyzer Proposal: Seal internal/private types · Issue #49944
From personal experience actually having implemented an analyzer to warn if classes with no new virtual members and no inheritors aren't sealed ...
Read more >
Recruiting Internally and Externally
Employee recruiting is the activity of identifying and soliciting individuals—either from within or outside an organization—to fill job vacancies or staff ...
Read more >
Recommended Informed Consent Language for Data Sharing
Language to Avoid. Promises in the informed consent can appear to limit an investigator's ability to share data with the research community.
Read more >
Default interface methods - C# 8.0 draft feature specifications
Access modifiers may be used on interface members of all kinds of members that are permitted. The access level public is the default...
Read more >
AS 2605: Consideration of the Internal Audit Function
This section provides the auditor with guidance on considering the work of internal auditors and on using internal auditors to provide direct assistance...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found