Finally, a language without protected variables

When I started to learn the soon-to-be-released programming language Dart, it was a love from first sight. I like Java, and Dart is like Java, but a little better. I’m planning to write a series of blogs about Dart, but I couldn’t resist writing about the missing protected keyword.

The thing is that I firmly believe that having protected data access is pretty annoying, and on multiple ocassions it was forcing me to write convoluted code just to access protected variables from a non-descendant class. Seven years ago I published a post “Who needs protected variables” at JavaLobby.

A year later I had to fight with protected variables in ActionScript – here’s why.

Now, I’m happy to report that Dart language specification has only private and public data access. Just like I always wanted! This is what the spec states:
Dart supports two levels of privacy: public and private. A declaration is private if its name begins with an underscore (the _ character) otherwise it is public.” Just like that. No keywords to remember.

I like Dart and suggest Java, C#, and ActionScript developers to learn it. You’ll find yourself at home. The JavaScript folks should learn it too.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s