Avdi Grimm wrote:
>> Because, unlike Java, Ruby is not a strongly typed language.
>
> To be pedantic, both Java and Ruby are strongly typed. However, Java
> is statically types, and Ruby is dynamically typed.
In a weakly-typed language, like C, it is possible to cast an integer
as a, for instance, a char*, and then call string functions like
sprintf() on it and the compiler will compile it, the runtime will run
it, and it will wreak whatever havoc you please. Most high-level
languages are strongly-typed, these days - neither Java or Ruby will
allow you to call a String method on an Integer. You can assign
whatever object you want to a variable in Ruby - hence *dynamic*
typing - but that object will only ever allow you to call supported
methods on it; otherwise you'll get a NoMethodError. Hence *strong*
typing.
···
On Mon, Apr 7, 2008 at 5:12 PM, Phillip Gawlowski <cmdjackryan@googlemail.com> wrote:
Ruby is?
Doesn't look like it to me, since I can change the type of a variable
with ease.
On Mon, Apr 7, 2008 at 5:12 PM, Phillip Gawlowski > <cmdjackryan@googlemail.com> wrote:
Ruby is?
Doesn't look like it to me, since I can change the type of a variable
with ease.
You're confusing static typing and strong typing.
In a weakly-typed language, like C, it is possible to cast an integer
as a, for instance, a char*, and then call string functions like
sprintf() on it and the compiler will compile it, the runtime will run
it, and it will wreak whatever havoc you please. Most high-level
languages are strongly-typed, these days - neither Java or Ruby will
allow you to call a String method on an Integer. You can assign
whatever object you want to a variable in Ruby - hence *dynamic*
typing - but that object will only ever allow you to call supported
methods on it; otherwise you'll get a NoMethodError. Hence *strong*
typing.
Another way to put it would be that Ruby's variables are type-less, while objects do have a specific type. While we're at it: type != class. Basically the type is defined by all operations (aka methods) usable on an instance - not the class it was created from.
Kind regards
robert
···
On 08.04.2008 00:53, Phillip Gawlowski wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Avdi Grimm wrote:
> On Mon, Apr 7, 2008 at 5:12 PM, Phillip Gawlowski > > <cmdjackryan@googlemail.com> wrote:
>> Ruby is?
>>
>> Doesn't look like it to me, since I can change the type of a variable
>> with ease.
>
> You're confusing static typing and strong typing.
>
> In a weakly-typed language, like C, it is possible to cast an integer
> as a, for instance, a char*, and then call string functions like
> sprintf() on it and the compiler will compile it, the runtime will run
> it, and it will wreak whatever havoc you please. Most high-level
> languages are strongly-typed, these days - neither Java or Ruby will
> allow you to call a String method on an Integer. You can assign
> whatever object you want to a variable in Ruby - hence *dynamic*
> typing - but that object will only ever allow you to call supported
> methods on it; otherwise you'll get a NoMethodError. Hence *strong*
> typing.
>