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

Use joinpath when splicing up paths in test files #207

Open
tdivoll opened this issue Feb 8, 2023 · 0 comments
Open

Use joinpath when splicing up paths in test files #207

tdivoll opened this issue Feb 8, 2023 · 0 comments
Labels
🧹 clean up code clean ups and other quick fixes

Comments

@tdivoll
Copy link
Collaborator

tdivoll commented Feb 8, 2023

          String interpolation/concatenation works fine here, but people seem to say that the "correct" way to do this is to use `joinpath` when splicing up paths (see for example [this discussion](https://stackoverflow.com/questions/32070934/what-is-the-advantage-of-using-path-combine-over-concatenating-strings-with)).

Because many paths are being created with the same base directory, I would make a custom function to simplify this a bit. Something like this:

julia> test_data_dir = "foo"
"foo"

julia> jointdd(s) = joinpath(test_data_dir, s)
jointdd (generic function with 1 method)

julia> jointdd("bar")
"foo\\bar"

Then line 6, for example, would reduce to

segmentation_B_not_ice_mask = float64.(load(jointdd("matlab_I.png")))

Or even throw in load:

loadtdd(s) = load(joinpath(test_data_dir, s))

segmentation_B_not_ice_mask = float64.(loadtdd("matlab_I.png"))

Also, I think piping would probably work nicely for such use case:

loadtdd = jointdd |> load
segmentation_B_not_ice_mask = "matlab_I.png" |>loadtdd  |> x->float64.(x)

Totally up to you, though! It's only a suggestion. 😃

Originally posted by @cpaniaguam in #130 (comment)

@tdivoll tdivoll self-assigned this Feb 8, 2023
@tdivoll tdivoll added the 🧹 clean up code clean ups and other quick fixes label Feb 8, 2023
@tdivoll tdivoll added this to To do in Ice Floe Coding Tasks via automation Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 clean up code clean ups and other quick fixes
Projects
Status: Nice To Have
Development

No branches or pull requests

1 participant