Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: Interesting read: "Why I use perl and still hate dynamic language weenies too" (heterogeneous lists)

by ikegami (Patriarch)
on Apr 17, 2007 at 16:15 UTC ( [id://610570]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Interesting read: "Why I use perl and still hate dynamic language weenies too"
in thread Interesting read: "Why I use perl and still hate dynamic language weenies too"

(I meant to include this in my previous post.)

One big difference is the ability to create heterogeneous lists with ease in untyped language. That allows us to create powerful general purpose functions. For example, compare

# "pack" in an untyped language. my $packed = pack('c N c/a*', $c, $i, $s); # "unpack" in an untyped language. my ($c, $i, $s) = unpack('c N c/a*', $packed);

vs

# "pack" in an typed language. Array<Object> unpacked; unpacked.push(c); unpacked.push(i); unpacked.push(s); String packed; pack(packed, "c N c/a*", unpacked); # "unpack" in a typed language. Array<Object> unpacked; unpack(packed, "c N c/a*", unpacked); char c = unpacked[0]; int i = unpacked[1]; String s = unpacked[2];

I don't care so much about the difference in *code size*. The size is not that much different. (80% seems ridiculous.) In fact, the code is not that much different. The real difference is in the amount of *hassle*. Almost all of the extra code needed in a typed language is very repetitive.

In order to hide the extra code and avoid more hassle, you end up creating (repetitive) special-purpose functions as shown below. Of course, this is a hassle as well.

# "pack" in a typed language. Func pack_my_format(String& packed, char c, int i, String s) { Array<Object> unpacked; unpacked.push(c); unpacked.push(i); unpacked.push(s); pack(packed, "c N c/a*", unpacked); } pack_my_format(String packed, c, i, s); # "unpack" in a typed language. Func unpack_my_format(String packed, char& c, int& i, String& s) { Array<Object> unpacked; unpack(packed, "c N c/a*", unpacked); c = unpacked[0]; i = unpacked[1]; s = unpacked[2]; } unpack_my_format(packed, char c, int i, String s);

Note: For the typed language, I used a mixture of C, C++, Java, Pascal and Perl that keeps the code as small as possible. Features include implicit type conversion, autoboxing, object allocation without "new", no separation of variable declarations and code, templates or generics, a Variant type, etc.

  • Comment on Re^5: Interesting read: "Why I use perl and still hate dynamic language weenies too" (heterogeneous lists)
  • Select or Download Code

Replies are listed 'Best First'.
Re^6: Interesting read: "Why I use perl and still hate dynamic language weenies too" (heterogeneous lists)
by TimToady (Parson) on Apr 17, 2007 at 18:37 UTC
    No question that typed languages often put you through hassles that dynamic languages don't, but I think you have to give at least some typed languages some credit for being structurally typed, which makes pack and unpack look more like:
    $packed = $obj.freeze; $obj = $packed.thaw;
Re^6: Interesting read: "Why I use perl and still hate dynamic language weenies too"
by dewey (Pilgrim) on Apr 17, 2007 at 16:47 UTC
    When you talk about an "untyped" language such as Perl, I think what you really mean is "uni-typed". There is only one type, the tagged scalar. This can be tagged as a regular scalar or as a reference and used in various ways, but at heart there is only one type in the language. That's why pack knows what to do with any value you throw at it; it takes a list of tagged scalars and creates a string according the the tags and values.

    When you make a "general-purpose" function in a typed language with a powerful type system, you can have all of the convenience of a uni-typed language and the compile-time checking of a typed language. For an example,see Haskell/Existentially quantified types.

    Bottom line, it seems to me that the problems we Perlish people have with static languages come from the fact that many type systems are not as rich as they should be (C, Java). From what I've seen, ML and Haskell are moving toward the flexibility we need.

    ~dewey
      There is only one type, the tagged scalar.

      Your programs are about to get a lot more useful; Perl supports arrays and hashes too!

        What?? My life just got so much easier! ;)

        But seriously, if I'm confused about this maybe you can clear it up. Is Perl statically typed, dynamically typed, or some crazy other thing that I don't know about?

        Perl does "support arrays and hashes", but I was always under the impression that this was a run-time check on tagged values (dynamic) rather than a compile-time check on untagged values (static). Are we saying that Perl is statically typed, where the types are scalar, hash, and array? If it's truly dynamically typed, how can these distinctions arise?

        Thanks for your help.

        ~dewey

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://610570]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-18 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found