-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
WIP: Clean up linear algebra code #4830
Conversation
You really don't like explicit |
My general policy for explicit vs. implicit returns has been to use |
I'd rather be consistent here. "Looking strange" is a criterion that tends to not scale well. Also, having any
Back when I was a young Julian hatchling, I had a certain colleague whom excoriated me for using them since "you don't need to!!" As a result, I've since past the point of no |
I prefer to have explicit @jiahao I guess this will interfere with your PR for a new API for pivoted factorizations. Should be easy enough to merge. |
FWIW, I think all returns should be explicit. |
tbh idrc. I just want to be consistent, and it was easier to delete Maybe it's time for an internal style guide? |
I've been writing up a style guide for DataArrays/DataFrames. The biggest impediment to a more general style guide is that many of the main contributors to Julia disagree on style. |
Some languages have BDFLs for this reason... but the democratic aspect of doing this in Julia is nice. Here's a not unreasonable style guide:
function mywrapper(A)
if issym(A)
B, c = symmetric_function(A)
return B, c #syntactically required
elseif isherm(A)
B, Q, c = hermitian_function(A)
return B, Q, c #would look asymmetric without explicit return
end
end function mywrapper2(A)
for i=1:10
change!(A)
if norm(A) > 10; return NaN; end #syntactically required
end
return A
end
function mywrapper3(A)
x, y = funct(A)
y > 0 ? throw(SingularError()) : x
end since these tend to be shorter and leaving out the
I prefer this to mandating explicit iszero(v)=return all([w==0 for w in v]) |
I have occasionally regretted not making explicit returns necessary – i.e. implicit returns are always |
I think I always explicitly return for defensive programming reasons (and because all other languages I use do it) - having the return value depend on whichever statement executes last seemed less safe/stable. |
Agreed: one-liners are the only good exception in my book. For me the biggest trouble with implicit returning is that it interacts with things whose return value isn't obvious until you really know the language -- like for loops. I remember an e-mail (that I couldn't find in the archives) from Tim Holy where he noted that adding an explicit So I'd be hugely in favor of a future release of Julia deprecating implicit returns in multi-line function definitions. |
+1 for deprecating implicit returns. It is jarring to have code like that reads somewhat grammatically and then just have a hanging noun at the end. Even the ternary example above Also, not having explicit returns makes it very difficult to find all function return values with a regex. Edit: for multi-liners I mean. Omitting returns in one-liners is most excellent. |
Deprecating implicit returns simply isn't going to happen. When manipulating code, you might need to generate a block like
i.e. yield the value of |
Just so that anyone reading this doesn't get the idea that everyone hates (I also used to do a bit of scala programming, so I'm used to using them.) On Monday, November 18, 2013, Jeff Bezanson wrote:
|
That said, perhaps as a stylistic matter, we could prefer explicit returns by convention. |
When we have implicit returns I think it is good to use it, to keep developers alert that the feature is there. The bugs where a syntax misunderstanding is the cause are often hard to find. If new users ignore the feature, they will design APIs where the functions does not end in |
The style convention about using explicit vs implicit |
This is so comprehensive, @jiahao. Your systematic thoroughness always impresses me. |
symv(uplo, one($elty), A, x) | ||
end | ||
end | ||
>>>>>>> General cleanup of linear algebra routines |
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.
Some rebase leftover here. I also wonder if something else went wrong in the rebase. A lot of level 2 code is added after herk
which is level 3.
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.
Yes, I noticed that after rebasing. Fixing.
@jiahao Great work. I only have the minor comments already that I raised in the code. |
Oops, I had meant to say that I was done and would leave the changes for further inspection, but additionally merged it into master immediately. |
I think this was ready to merge anyways. |
This PR attempts to clean up the base linear algebra code.
General principles:
Exception
s in favor of genericerror()
messagesreturn
s and semicolons