Eloquently sums up my feelings about the disadvantages of dynamic typing

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 16 20:07:20 PDT 2013


On Thursday, October 17, 2013 04:49:29 growler wrote:
> On Thursday, 17 October 2013 at 02:37:35 UTC, H. S. Teoh wrote:
> > On Wed, Oct 16, 2013 at 10:16:17PM -0400, Jonathan M Davis
> > 
> > wrote:
> >> On Tuesday, October 15, 2013 15:15:45 Walter Bright wrote:
> >> > http://www.reddit.com/r/programming/comments/1oi8wd/ruby_is_a_dying_lan
> >> > guage /ccs8yr8
> >> 
> >> I can't possibly like any language where the type of a
> >> variable could
> >> change based on whether the condition in an if statement is
> >> true
> >> (because a variable gets assigned a completely different type
> >> depending no the branch of the if statement).
> >> 
> > auto func(alias condition)()
> > {
> > 
> > static if (condition())
> > 
> > int t;
> > 
> > else
> > 
> > float t;
> > 
> > return t;
> > 
> > }
> > 
> > ;-)
> 
> But if you make a mistake it is very likely that you'll see it at
> compile time, not runtime. Plus D has very explicit casting which
> also helps.

The key difference is that the type of a variable won't change on you in D. 
Sure, the return type of a function could change depending on the types of its 
arguments or the value of its template arguments, but it's all known at 
compile time, and you'll get an error for any type mismatch. In contrast, with 
a dynamically typed language, the type of a variable can actually change while 
your program is running, resulting in function calls being wrong due to the 
fact that they don't work with the new type. If you're dealing with static 
typing, the type of every variable is fixed, and the legality of code doesn't 
suddenly change at runtime.

And it's not like scripting requires dynamic typing (e.g. you can write 
scripts in D, which is statically typed), so as far as I'm concerned, there's 
no excuse for using dynamic typing. It just causes bugs - not only that, but 
the bugs that it causes are trivially caught with a statically typed language. 
I pretty much outright hate dynamic typing and expect that I will never 
heavily use a language that has it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list