|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
Another formatting question: function typesHi All,
I wanted to take the community's temperature on how they prefer to see function types formatted. I have three questions. 1. Do you want spaces around the => or not? Here is with spaces: (String, Int) => Unit Here is without: (String, Int)=>Unit 2. If a type has arity 1, do you want parens around it or not? Here it is with parens: (String) => Unit Here it is without: String => Unit 3. Lastly, anything else you like to see? Thanks. Bill ---- Bill Venners Artima, Inc. http://www.artima.com |
|
|
Re: Another formatting question: function types1: With the spaces
2: Either is legible, without the spaces is cleaner. On Wed, Jun 10, 2009 at 12:56 PM, Bill Venners<bill@...> wrote: > Hi All, > > I wanted to take the community's temperature on how they prefer to see > function types formatted. I have three questions. > > 1. Do you want spaces around the => or not? Here is with spaces: > > (String, Int) => Unit > > Here is without: > > (String, Int)=>Unit > > 2. If a type has arity 1, do you want parens around it or not? Here it > is with parens: > > (String) => Unit > > Here it is without: > > String => Unit > > 3. Lastly, anything else you like to see? > > Thanks. > > Bill > ---- > Bill Venners > Artima, Inc. > http://www.artima.com > |
|
|
Re: Another formatting question: function typesI've been writing
On Wed, Jun 10, 2009 at 11:56:35AM -0700, Bill Venners said > 1. Do you want spaces around the => or not? Here is with spaces: > > (String, Int) => Unit this > Here it is without: > > String => Unit and this > 3. Lastly, anything else you like to see? Prerences for by-name parameters too: =>Foo vs => Foo Curiously I have a slight preference for no space here, even though I use one for other function types. > > Thanks. > > Bill > ---- > Bill Venners > Artima, Inc. > http://www.artima.com |
|
|
Re: Another formatting question: function typesSpaces and Parens.
Spaces for legibility. Parens, cause I think of them as tuples, its an SML thing. () 0-tuple (String) 1-tuple (String, Int) 2-tuple On Wed, Jun 10, 2009 at 2:56 PM, Bill Venners <bill@...> wrote: Hi All, |
|
|
Re: Another formatting question: function typesSpaces and parens too. It might get weird if the result is a tuple of the same arity as the function, but...
On Wed, Jun 10, 2009 at 3:56 PM, Bill Venners <bill@...> wrote: Hi All, -- Daniel C. Sobral Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value. |
|
|
Re: Another formatting question: function types1. Without spaces
2. Without parens For example: String=>Unit (String, Int)=>Unit I think this makes it a little cleaner without taking up too much space. Also, I think it makes type annotations a bit easier to read. For example: val foo: String=>Unit = ... vs. val foo: String => Unit = ... The extra spaces require a little more effort to parse (at least to my eye). Rather than relying on spacing to delineate value, type and expression, I have to actually look at "=>" vs "=", symbols which have comparatively little visual distinction. As a matter of interest, when programming Haskell or SML, I do prefer the spaces syntax: -- Haskell foldl :: (b -> a -> b) -> b -> List a -> b (* SML *) fun foldl f : (('b, 'a) -> 'b) init : 'b ls : ('a list) = ... I'm not quite sure why I find the spaces better in Haskell/SML and not in Scala, but there it is. Daniel
|
|
|
Re: Another formatting question: function typesCorrection, that should have been:
fun foldl f : (('b * 'a) -> 'b) init : 'b ls : ('a list) = ... ...for all five of you who care. :-) Daniel
|
|
|
Re: Another formatting question: function types1. With spaces.
2. Without parens. 3. We need to figure out keyword and default argument formatting. The Python style guide PEP-8 has no spaces around default arguments. http://www.python.org/dev/peps/pep-0008/ - Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value. Yes: def complex(real, imag=0.0): return magic(r=real, i=imag) No: def complex(real, imag = 0.0): return magic(r = real, i = imag) Blair Bill Venners wrote: > Hi All, > > I wanted to take the community's temperature on how they prefer to see > function types formatted. I have three questions. > > 1. Do you want spaces around the => or not? Here is with spaces: > > (String, Int) => Unit > > Here is without: > > (String, Int)=>Unit > > 2. If a type has arity 1, do you want parens around it or not? Here it > is with parens: > > (String) => Unit > > Here it is without: > > String => Unit > > 3. Lastly, anything else you like to see? > > Thanks. > > Bill > ---- > Bill Venners > Artima, Inc. > http://www.artima.com > |
| Free embeddable forum powered by Nabble | Forum Help |