-
Notifications
You must be signed in to change notification settings - Fork 77
Conversation
I like this idea a lot. Suggestions:
|
I am a huge fan of this, but I would prefer an incremental approach where every new/change code has to go through the formateé. Otherwise we have a hard break in the got history. On the other hand just doing it might be a lot less work. |
I posted this commit just to see if people liked the output. If we're happy with how it looks, I'll add instructions, CI, docs, etc.
This was just run using the default settings (indent=4, margin=92). Unfortunately it doesn't appear to have a whole lot of other options.
Yeah, not sure there is an obvious way to make it incremental. Also, since it changes the indentation from 2 to 4, it would be pretty hard to do incrementally. |
Do we need to switch the indentation from 2 to 4? |
src/DGmethods/DGmodel.jl
Outdated
@launch( | ||
device, | ||
threads = Nfp, | ||
blocks = nrealelem, | ||
faceviscterms!( | ||
bl, | ||
Val(dim), | ||
Val(polyorder), | ||
dg.direction, | ||
dg.gradnumflux, | ||
Q.data, | ||
Qvisc.data, | ||
auxstate.data, | ||
vgeo, | ||
sgeo, | ||
t, | ||
vmapM, | ||
vmapP, | ||
elemtobndy, | ||
topology.realelems, | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main reservations about the formatter is that it makes some of the function calls that used to fit on 2-3 lines take 20 lines. While this is cleaner, it also means you see less of the algorithm on your screen at once.
Is there a way to make it only linebreak after the last comma before hitting 92 characters on a line instead of after every comma?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, unfortunately. Personally I feel this is the main downside as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For particularly bad places there is always skip formatting
No this is one of the few options the formatter provides, but it had been suggested by several people as a way to make the nested function calls more obvious. The cases where we have large numbers of nested loops such as But again, feedback appreciated. |
Personal I like 2 spaces and 80 character limit, but much prefer uniformity than these little things. |
4e72b21
to
f8ea8ca
Compare
So the general consensus is that we should enable this. The main concerns:
Plan:
The remaining question is what formatting options should be applied? If you have opinions chime in below. The options are here: https://github.com/domluna/JuliaFormatter.jl |
It would also be nice to have a git hook that runs the formatter. Below is what we used in a previous project as a #!/bin/bash
#
# Called by git-commit with no arguments. This checks to make
# sure that all .c and .h files are indented correctly before
# a commit is made.
#
# To enable this hook, make this file executable and place it
# in $GIT_DIR/hooks.
. git-sh-setup
CHFILES=$(git-diff-index -M --name-only --cached HEAD | \
grep -E '.*\.(c|cpp|h)$' | grep -v 'node_data\.h')
for CHFILE in $CHFILES;
do
MKTEMPLATE=`basename $CHFILE`.XXXXXXXX
TEMPFILE=`mktemp -t "$MKTEMPLATE"` || exit 1
clang-format $GIT_DIR/../$CHFILE > $TEMPFILE
if diff $GIT_DIR/../$CHFILE $TEMPFILE
then
rm -f $TEMPFILE
else
rm -f $TEMPFILE
NEEDS_FORMAT=1
echo >&2 "$CHFILE needs to be indented with:"
echo >&2 " clang-format -i $GIT_DIR/../$CHFILE"
fi
done
if [ -z "$NEEDS_FORMAT" ]
then
exit 0
else
exit 1
fi |
I also like having a formal style guide, such as https://github.com/jrevels/YASGuide, which JuliaFormatter.jl almost fully supports. |
my opinions:
|
I'm not too fussy: I generally use 4 space indent elsewhere, but our kernels have a lot of indentation which makes it cumbersome. |
I agree with almost all the points set in the Coding Conventions section of the documentation. Switching to 80 columns (instead of 79) is a minor change. Outside of that, it looks like we can follow the YASguide with small exceptions for allowed unicode characters and using 2 spaces instead of 4. The formatter will fix all the spacing, but we need to make sure we are consistent with function names and everything else as well, and that might need to be left to the reviewer(s). I think I agree with @blallen's list, except that I would set Once we have this decided, I will update the Coding Conventions document to reflect the changes here. |
I vote for 4 spaces. The point of indentation is for a clear visual demarcation of blocks, which also means variable scope in many cases. Less than 4 spaces is not clear, IMO. Apart from that, I'm good with everything else. |
f8ea8ca
to
85a86d0
Compare
85a86d0
to
cab981c
Compare
I've updated this PR to the current changes. Once this is merged, the process to update an existing PR will look something like:
To squash this all into a single commit, you should then be able to
|
Please chime in if you have any objections! |
I might try to do this over the weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was scrolling through most of the files and it looks fine for the most part. Some of the manual alignment (for example when aligning =
signs) is now gone and comments are funky. JuliaFormatter will not allow us to do manual alignment anymore, but maybe it's worth fixing some of the comments while we are at it?
s_b = Ri / Pr_0 | ||
if Ri > 0 | ||
temp = ((1 - 2 * β_h * Ri) - sqrt(1 + 4 * (β_h - β_m) * s_b)) | ||
ζ = zfactor / (2 * β_h * (β_m * Ri - 1)) * temp # Eq. 19 in Ref. Byun1990 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments are super weird in this area (and a few other areas) due to JuliaFormatter not dealing with comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stuff will be gone when the new surface fluxes is merged (#556)
You can put stuff in blocks to turn off the formatter: #! format: off
Stuff in here the formatter skips
#! format: on |
Should we go through and figure out where all the manual formatting is preferred, set syntax off and on before merging? I guess we should at least rebase and apply the formatter again before merging this. |
If someone wants to figure out how JuliaFormatter works, we could modify it to suit our own needs. |
cab981c
to
ba69319
Compare
bors r+ |
536: apply JuliaFormatter.jl r=simonbyrne a=simonbyrne This applies [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) to the whole repository. Any thoughts/comments? - [ ] Testing? Co-authored-by: Simon Byrne <simonbyrne@gmail.com>
Build failed |
ba69319
to
a2752f3
Compare
bors r+ |
536: apply JuliaFormatter.jl r=simonbyrne a=simonbyrne This applies [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) to the whole repository. Any thoughts/comments? - [ ] Testing? Co-authored-by: Simon Byrne <simonbyrne@gmail.com>
Build failed |
a2752f3
to
b8cee51
Compare
Codecov Report
@@ Coverage Diff @@
## master #536 +/- ##
==========================================
- Coverage 70.55% 70.51% -0.04%
==========================================
Files 108 108
Lines 6717 6736 +19
==========================================
+ Hits 4739 4750 +11
- Misses 1978 1986 +8
Continue to review full report at Codecov.
|
bors r+ |
536: apply JuliaFormatter.jl r=simonbyrne a=simonbyrne This applies [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) to the whole repository. Any thoughts/comments? - [ ] Testing? Co-authored-by: Simon Byrne <simonbyrne@gmail.com>
Build failed |
bors r+ |
Build succeeded: |
This applies JuliaFormatter.jl to the whole repository.
Any thoughts/comments?