[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: another take on hackers and painters




On Thursday, May 22, 2003, at 03:58  PM, John Clements wrote:

>
> On Thursday, May 22, 2003, at 12:53  AM, Mike Lambert wrote:
>
>> The argument about 1 + "3" and what it should do isn't just a matter 
>> of
>> what to do with "3". There are two different questions to this 
>> problem.
>> One of which is being ignored and making the discussion a lot more
>> confusing than it needs to be, imo. :)
>>
>> A) Who provides the interpretation for the operator and the contexts 
>> for
>> the operands?
>> B) How do you handle the case of coercion to the required context?
>>
>> In typed languages, B is "you don't". This necessarily provides a lot 
>> more
>> freedom to A. A+B does different things depending upon whether the
>> operands are integers, strings, or floats. 1+1 returns 2, and "1"+"1"
>> returns "11". The interpretation of the operand uses the whole type 
>> system
>> to figure out which operand function is the desired one that matches 
>> the
>> operands.
>>
>> Now, try showing a dynamic typing system to a static typing person, 
>> and
>> they go crazy. "1+"3"? Insane, bugs will proliferate!" To a 
>> static-typing
>> programmer, 1+"3" is as confusing as "1"+"3" is to a dynamic 
>> programmer.
>> The main difference is that in dynamic typed languages, the answer to
>> question B above allows for type coercion to the types necessary for 
>> the
>> operands.
>
> Be careful.  The distinction you're talking about is largely 
> orthogonal to the dynamic vs. static typing issue.  Case in point: 
> Scheme is dynamically typed, but will not perform the coercion you're 
> describing.  At the opposite corner, there's no reason you can't have 
> a statically typed language with coercion.

... though I suppose coercion could really damage type inference.

Just to respond to myself.

john clements