Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sure! Let’s say I want to enforce that a variable only ever holds an integer. Rather than put the conventional prefix and the name together, like this:

    var intValue = 3;
…I separate the conventional prefix with a space:

    int value = 3;
…so now my co-workers don’t need to remember the convention – it’s enforced by the language.

(I hope this makes the joke more obvious.)





I wasn't talking about Hungarian notation. I meant more like if you see a variable named `user` or `activeUser` you know that it's going to contain a predictably-shaped data object that describes a user. E.g. it will always have a `user.id` property. I would never call an string-ish ID a user, then. I would call it `activeUserId` or `userId` or just `id` if the distinction between those was already obvious from context... But that's very different from writing `strUserId` which I never do: I try to make sure my names always convey semantic distinctions.

Mhm! Exactly! In the system those other languages use, once you see the variable’s declaration:

    User activeUser
…you’ll always know that `activeUser` contains a User value – something that might have an `Id` property. And the convention is enforced by the language, so it’s easy to communicate. These semantic distinctions are very useful, I agree.

Haha I knew you'd say that. I'm not pretending there aren't advantages to strict systems of declared types. There are many! But my point is simple to the point of stupidity: there's just more stuff on screen when you have to write `User` twice. In this simple example it looks trivially simple to write the word "user" twice, but in a reasonably-complex real example the difference will be far more noticeable.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: