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

Minor improvements and best practices #8

Open
rogersamso opened this issue Aug 26, 2022 · 9 comments
Open

Minor improvements and best practices #8

rogersamso opened this issue Aug 26, 2022 · 9 comments

Comments

@rogersamso
Copy link
Collaborator

Hi @Victor-Garcia-p
Here I will write some improvements that could be done in the code.

@rogersamso
Copy link
Collaborator Author

The files that you use to make plots could be converted into Pluto notebooks or Jupyter notebooks.

This is optional, but I recommend it because notebooks are good for interactive visualization.

@rogersamso
Copy link
Collaborator Author

rogersamso commented Aug 26, 2022

A good practice is to try to divide your code into functions, rather than writing long scripts.

In notebooks it is perfectly fine to write scripts, though. In a notebook you should only write functions in case you find yourself repeating the same lines of code over and over, but then those functions should be placed in a separate file, and imported by the notebook.

@rogersamso
Copy link
Collaborator Author

rogersamso commented Aug 26, 2022

For better performance, use const for global variables that do not change.

If its value changes during execution, but the type remains the same, then you can provide the type for better performance (this is only available from julia 1.8):

x:Int64 = 4

@rogersamso
Copy link
Collaborator Author

Standard desviation should be written without the s (deviation).

@rogersamso rogersamso changed the title Minor improvements Minor improvements and best practices Aug 26, 2022
@rogersamso
Copy link
Collaborator Author

It is better to write all the paths on top of the file. This way, with a quick look at the file, you already know what data it is importing.

@rogersamso
Copy link
Collaborator Author

Be more explicit with variable names. Write this:

# Define paths
data_dir = joinpath(@__DIR__, "..", "data")
grid_path = joinpath(data_dir, "grid.jld2")

instead of this:

#Define the path of the data files
path = joinpath(@__DIR__, "..", "data")

#Load the grid
file=joinpath(path,"grid.jld2")

@rogersamso
Copy link
Collaborator Author

rogersamso commented Aug 26, 2022

Use JuliaFormatter.jl to autoformat your code. It formats your code so that it follows the preferred julia coding style.

Install this package in the global environment, rather than in the project environment, because we don't want this package in the Project.toml file.

You can do this by running this in the terminal:

julia
using Pkg
Pkg.add(JuliaFormatter)
using JuliaFormatter

And then, from the code folder just run:

format(".")

This will fix all format issues in your files. You can see all changes in a particular file by pressing ; from the julia REPL and running:

git diff plots2d.jl

Try to see what it has corrected, to avoid repeating the same mistakes in the code you write from now on.

@rogersamso
Copy link
Collaborator Author

File names should be written in lower case, unless they are modules.

@Victor-Garcia-p
Copy link
Owner

Fixed, thanks for the advise

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

No branches or pull requests

2 participants