Dart Language Design – Why No Special Character for Variables?

dartlanguage-design

I come from a PHP background and I have been considering looking at DART in more detail.

DART is an, open source, front-end/back-end, language for web development.

PHP has a special $ (dollar) character to indicate variables:

$variable
CONSTANT
'string'
"etc"

I find that dollar sign to be really useful for speeding up the proces of refactoring, especially if PHP code is mixed with HTML or content. It reduces the number of false positives when, say, doing a find and replace.

As DART is a completely fresh language (with no legacy) that can be embedded in HTML, it surprised me to see that it does not have any special identifier to indicate variables.

What's the reasoning behind that design decision?

Best Answer

Actually you can use $ as a a prefix to variable names.

I tried it for you: http://try.dartlang.org/s/lKco

Please note what happens to the great string interpolation feature. Basically you can access vars in a string with ${yourvar}. If you name a variable with $, then it looks ugly: ${$yourvar}. Therefore I do not recommend the $prefix style.

I have started with PHP too. But I found out soon as I switched to Java, that $ is not really common usus. What is the sense behind - the PHP developer would probably say, easy identification of variables. The Java developer would cry in pain.

The Dart developers try to make an "unexciting" language. It should look familiar to many. Without doubt Java syntax is more widespread than PHP syntax. Maybe this is the reason why Dart developers have left out the $.

On the other hand, personally speaking, I think it is really not necessary and after getting used to Java, I find it ugly. Ruby doesn't use it. JS doesn't use it. And so on.

Anyway here are more answers to the language: http://www.dartlang.org/support/faq.html#language

If you want to follow the recent blogs on Dart I recommend you: http://www.dartosphere.org

Related Topic