On Thursday, 5 June 2014 at 09:43:13 UTC, Jonathan M Davis via Digitalmars-d-announce wrote:

Though I confess what horrifies me the most about dynamic languages is code
like this

if(cond)
    var = "hello world";
else
    var = 42;

The fact that an if statement could change the type of a variable is just atrocious IMHO. Maybe I've just spent too much of my time in statically typed languages, but I just do not understand the draw that dynamically typed languages have for some people. They seem to think that avoiding a few simple things that you have to do in your typical statically typed language is somehow a huge improvement when it causes them so many serious problems that
static languages just don't have.

- Jonathan M Davis

Wouldn't static-if accomplish much of the same?

```
static if (cond)
    auto var = "hello world";
else
    auto var = 42;
```

I understand it is horrible, and unexperienced programmers often make the mistaken of forgetting the definition of var in the *else* condition, while painstakingly try to use it *after* it.

Now the first time I saw `auto`, in D or C++, I was horrified. But in essence it is a move towards not having to think about the type, or in other cases having to actually type it out, but just have the compiler infer it auto-matically. A dynamic language is just having auto everywhere without having to type even that, and giving up compile time type checking in turn.

On the other hand, some dynamic languages allow you to restict a variable entering a function by its type. In essence, I see both static and dynamic languages trying to meet in the middle.

The middle ground is the idea that data has a type and a variable is just a reference to some data; a way for use humans to express data flow. In other words, relying more on compile-time type inference.

That is the direction I see in general; programmers more and more relying on tools and analysers to do their work.

Reply via email to