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

[Renaming] ComputeNixEnv -> ComputeEnv; ensurePackagesAreInstalled -> ensureStateIsCurrent #1675

Merged
merged 3 commits into from
Dec 13, 2023

Conversation

savil
Copy link
Collaborator

@savil savil commented Dec 7, 2023

Summary

These names were getting rather stale. Hopefully, the new ones represent
them more accurately.

How was it tested?

compiles and cicd tests should pass

Copy link
Collaborator Author

savil commented Dec 7, 2023

Copy link
Contributor

@mikeland73 mikeland73 left a comment

Choose a reason for hiding this comment

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

There's a bunch of other functions you will need to change if you want to keep consistency:

Good call.

  • NixEnv -> DevboxEnvExports
  • NixEnvOpts -> DevboxEnvExportsOpts
  • ensurePackagesAreInstalledAndComputeEnv -> computeCurrentDevboxEnv
  • NixEnvPath (maybe?) -> yep, devboxEnvPath

@mikeland73 PTAL

@savil savil force-pushed the savil/skip-cache-if-lockfile-changed branch from 1eb5988 to 6746aba Compare December 7, 2023 23:12
@savil savil force-pushed the savil/rename-funcs branch from 38313c4 to 96630ea Compare December 7, 2023 23:12
@savil savil requested a review from mikeland73 December 7, 2023 23:53
@savil
Copy link
Collaborator Author

savil commented Dec 7, 2023

Also, treating current as a shorter synonym for upToDate (shorter in terms of number of words) but maybe I should change to that?

Base automatically changed from savil/skip-cache-if-lockfile-changed to main December 8, 2023 18:16
@savil savil force-pushed the savil/rename-funcs branch from 3f884b3 to e01fe99 Compare December 8, 2023 23:43
@savil
Copy link
Collaborator Author

savil commented Dec 8, 2023

@mikeland73 PTAL

@savil savil requested review from loreto, ipince and LucilleH and removed request for loreto, ipince and LucilleH December 11, 2023 18:57
@savil
Copy link
Collaborator Author

savil commented Dec 11, 2023

ping

Copy link
Contributor

@mikeland73 mikeland73 left a comment

Choose a reason for hiding this comment

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

Some comments. Approving to unblock.

Only blocker for me:

computeDevboxEnv vs computeCurrentDevboxEnv

This distinction means nothing to me. computeCurrentDevboxEnv should be something like ensureProjectStateIsCurrentAndComputeEnv. If you want to shorten it could also be ensureStateIsCurrentAndComputeEnv

I think when a function is complex, giving it a longer name for clarity is better.

I also think in many cases we can drop Devbox from variables and function names. So computeEnv or computeEnvironment. At the end of the day, the struct is named devbox so it's fairly clear what the subject is.

devbox.go Outdated
@@ -23,7 +23,7 @@ type Devbox interface {
Install(ctx context.Context) error
IsEnvEnabled() bool
ListScripts() []string
NixEnv(ctx context.Context, opts devopt.NixEnvOpts) (string, error)
DevboxEnvExports(ctx context.Context, opts devopt.DevboxEnvExports) (string, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

EnvExports ? So if the struct name is devbox:

devbox.EnvExports ?

Also a bit repetitive but usually our option structs end in Opt. We should leave for consistency. (so EnvExportOpts)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, lets call it EnvExports. Good call.

Yeah, I drop the Opt because devopt already specifies it. For consistency, I can drop it from the other places as well? Happy to do a follow up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Upon further inspection, I am renaming to EnvExportOpts and adding this naming guideline in the devopts package:

// Naming Convention:
// - suffix Opts for structs corresponding to a Devbox api function
// - omit suffix Opts for other structs that are composed into an Opts struct

// DevboxEnvExports returns a string of the env-vars that would need to be applied
// to define a Devbox environment. The string is of the form `export KEY=VALUE` for each
// env-var that needs to be applied.
func (d *Devbox) DevboxEnvExports(ctx context.Context, opts devopt.DevboxEnvExports) (string, error) {
ctx, task := trace.NewTask(ctx, "devboxNixEnv")
Copy link
Contributor

Choose a reason for hiding this comment

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

make sure trace tasks and profiling names are changed too.

internal/impl/devbox.go Outdated Show resolved Hide resolved
internal/impl/devbox.go Show resolved Hide resolved
internal/impl/packages.go Outdated Show resolved Hide resolved
internal/impl/devbox.go Outdated Show resolved Hide resolved
@savil
Copy link
Collaborator Author

savil commented Dec 12, 2023

Some comments. Approving to unblock.

Only blocker for me:

computeDevboxEnv vs computeCurrentDevboxEnv

This distinction means nothing to me. computeCurrentDevboxEnv should be something like ensureProjectStateIsCurrentAndComputeEnv. If you want to shorten it could also be ensureStateIsCurrentAndComputeEnv

I think when a function is complex, giving it a longer name for clarity is better.

I also think in many cases we can drop Devbox from variables and function names. So computeEnv or computeEnvironment. At the end of the day, the struct is named devbox so it's fairly clear what the subject is.

The distinction is: computeEnvThatWillBeUpToDate versus computeEnvThatMightBeStale.

I don't see the value in being so explicit TBH, because then we'll end up with super long sentences for functions.

ensureStateIsCurrentAndComputeEnv is not a good name because it focuses on the implementation and not the actual meaning goal. The goal is to get the environment that we can guarantee is up-to-date.

If you're not sure the first time you encounter the name, you can inspect the docblock of the function to understand what it does, and in your mind you'll realize "Ah, the current is referring to ensuring the environment is current or up to date". And henceforth it'll be clear.

@mikeland73
Copy link
Contributor

The distinction is: computeEnvThatWillBeUpToDate versus computeEnvThatMightBeStale.

This is not quite why ensurePackagesAreInstalledAndComputeEnv was introduced (see below)

ensureStateIsCurrentAndComputeEnv is not a good name because it focuses on the implementation and not the actual meaning goal. The goal is to get the environment that we can guarantee is up-to-date.

My issues with computeCurrentDevboxEnv are:

  • It's very similar to computeDevboxEnv.
  • current is not a strong enough descriptor of what it is doing. current means "the current thing" and it also means "up to date". The former is probably more common.
  • The function is not only computing the up to date environment, it is making the internal state be up to date. It changes the hidden files and installs nix packages. I'm also not sure I agree that making it up to date is not a goal (I would argue it definitely is). This function was introduced because there were 3-4 places where we repeated the exact same steps, but the goal is to do both, 1) bring the state up to date 2) compute the env.
  • My view with naming is that when meaning in doubt, be explicit.

Does that make sense?

@savil savil force-pushed the savil/rename-funcs branch 2 times, most recently from 5ed63b1 to 60a70f9 Compare December 13, 2023 17:12
@savil
Copy link
Collaborator Author

savil commented Dec 13, 2023

The distinction is: computeEnvThatWillBeUpToDate versus computeEnvThatMightBeStale.

This is not quite why ensurePackagesAreInstalledAndComputeEnv was introduced (see below)

ensureStateIsCurrentAndComputeEnv is not a good name because it focuses on the implementation and not the actual meaning goal. The goal is to get the environment that we can guarantee is up-to-date.

My issues with computeCurrentDevboxEnv are:

  • It's very similar to computeDevboxEnv.
  • current is not a strong enough descriptor of what it is doing. current means "the current thing" and it also means "up to date". The former is probably more common.

I'd already indicated that I wasn't sure if current was best. I've switched to upToDate.

  • The function is not only computing the up to date environment, it is making the internal state be up to date. It changes the hidden files and installs nix packages. I'm also not sure I agree that making it up to date is not a goal (I would argue it definitely is). This function was introduced because there were 3-4 places where we repeated the exact same steps, but the goal is to do both, 1) bring the state up to date 2) compute the env.
  • My view with naming is that when meaning in doubt, be explicit.

Does that make sense?

Fair enough. And its not such a big deal to me so I've changed it for now.

But I have added a TODO to find a better name.

I consider it a mild code-smell to introduce a function when the callers can just directly invoke the core-primitives themselves (in this case, ensureStateIsUpToDate and computeEnv). By adding this function, we do get the small convenience of avoiding two function calls, but then add the cognitive overhead of needing to remember that "oh, we also have this small convenience function".

And then, over time, as has happened here with the "no such host" check, we introduce behavior changes as well. So, it is no longer exactly composing the two functions. And then this begs the question, what is the "core concept of this function" and when should one invoke it versus directly invoking the two functions it is composing?

@savil savil force-pushed the savil/rename-funcs branch from 60a70f9 to 0be16d0 Compare December 13, 2023 17:23
@savil savil changed the title [Renaming] ComputeNixEnv -> ComputeDevboxEnv; ensurePackagesAreInstalled -> ensureProjectStateIsCurrent [Renaming] ComputeNixEnv -> ComputeEnv; ensurePackagesAreInstalled -> ensureStateIsCurrent Dec 13, 2023
@savil savil merged commit e0aad3e into main Dec 13, 2023
25 checks passed
@savil savil deleted the savil/rename-funcs branch December 13, 2023 17:46
Copy link

sentry-io bot commented Dec 16, 2023

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ **exec.ExitError: <redacted *errors.withStack>: <redacted errors.withMessage>: <redacted exec.ExitError> go.jetpack.io/devbox/internal/nix in (*Nix).Pri... View Issue
  • ‼️ **exec.ExitError: <redacted usererr.combined>: <redacted fmt.wrapError>: error running "nix profile install": <re... go.jetpack.io/devbox/internal/nix/nixprofile in... View Issue
  • ‼️ **Generic Error: <redacted errors.withStack>: <redacted usererr.combined> go.jetpack.io/devbox/internal/boxcli/usererr in... View Issue
  • ‼️ **Generic Error: <redacted errors.withStack>: <redacted usererr.combined> go.jetpack.io/devbox/internal/boxcli/usererr in... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants