in reply to Re^14: use fields; # damnit
in thread use fields; # damnit
It's interesting to compare tha various definitions of both what "strongly typed" means, and how Perl typing system is characterised by various people with the "industry standard definitions" of that term.
Personally, I find it a stretch to consider a language that has only one type (plus two conglomorates) as strongly typed. I find there to be very little difference between "one type" and "no types".
Assembler has no types--just memory and pointers to memory. Any pointer can point to memory containing anything. And any piece of memory (regardless of what it contains) can be treated as anything, including a pointer to anything.
Perl has only one type: Scalars, plus two conglorates: hashes of scalars and arrays of scalars. And a scalar be used to contain any type of data: characters, integers, reals, strings, and references to anything. Often it contains many of these simulataneously.
Whilst I can't fault your four levels of type definition, using the phrase "a strongly typed language" to describe Perl, given the industry accepted definition of that phrase, is something of a stretch.
Of course, I'm not necessarially agreeing with that particular definition entirely, and I totally disagree that (all) langauges traditionally defined as being "strongly typed" actually meet that definition. More to the point, even those that do meet that definition rarely, if ever, deliver the kinds of benefits that "management" have been led to expect of them, by such definitions.
Ultimately, I think that contextual typing is the most powerful (and maybe revolutionary) concept in perl. It won't really come to fruition until perl 6 hits the streets with it's enhanced contextual information, but it will be very interesting to see how things evolve once it does.
The very idea that I can be passed some entity and assign it to a local variable defined as some type and the entity itself (or rather the author of the entity) can decide to give me the appropriate representation of that entity to fit my requirements--or raise an exception if it doesn't know how to convert itself to my requirements is just so powerful.
Rather than me, the user of the entity trying to decide how to perform the conversion to the type I need, context moves that responsibility back to the author of the entity where it belongs.
I'm not yet sure that this idea will be taken to it's full potential even with Perl 6. If I try to assign a scalar given to me to a variable defined as my int $x; (on a 32-bit platform) and the scalar contains '5e10', what will P6 do? Will the enhance want function notice the discrepancy?
What if I try my Animal $beast = new Dog( ... );? I could see the possibility of want detecting the caller context as Animal and allowing the author of the Dog module to provide a return of the Animal instance (reference) that underlies the Dog instance regardless of whether Dog inherits from Animal or is composed from Animal and one or more other Classes. I guess you could do this now by providing a Dog::getAnimal method.
Perl already has this kind of context awarness to a certain level. If you use a reference in a scalar context, it gives you a textual representation of the reference. If you use [cpna://overload], you can tweak this to provide a more meaningful representation without the need to call an asString() method explicitly.
Finding uses for such an extension of the context information isn't at all hard. For example: A Dog in a Dog context might sort according to its bred, but in an Animal context it might sort according to it's genus (Is that the right term?).
And yes. I rambled. And no, I'm not critiquing your post. Just adding my rambling thoughts to the mix.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^16: use fields; # damnit
by Aristotle (Chancellor) on Aug 21, 2004 at 23:54 UTC | |
by BrowserUk (Patriarch) on Aug 22, 2004 at 00:56 UTC | |
by Aristotle (Chancellor) on Aug 22, 2004 at 09:18 UTC |