Re: [scala-language] Annoyed by //

116 views
Skip to first unread message

ARKBAN

unread,
Apr 27, 2012, 12:52:08 PM4/27/12
to scala-...@googlegroups.com
(Corrected the email address to scala-debate)

> Although you will agree that learning the line comment syntax is not
> particularly hard,

I do agree, I was attempting to point out the non-trivial mental cost of
switching back and forth between languages' and keeping their
idiosyncrasies straight. This is important when you consider Scala
advocacy -- familiar syntax helps newbies.

For a real world example, look at PHP and its infuriating use of "." as
a string concatenation operator; pretty much every time I or anyone on
my team has to jump into PHP we screw up and write "+" a few times until
we hit a runtime error. Then we waste time going back and fixing all the
operators, and it does not leave us with a good impression of PHP.

If // were an extremely common operator I'd be much more in favor of
breaking consistency. But it doesn't sound like // is going to be the
next hot operator anytime soon. Honestly if you want to choose a better
comment character, I'd suggest considering # for consistency with
Python, Ruby, Shell scripts, etc. (Also I think on some keyboards with
larger Enter keys the \ character is moved around to various places.)

ARKBAN

On 4/26/12 5:06 PM, Alex Repain wrote:
> 2012/4/26, ARKBAN<ark...@arkban.net>:
>> > I hate that // is the single line comment, probably, we all do.
>>
>> I, for one, am very happy that the single line comment is consistent
>> with other C-like languages. It is one less thing to learn when
>> switching languages, and one more less hurdle for new Scala developers.
>>
> Although you will agree that learning the line comment syntax is not
> particularly hard, in Scala or in any other (practicable) language.
> This could have been an idea worth discussing ... years ago, when the
> language was fresh and would possibly evolve abruptly in its core
> syntax. Now it's just how it is. If you definitely want to use //, try
> escaping it with backquotes :
>
> scala> def `//`(i: Int) = 2 * i
>
> $div$div: (i: Int)Int
>
> scala> $div$div(3)
>
> res0: Int = 6
>
> scala> `//`(3)
>
> res1: Int = 6
>
>> ARKBAN
>>
>> On 4/26/12 2:25 PM, Daniel Sobral wrote:
>>> I'd be annoyed if // was not single line comment.
>>>
>>> On Thu, Apr 26, 2012 at 14:56, Rodrigo Cano<ioni...@gmail.com> wrote:
>>>> Hi there,
>>>>
>>>> Here is the issue (and I know all the reasons for it to be like it is,
>>>> and
>>>> that I'm probably be discarded right away, anyway I wanted to share :-)
>>>> ), I
>>>> hate that // is the single line comment, probably, we all do. Any
>>>> respectable path uses / as separator, unix paths, xpath, urls, sed,
>>>> anything. If I would write a path-like thing now, I would use / as
>>>> separator. The thing is that the // is almost always assigned a meaning
>>>> too,
>>>> but we are restricted in scala from having it as an operator.
>>>> In order to propose something with meaning that could potentially justify
>>>> making such big change, it occurred to me that I have to suggest
>>>> something
>>>> that gives more punctuation freedom, and I came to think of one
>>>> punctuation
>>>> symbol which we already cannot use, and that in fact, we never use
>>>> (because
>>>> it's bad taste :-P), the `;`, practically we never use it, so nobody
>>>> would
>>>> mind if `;;` would be the single line comment, after all, it even makes
>>>> no
>>>> sense (that it occurs to me now) to write ;; in scala. I can't think of a
>>>> case were I would like to write an empty statement like that.
>>>>
>>>> With such change, we really gain in syntax freedom I think. What are your
>>>> opinions?.
>>>>
>>>> Cheers.
>>>
>

Michael Schmitz

unread,
Apr 27, 2012, 12:55:07 PM4/27/12
to ARKBAN, scala-...@googlegroups.com
I hate plus (+) as a string concatenation operator.  It's definitely tripped me up more than a few times since it's overloaded with addition.  This comment isn't supposed to be constructive and I'm OK with the status quo however ;-)

Raoul Duke

unread,
Apr 27, 2012, 1:35:13 PM4/27/12
to scala-...@googlegroups.com
On Fri, Apr 27, 2012 at 9:52 AM, ARKBAN <ark...@arkban.net> wrote:
> For a real world example, look at PHP and its infuriating use of "." as a
> string concatenation operator

ah hah! your problem is that you are using PHP instead of Haxe to
generate PHP ;-)

ARKBAN

unread,
Apr 27, 2012, 1:37:30 PM4/27/12
to scala-...@googlegroups.com
Actually we're in the process of jettisoning all our PHP and replacing
it all with Lift : )

Patrick

Russ P.

unread,
Apr 27, 2012, 4:12:43 PM4/27/12
to scala-debate
On Apr 27, 9:52 am, ARKBAN <ark...@arkban.net> wrote:
> (Corrected the email address to scala-debate)
>
> >  Although you will agree that learning the line comment syntax is not
> >  particularly hard,

Yeah, I learned it in less than three months, but then again I'm a
fast learner.

> If // were an extremely common operator I'd be much more in favor of
> breaking consistency. But it doesn't sound like // is going to be the
> next hot operator anytime soon. Honestly if you want to choose a better
> comment character, I'd suggest considering # for consistency with
> Python, Ruby, Shell scripts, etc. (Also I think on some keyboards with
> larger Enter keys the \ character is moved around to various places.)

I'd be all for allowing # as an alternative comment marker, but
unfortunately I think it's already used for something else.

--Russ P.

Rodrigo Cano

unread,
Apr 27, 2012, 4:13:53 PM4/27/12
to Russ P., scala-debate
The whole point of even suggesting another comment marker, in my opinion, is freeing up other characters, using # would incur in the same sins as //

ARKBAN

unread,
Apr 27, 2012, 4:29:33 PM4/27/12
to scala-...@googlegroups.com
I was attempting to follow in the footsteps of someone else who suggested replacing // with \\. You are always going to loose a character or 2, its just a matter of which ones do you want to loose?

ARKBAN

Rodrigo Cano

unread,
Apr 27, 2012, 4:53:35 PM4/27/12
to ARKBAN, scala-...@googlegroups.com
Not with the ; since you already cannot use it.

Tony Morris

unread,
Apr 27, 2012, 9:58:11 PM4/27/12
to Michael Schmitz, ARKBAN, scala-...@googlegroups.com

Indeed (+) denotes abelian monoid, of which string concat is not. These discussions are epic.

Philip Panyukov

unread,
May 1, 2012, 4:15:36 AM5/1/12
to Russ P., scala-debate
On a Mac keyboard the # is a royal pain, as it's not marked on keyboard and is hidden under ALT+3, at least on the so-called "British" layout. It always takes me three tries to get it right when I need it.

Sent from my iPhone

Alex Repain

unread,
May 1, 2012, 8:33:47 AM5/1/12
to Tony Morris, Michael Schmitz, ARKBAN, scala-...@googlegroups.com
2012/4/28, Tony Morris <tonym...@gmail.com>:
> Indeed (+) denotes abelian monoid, of which string concat is not. These
> discussions are epic.

What if you consider not the category of strings, but of sets of
strings of given length i ?
object set : {Li = {s / s.length = i}, i in [0, +inf[}. It is
isomorphic to (N+, +). Let's define |+| on this category as :

Li |+| Lj = L(i+j)

then for two strings a, b, (a + b) can be decomposed with |+| and some
magical functions :

+ : (String, String) -> (Set[String], Set[String]) -> Set[String] -> String
(a + b) = chooseAnElement(lengthSet(a) |+| lengthSet(b))

So there actually is some abelian monoid binary op going on, under the
hood. It''s just not fully carrying the semantics of concatenation
(i.e., chooseAnElement, which requires to recall a and b, not only
their length sets).

Not that it strictly justifies the use of '+' as a concat operator,
but well, it could be worse. The only obstacle to strictly identifying
'+' as an bin op of an abelian monoid is commutativity, and this is
violated by so many other types in Scala (collections ?).
--
*Alex REPAIN*
Computer Science Engineer
Scala-enthusiast

Philippe Lhoste

unread,
May 2, 2012, 6:43:28 AM5/2/12
to scala-...@googlegroups.com
On 01/05/2012 10:15, Philip Panyukov wrote:
> On a Mac keyboard the # is a royal pain, as it's not marked on keyboard and is hidden
> under ALT+3, at least on the so-called "British" layout. It always takes me three tries
> to get it right when I need it.

Ditto on a French keyboard. And \ isn't better, as it 'hides' under AltGr+8.
But so are []{}| and some others, so we are biting the bullet and code anyway... :-)

--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

Reply all
Reply to author
Forward
0 new messages