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

where {T} vs where T #53

Closed
odow opened this issue Sep 11, 2019 · 4 comments
Closed

where {T} vs where T #53

odow opened this issue Sep 11, 2019 · 4 comments
Labels
decision Uncertain if a change is warranted

Comments

@odow
Copy link
Contributor

odow commented Sep 11, 2019

Following https://github.com/jrevels/YASGuide#other-syntax-guidelines, I propose that all occurrences of where T are replaced with where {T}.

This makes things clearer, and unifies the syntax with more complicated where statements (e.g., with multiple terms) which require {}.

Bad:

function foo(x::T) where T <: Integer
    return 2x
end

Good:

function foo(x::T) where {T <: Integer}
    return 2x
end

p.s. very cool. Thanks for working on this.

Edit: to make the point more explicit:

Also Bad:

function foo(x::T) where T
    return 2x
end

bar(x::T) where T = 2x

Good:

function foo(x::T) where {T}
    return 2x
end

bar(x::T) where {T} = 2x
@StefanKarpinski
Copy link
Contributor

What about where T but where {T <: Integer}. There is a slight wrinkle that people prefer the { } version in the one-line case:

foo(x::T) where T = 2x # confusing
foo(x::T) where {T} = 2x # clearer

So a possible rule would be this:

  • no braces in long form function definition when the where clause is just a single typevar
  • otherwise always enclose in braces

@odow
Copy link
Contributor Author

odow commented Sep 11, 2019

The fewer special exceptions the better.

For the sake of two characters, instead of having to remember (and code, maintain, etc) if long form and single type var, it's just "Always enclose in braces."

@domluna domluna added the decision Uncertain if a change is warranted label Sep 12, 2019
@StefanKarpinski
Copy link
Contributor

Surveying Base Julia, the vast majority of even multiline function definitions with just a single name after the where use curly braces, so it seems like people are fine to just use them consistently.

@domluna
Copy link
Owner

domluna commented Sep 14, 2019

Added this in 8944eaa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision Uncertain if a change is warranted
Projects
None yet
Development

No branches or pull requests

3 participants