The Artima Developer Community
Sponsored Link

Weblogs Forum
Programming with "Duh" Typing

370 replies on 371 pages. Most recent reply: Aug 8, 2007 9:54 AM by James Watson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 370 replies on 371 pages [ « | 1 ... 256 257 258 259 260 261 262 263 264 ... 371  | » ]
Petrik de Heus

Posts: 19
Nickname: p8
Registered: Jul, 2007

Re: Programming with "Duh" Typing Posted: Jul 27, 2007 12:10 PM
Reply to this message Reply
Advertisement
> > Cedric Beust wrote
>
> In a dynamically typed language, you have to write tests
> to catch type mistakes (such as the one described by James
> earlier, where he forgot a * in front of a variable,
> thereby declaring it as a literal instead of an array).
> These tests are unnecessary in statically typed languages
> s since they are caught by the compiler.
>
> On the other hand, I can't think of a test written in a
> statically typed language that would be made unnecessary
> in a dynamically typed language because of the fact that
> types are optional in that language.

I can.

Try the following in Java:
assertEquals("10000000000", (new Double(Math.pow(10, 10)).intValue()));

Ruby gives the expected result even for very large numbers:
10.power!100000


There are other problems.
If Java were truly static you wouldn't need to cast.
The following compiles in Java but throws a RuntimeException:
List a = new ArrayList();
a.add(new SomeObject());
for ( Iterator iter = a.iterator(); iter.hasNext(); ){
AnotherObject value = (AnotherObject )iter.next();
}


And generics won't help all time. The following compiles but generates a ClassCastException:
List artists = new ArrayList();
artists.add(new Artist());
List<Album> albums = new ArrayList(artists);
for (Album album : albums) {
album.getGenre();
}


In Java you can do:
"" + new Object()

Which might not give the expected result.
In Ruby this creates an error.
p "Object " + Object.new
=> TypeError: can't convert Object into String

Flat View: This topic has 370 replies on 371 pages [ « | 256  257  258  259  260  261  262  263  264 | » ]
Topic: Programming with "Duh" Typing Previous Topic   Next Topic Topic: Python 3000 Plea for Help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use