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

Rename getter functions to be idiomatic #8320

Merged
merged 6 commits into from Jan 25, 2021
Merged

Conversation

terencechain
Copy link
Member

@terencechain terencechain commented Jan 23, 2021

What type of PR is this?

Clean up

What does this PR do? Why is it needed?

Rename a few getter functions to make it more idiomatic for Go
More info: https://hackmd.io/CVorlf6HQpWtU5jCSPQvhg

Which issues(s) does this PR fix?

N/A

Other notes for review

N/A

@terencechain terencechain changed the title Rename getter functions Rename getter functions to be idiomatic Jan 25, 2021
@terencechain terencechain marked this pull request as ready for review January 25, 2021 16:04
@terencechain terencechain requested a review from a team as a code owner January 25, 2021 16:04
Copy link
Contributor

@rkapka rkapka left a comment

Choose a reason for hiding this comment

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

I would like to propose the following standard for naming constructors.

If the package name describes the object being created, then the constructor name should be New, to avoid duplication. Example: service.New vs service.NewSevice (the function returns a Service struct). Otherwise, the name should be NewXyz. Example: helpers.NewSlotTicker vs helpers.New. Seeing helpers.New does not tell you anything about what's being created.

// getBlockRootsByFilter retrieves the block roots by slot
func getBlockRootsBySlot(ctx context.Context, tx *bolt.Tx, slot uint64) ([][]byte, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.getBlockRootsBySlot")
// blockRootsByFilter retrieves the block roots by slot
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
// blockRootsByFilter retrieves the block roots by slot
// blockRootsBySlot retrieves the block roots by slot

@@ -83,7 +83,7 @@ type Service struct {
}

// NewService initializes a new p2p service compatible with shared.Service interface. No
// connections are made until the Start function is called during the service registry startup.
// connections are made until the New function is called during the service registry startup.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this change is correct?

@@ -83,7 +83,7 @@ type Service struct {
}

// NewService initializes a new p2p service compatible with shared.Service interface. No
// connections are made until the Start function is called during the service registry startup.
// connections are made until the New function is called during the service registry startup.
func NewService(ctx context.Context, cfg *Config) (*Service, error) {
Copy link
Contributor

@rkapka rkapka Jan 25, 2021

Choose a reason for hiding this comment

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

I would prefer New instead of NewService. Similarly for other services.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. But let's do it in another PR

@@ -103,7 +103,7 @@ func (bs *Server) ListAttestations(
}

// ListIndexedAttestations retrieves indexed attestations by block root.
// IndexedAttestationsForEpoch are sorted by data slot by default. Start-end epoch
// IndexedAttestationsForEpoch are sorted by data slot by default. New-end epoch
Copy link
Contributor

Choose a reason for hiding this comment

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

Something is not right here.

// GetSlotTicker is the constructor for SlotTicker.
func GetSlotTicker(genesisTime time.Time, secondsPerSlot uint64) *SlotTicker {
// New starts and returns a new SlotTicker instance.
func New(genesisTime time.Time, secondsPerSlot uint64) *SlotTicker {
Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree with this change - slotutil.New does not convey information about what is being created. I would prefer slotutil.NewSlotTicker.

// GetEpochTicker is the constructor for EpochTicker.
func GetEpochTicker(genesisTime time.Time, secondsPerEpoch uint64) *EpochTicker {
// New starts the EpochTicker.
func New(genesisTime time.Time, secondsPerEpoch uint64) *EpochTicker {
Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree with this change - helpers.New does not convey information about what is being created. I would prefer helpers.NewEpochTicker.

// entering a offset greater than secondsPerSlot is not allowed.
func GetSlotTickerWithOffset(genesisTime time.Time, offset time.Duration, secondsPerSlot uint64) *SlotTicker {
func NewWithOffset(genesisTime time.Time, offset time.Duration, secondsPerSlot uint64) *SlotTicker {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't know what is that thing with offset. I would prefer NewSlotTickerWithOffset.

@prylabs-bulldozer prylabs-bulldozer bot merged commit d5ec248 into develop Jan 25, 2021
@delete-merged-branch delete-merged-branch bot deleted the rename-functions branch January 25, 2021 21:27
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.

None yet

2 participants