[squeak-dev] Re: Can i has underscores? :)

Juan Vuletich juan at jvuletich.org
Thu Apr 15 01:59:29 UTC 2010


Igor Stasenko wrote:
>
> Err.. let me tell you what will happen if i, say, add an instance
> variable to some basic class -
> it will recompile all subclasses. And when some of those methods could
> contain underscores as assignment,
> while some of them (a newer ones) could use underscores in
> selectors/identifiers.
>   

Shout has nothing to do with this. Shout is used by PluggableTextMorph 
when rendering code. So recompiling existing classes by adding ivars 
does nothing to the methods. They are left exactly as they were. 
Activating the #syntaxHighlightingAsYouTypeAnsiAssignment preference 
only affects how code is shown. If you save a method that was rendered 
converting all assignments to ':=', it will be saved that way.

> No matter what you choose in a system-wide preference, you won't be
> able to recompile the all classes.
> Will Shout be able to help me with that? :)
> It is obvious, that to prevent this from happening, all sources, which
> is going to the compiler, should
> use same syntax, or each class should have own #useUnderscores setting.
>   

Not at all. Just tried this:
Preference #allowUnderscoreAssignments set to true.
Preference #allowUnderscoreSelectors set to true.
Preference #syntaxHighlightingAsYouTypeAnsiAssignment set to true.

Then the following method uses underscores both in identifiers and 
assignments:
        test_underscore
            | a_a b_b c_c d_d_ |
            a_a _ 1.
            b_b := 2.
            "c_c _3." "Not possible. _3 is taken as an unary selector"
            "d_d_ 4" "Not possible. d_d_ is considered the varname"

And Shout renders it as:
        test_underscore
            | a_a b_b c_c d_d_ |
            a_a := 1.
            b_b := 2.
            "c_c _3." "Not possible. _3 is taken as an unary selector"
            "d_d_ 4" "Not possible. d_d_ is considered the varname"

Shout and the regular Parser can tell whether an underscore is an 
assignment or part of an identifier. The only problem is the ambiguity 
in lines with c_c and d_d_ variables, that I had to comment, as the 
second underscore in each of the is considered part of an identifier and 
not an assignment. That could cause problems with very few old methods 
that fail to include some whitespace before and after the assignment. 
But as the idea is to use Shout to render the methods, when you save one 
of these, you'll have to add that whitespace yourself.

> But that wouldn't help, if i add an instance variable with underscore
> in base class,
> while subclass will still insist on using underscores for assignment -
> then it will be unable to access that ivar
> in own methods :)
>
>   

Not true, as the example above shows.

Cheers,
Juan Vuletich



More information about the Squeak-dev mailing list