| Betreff: | Re: [scala-user] benefit of dynamic typing? |
|---|---|
| Datum: | Tue, 08 Feb 2011 22:50:37 +0100 |
| Von: | HamsterofDeath <h-s...@gmx.de> |
| An: | Jim Powers <j...@casapowers.com> |
i do not see an advantage. you have to magically know that the row-instance you are working on has bar, baz and goo. you also have to magically know what the types of these attributes are to be able to properly work with them. there is no difference to a construct like this:Rails ActiveRecord - Active record creates objects on the fly with attributes (getters and setters) based on "what came back" from a SQL query.
For instance:
If I instantiate an AR object tied to the following SQL:
SELECT bar, baz FROM foo
My resulting AR objects will respond to bar and baz:
row = Foo.find(...)row.bar # worksrow.baz # works
Now, say you use the following SQL
SELECT bar, baz, <computed expression> goo FROM foo
row = Foo.find(...)row.bar # worksrow.baz # worksrow.goo # works!
No doubt.
I'm guessing that the mailing list is probably not super-interested in
a protracted "discussion" of this issue ;-), so I'll let this be my
last response on the issue:
RE: "What I thought was a Foo was actually a Goo"
Yup, moving (some) compile time checking to run-time. Although I do
fully understand the trade-offs a considerable amount of this kind of
coding happens all the time. Typically, incorrectly thinking you have
a Foo when you have a Goo, really only matters if a Goo does not
respond to the same messages (protocol) as a Foo. Often beyond that
it doesn't matter. It's called "duck-typing" and is rather common.
In many cases (especially expressing the results of SQL queries in
"another" language) what you call "a thing" (it's type) doesn't really
matter. All that matters is that it responds to the "messages" I send
it (Ruby really is just a MPI kind of language). Whether this is or
is not an advantage I guess depends on your point of view: quite a lot
of code gets written this way, considerably more than the code written
in Scala, Haskell, Clean, SML, OCaml, etc. Popularity is not a
"deciding" metric on it's own, but I would guess that dynamically
typed languages just seem more approachable. On the other hand
statically typed languages help the programmer state up-front all the
entities under consideration.
RE: data-flow analysis
Hrm. I must admit that I still struggle with Scala's type system.
Although I can use a number of features in Scalaz, for instance, I'm
not 100% clear on how all it works. For example, things like this:
https://gist.github.com/66925 are nowhere immediately obvious pieces
of code. I find myself in the REPL trying my darnedest to figure out
what the compiler is doing. I find it frustrating unraveling that
kind of data flow analysis. And as Tony and others on the Scalaz team
have pointed out sometimes, if you're not completely clear, the
compiler will resolve the type constraints with a different type than
you expect. I also do understand that this is due to the limitations
of the Scala language and type system, but ferreting out what's going
on is equally daunting, and typically not straight-forward.
--
Jim Powers
When the most of your code works with external systems - for instance
web-services, than the point of runtime failure is an external system,
and compiler checks for the typing correctness of the program checks
actually nothing, because you'll get runtime type error anyway, and
there is nothing you can do with it. So if the static typing can't grant
anything anyway - why bother with asInstanceOf[]?
Another reason that only part (which is not the one you're using) could
be altered - for the dynamic language it's fine. Imaging if
bash-scripting was statically typed. In this case scripts should be
"compiled" against very particular versions of utilities. If something
changes in 'ls' - go 'recompile' your scripts. For the small scripting
purposes or integration purposes dynamic typing is good not because it
has some particular advantages over static typing, but because static
typing has disadvantages in this case - too much checks those grant nothing.
--
Best Regards,
Volodymyr Kyrychenko
Web applications. The reason is that they interact with a user over
HTTP, creating HTML, and reading from a database. All these operations
are not type safe. The application then needs to do a lot of conversion
/ reflection. It doesn't matter whether this is done in a static/dynamic
languages. The dynamic languages are more oriented towards dealing with
untyped data.
Ittay
> HamsterofDeath wrote:
> > so even in the example you provided, i'd prefer the statically typed
> > version because its time bomb goes off sooner.
>
> When the most of your code works with external systems - for instance
> web-services, than the point of runtime failure is an external system,
> and compiler checks for the typing correctness of the program checks
> actually nothing, because you'll get runtime type error anyway, and
> there is nothing you can do with it. So if the static typing can't grant
> anything anyway - why bother with asInstanceOf[]?
i see similarities to "null vs Option[Type]" here. null is simpler, but can become time bomb and explode at a random time when you actually try to access the object which makes it more difficult to find the source of the problem. explicitly checking as soon as possible acts as a guard against this.
>
> Another reason that only part (which is not the one you're using) could
> be altered - for the dynamic language it's fine. Imaging if
> bash-scripting was statically typed. In this case scripts should be
> "compiled" against very particular versions of utilities. If something
> changes in 'ls' - go 'recompile' your scripts. For the small scripting
> purposes or integration purposes dynamic typing is good not because it
> has some particular advantages over static typing, but because static
> typing has disadvantages in this case - too much checks those grant
> nothing.
i see. so basically, "dynamic typing" means "i know more than the compiler does." i thought about this. imho, a hybrid would be best. for example Finder.find("select a,b,c from x") should return a TupleN with correct generic type parameters. the compiler should be able to understand the given sql statement and construct a class/type from it, so the benefits of static typing (code completion ftw) can be used as well as multiple return types.
There is no such thing as "untyped data."
> Ittay
Randall Schulz
>> I often find myself wishing I could build new combinations of traits at runtime and create an instance from them.
What exactly do you mean by that? Something like an anonymous class? Do you imply that you don’t know the traits you want to mixin until you actually run?
Razvan
one step further:
you don't know at compile time if it will be the UpperCase- or ReverseNames-trait.
-------- Original-Nachricht --------
> Datum: Wed, 9 Feb 2011 11:03:03 -0500
> Von: "Razvan Cojocaru" <p...@razie.com>
> An: "\'Ivan Porto Carrero\'" <iv...@mojolly.com>, scala...@googlegroups.com
> Betreff: RE: Re: [scala-user] benefit of dynamic typing?
Yup. It's surprisingly useful.
Run-time? Compile-time? What's the difference? It's all "computer
time". If you like all the uber type stuff, then cool. Make it so
the the compiler is available at run-time (in an easy fashion, yes I
use one of the numerous hacks out there to use the Scala compiler at
run-time) and have it do the incremental type-check magic. It's all
good.
--
Jim Powers
can you combine scala and groovy? if yes, the problem might be solved already :)
i'll check that later
-------- Original-Nachricht --------
> Datum: Wed, 09 Feb 2011 17:14:30 +0100
> Von: "Dennis Haupt" <h-s...@gmx.de>
> An: "Razvan Cojocaru" <p...@razie.com>, scala...@googlegroups.com, iv...@mojolly.com
> Betreff: Re: RE: Re: [scala-user] benefit of dynamic typing?
Right... but I believe null is not a timebomb, but some kind of dynamic type. It is a pretty legitimate implementation of Option; the problem is that then all we do we do, often unknowingly, within a monad, and this makes what we do opaque to both us and the compiler; in explicit Option there's no way we would mix a pure value with a partial value.
Although Tony Hoare's sentiments are laudable, they primarily stem
from the chaos "NULL" references cause in languages like
C/C++/Pascal/etc. where there is little abstraction of the machine in
question and the runtime is impotent to always "safely" handle "null"
pointers, or pointers into arbitrary memory for that matter. Java's
null is about as harmless as Lisp's nil (or Scala's None).
--
Jim Powers
Basically dynamic wiring of the objects or flow or whathaveyou may make sense but building new types at runtime - I still don't see how arbitrarily mixing in traits *at runtime* can amount to something useful... I hear you but I don't see it. Anyone has an example?
Runtime vs compiletime - I'm not there when the program runs, that's the difference :) so that "you screwed up" exception at 2am ain't that useful.
Hey, I'm not arguing that it's completely useless - I don't see a good example. I haven't seen a good example so far, just constant mentions that there are...
Cheers.
Randall R Schulz wrote:
> On Tuesday February 8 2011, Ittay Dror wrote:
>> ... The dynamic languages are more oriented
>> towards dealing with untyped data.
> There is no such thing as "untyped data."
correction: dynamic languages are more oriented at dealing with
attribute keys as method names.
Ittay
>
>> Ittay
>
> Randall Schulz
Yes it could. But if your interface is dynamically build against amazon
WSDL for instance - what could you possibly do to disarm it? Whatever
you will do with compilation checks (for instance using some sort of
WSDLC at compile time) will not gona help you if amazon alter the services.
>> Another reason that only part (which is not the one you're using) could
>> be altered - for the dynamic language it's fine. Imaging if
>> bash-scripting was statically typed. In this case scripts should be
>> "compiled" against very particular versions of utilities. If something
>> changes in 'ls' - go 'recompile' your scripts. For the small scripting
>> purposes or integration purposes dynamic typing is good not because it
>> has some particular advantages over static typing, but because static
>> typing has disadvantages in this case - too much checks those grant
>> nothing.
>
> i see. so basically, "dynamic typing" means "i know more than the compiler does."
Yes - a kinda.
> i thought about this. imho, a hybrid would be best.
Depends. If we're talking here about big projects - so the static
language with @dynamic part is best here, but if we're talking about
customization scripts/plugins/embedded parts - simple dynamic languages
rule, because it's easier to fix some javascript that does simple thing
and put it in MyCoolProgram/plugins directory possibly in already
started program, than start with big compilation process against
MyCoolProgram/libraries.
And another good example is E4X[1]. Nothing like this could be done with
static checks.
[1] http://en.wikipedia.org/wiki/ECMAScript_for_XML
> Dennis Haupt wrote:
> > null is simpler, but can become time bomb and explode at a random time
> when you actually try to access the object which makes it more difficult to
> find the source of the problem. explicitly checking as soon as possible
> acts as a guard against this.
>
> Yes it could. But if your interface is dynamically build against amazon
> WSDL for instance - what could you possibly do to disarm it? Whatever
> you will do with compilation checks (for instance using some sort of
> WSDLC at compile time) will not gona help you if amazon alter the
> services.
this problem is independent of the used type system. once you leave the compiler's realm, static typing does not apply anymore.