Not in direct reply, but I thought I'd chime in...
I've been using MiniD for the last few months, which has a few features that languages like Python and Ruby don't have. It has (dynamic) argument type checking, which catches a lot of dumb typing errors and allows for nullable types; true namespaces and modules; and the parser is very strict about statements, expressions and general syntax. These add up to much better error messages and fewer silly mistakes, while still having a completely dynamic runtime. For example:
function foo( bar, baz: array|null ) { this.( bar )( baz ) // .() is MiniD's "perform", or "send" }
The choice to use type-checking is yours. If you want to use duck typing, don't give it a
type. My next choice is Dylan, but it was not as dynamic, or should i say reflective, as I needed.
Mike
From: John Cowan <cowan@...> To: langsmiths@yahoogroups.com Sent: Tuesday, June 23, 2009 2:25:48 PM Subject: Re: [langsmiths] Re: Duck typing and errors
Brian Hurt scripsit:
> No, the big advantage of static typing is development time. First of all,
> static typing drastically reduces the number of unit tests you need-
> responsibility for the correctness of many of the constraints that unit
> tests are checking can instead be ensured automatically by the type
> system.
That's a big advantage for supporting static typing, but not a big
advantage for requiring it. Nor is it an advantage particular to static
typing as opposed to any other sort of compile-time declaration system.
> As an example of what I mean by this, note in the example code
> I tossed off I casually introduced the FieldName.t type, which
> (obviously) represents a field name. The underlying representation
> of this type is probably just a string- but by controlling when and
> how field names can be created, I can enforce generic constraints.
> For example, already it's an error if you accidentally reverse the
> field name and field values.
This is a consideration orthogonal to static vs. dynamic typing: what
I will call generic vs. specific types. It's perfectly reasonable in a
dynamically typed language to put the field name into a specific type,
which provides the same type safety at run time that the statically
typed version does at compile time. Furthermore, there is nothing about
a statically typed language that prevents an API designer from using a
generic type such as String to represent a field name.
It may be true that dynamically- typed-language programmers are more
likely to use generic types, as a result of the easy availability
of type-heterogeneous containers such as lists and dictionaries.
What's more, few languages (CL is the exception here) provide syntax
for literals of specifically typed objects.
> But you can go further than that. I might not let arbitrary strings be
> converted into field names, I might only allow the database interface to
> create field names- and have some function where given a table, you can
> produce the list of FieldName.t' s that represent that table's fields.
> This way I gaurentee that a field name is a valid field name of at least
> some table. With phantom types and some trickery I can even gaurentee, in
> the type system, that the field names are valid for the table being
> selected against.
This of course is very straightforward in a dynamically typed language
by writing your own checking routines, if indeed you need them. You have
a Turing-complete engine, so use it.
> Over the course of say, a thousand bugs, that' s 83 working hours,
> or over two weeks of time lost.
If you have a thousand bugs of the kind a type system can catch, by all
means use it.
> You could make a dynamically typed system with variant types and pattern
> matching, but I've yet to see it.
The Scheme "match" macro does exactly that, and so does Q/Pure, which are
based on generalized term rewriting.
I've been working on my language again lately and playing around with argument type checking, protocols and multi-methods. I find it can be helpful to find...
... I use Python which is also a duck typing language. In my experience the missing type check at the beginning of a function/method poses no big problems. You...
... The other realm where lack of type chcking becomes problematic is where an instance variable gets populated with a object of the wrong type in the...
Hi all I don't think I have posted to this list, but I have some comments about Duck Typing and errors in Python code in particular. For background, I have a...
... I'll take this a step further and assert that: 1) If they're problems, they should be fixed even if they're not technically "bugs"- things are that...
... If type inference is done on the basis of messages that an object can receive, what happens when via message forwarding* every object can validly receive...
This is certainly true -- dynamic typing's strengths are more than just duck typing. Programatically extending types at runtime (a la Rails's ActiveRecord) and...
Robert Fischer
robert.fischer@...
Jun 23, 2009 12:23 pm
... I think I'm going to argue that. Dynamic typing's main strengths are 1. Algol-68 type systems are exceeding limited and broken (and this was known in...
... Static typing is inherently more restrictive than dynamic typing. That is, there are well-typed programs that any decidable static type system will reject....
... By definition, yes. ... Not just performance. Actually, the performance advantage is minor at best- and can be offset by other things. For example, it's...
This is an obvious case for polymorphism, so an object would provide its own to_sql implementation. If you didn't want to do that, the Groovy code could look...
Robert Fischer
robert.fischer@...
Jun 23, 2009 5:43 pm
... So the question then becomes why did ActiveRecord go with monkey patching instead of this route? Note that this exact same solution also works nicely for...
You misunderstand what's going on. An ActiveRecord class starts out life looking like this: class Foo < ActiveRecord::Base end That's it. It delegates the...
Robert Fischer
robert.fischer@...
Jun 23, 2009 9:29 pm
... I think I actually disagree here. The top one is shorter, granted- but I don't think it's more readable. Or rather, I don't think it's more readable *in...
This is a key culture difference between dynamic and static type communities -- static type communities want any tiny snippet of code to be obvious without...
Robert Fischer
robert.fischer@...
Jun 23, 2009 11:59 pm
... The obvious point to make here being that the former is always better than the latter provided that all other things are equal. - John...
John Nowak
john@...
Jun 24, 2009 12:24 am
... Without looking it up, can you tell me what the functions 'bind' and 'return' do? How about 'cata' or 'hylo'? Or 'appEndo'? Or 'runKleisli'? The...
John Nowak
john@...
Jun 24, 2009 12:00 am
... How is that more "static-friendly"? Why not just offer a selection function that takes a list of items to use to descend the tree: select : List String ->...
John Nowak
john@...
Jun 24, 2009 12:19 am
... That's a big advantage for supporting static typing, but not a big advantage for requiring it. Nor is it an advantage particular to static typing as...
... The advantage to requiring it I've dealt with in another email. ... Any system of checked metadata about code is a type system. ... What's the advantage of...
Not in direct reply, but I thought I'd chime in... I've been using MiniD for the last few months, which has a few features that languages like Python and Ruby...
That's the way Groovy works, too, and I'm a fan of that optional static typing. ~~ Robert. ... -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised...
Robert Fischer
robert.fischer@...
Jun 24, 2009 2:06 am
... Objective-C does this as well. Personally, I would prefer protocol checking to type checking as any notion of type as it refers to a implementation (as it...
... Define "validly receive every message". The only thing you can validly do for *every* message is just throw an exception. Otherwise you have to either...
Examples of things I can do if I accept any message: navigate an XML document, build a JSON object. ...
Robert Fischer
robert.fischer@...
Jun 23, 2009 3:31 pm
... Suppose I have a object which can proxy any message across a network. At compile time, the compiler has no way of knowing what the object on the other side...