Block argument syntax

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Block argument syntax

Eliot Miranda-2


On Fri, Mar 1, 2013 at 7:57 AM, Bert Freudenberg <[hidden email]> wrote:

On 2013-03-01, at 16:48, Chris Muller <[hidden email]> wrote:

>> I know this is true for a number of Smalltalk implementations.  I found it
>> very surprising also.  Someone I worked with always formatted their code
>> this way.  He said it made it easier to double click and highlight the
>> variable.  I wasn't sure that was enough reason to do it but he did.
>
> So, score +1 for ": x" but ":x" is still left with a score of 0.  What
> is the advantage of writing ":x"?

One char less. Better visual grouping of multiple arguments.

(1) [:a :b|a+b]
(2) [:a :b | a + b]
(3) [ :a :b | a + b ]
(4) [ : a : b | a + b ]

In my eyes, (2) is the best compromise between conciseness and readability.

For me it's

(5) [:a :b| a+b]

;)
 

- Bert -






--
best,
Eliot


Reply | Threaded
Open this post in threaded view
|

Re: Block argument syntax

John Brant-2
In reply to this post by Frank Shearar-3
On 3/1/2013 4:47 AM, Frank Shearar wrote:

> I was rather surprised to learn that the following is valid syntax:
>
>      [ : x | x + 1]
>
> (Note the space before the argument name.)
>
> In fact, this is too:
>
>      [ : "This is a really long comment in a very, very strange place.
> It makes it very hard to see that the : before this comment turns the
> token after this comment into a block argument." x | x + 1]


Not quite related, but in the VW/Squeak family, this is a valid symbol:

        # "I like to comment symbols" a

Depending on the font you use, it can be difficult to tell the
difference between these:

        #""''

        #'""'



John Brant

12