[nem-en] 0000898: 'int' treated as an identifier evenifusedwithout verbatim specifier (@)

vc vc at rsdn.ru
Tue Feb 20 20:54:48 CET 2007


> In general this is useful to redefine constant variables:
> 
> def x = "1,2,3";
> def x = x.Split (',');
> def x = x.Map (int.Parse);
> def x = x.FoldLeft (0, _ + _);

1. Useful it's good, but error prone is bad.
I too much use C++ and for me redefinition no problem. But for many people
this can be issues.

2. It example is better looks like this:
def x = "1,2,3"
   .Split (',');
   .Map (int.Parse);
   .FoldLeft (0, _ + _);
or
def x = "1,2,3".Split (',').Map (int.Parse).FoldLeft (0, _ + _);

3. If it will be looks like this:
def   x = "1,2,3";
redef x = x.Split (',');
redef x = x.Map (int.Parse);
redef x = x.FoldLeft (0, _ + _);
we lose nothing in expressiveness, and win in protection from the fool.

> In case of redefining type name... this is quite common also in C#

In C# int, string and so on is keywords. But, you right. In general case it
is true.

>  and
> adding new type names should not in general break code using their
> names as variable names:
> 
> create code:
> ///
> def  Foo = "aa";
> ///
> 
> then after a week add:
> ///
> class Foo { }
> ///
> 
> --->  oh, we now get compile error in weird places, which does not
> have any connection with Foo

OK, but in case "| x as y" we should warn user and propose the decision of a
problem.




More information about the devel-en mailing list