From: Gavin Kistner Date: 2005-06-01T23:25:29+09:00 Subject: Re: Intellisense and the psychology of typing On Jun 1, 2005, at 8:06 AM, Caleb Clausen wrote: > And I still fail to see the semantic difference between the two. > Please explain, I'm still listening. In what case would a tool -- any > tool -- be it compiler, interpreter, rdoc, ide, or whatever want to > treat your 'type hint' differently than my 'type declaration'? As far > as I'm concerned, they're different words for the same thing. Just > because you want to put it in a comment is not a semantic difference; > it's just syntactical. Speaking for my own understanding/interpretation: What is the semantic difference between a hint and a declaration? A hint says "Hey, this parameter/return value *might* be of Type Foo". A declaration says "This parameter/return value *must* be, is *guaranteed* to be of Type Foo". A hint is appropriate for suggesting methods that might be applicable. It would be inappropriate to raise a compilation or runtime error if the type was not was expected. (Depending on preference/verbosity level, it might be appropriate to raise a warning.) Statically-typed languages declare/ensure the types of objects. Ruby (thankfully, IMO) does not. It would be inappropriate (again, IMO) to use a syntax in Ruby for type hints which could be reasonably mistaken for type declarations. > The principle of least surprise is a good principle in language > design. Having just hijacked another thread to shout "guys, please stop touting POLS for Ruby!", I will yet stand up and agree with you on this. Any good UI design (be it visual or the interface to a language) should strike a balance between performing as the user expects and performing well. When the benefit from violating a user's expectations is minimal, it's usually not a good idea to violate those expectations. For example, even if a study showed that people were 2% safer if the gas and brake pedals on a car were reversed, it would be a logistical nightmare to introduce such a change. Violating the expectations of the majority of users may be desirable if the benefits are legion, a paradigm shift of happiness. > [...] I tried to come up with an > objective version of POLS, from the point of view of an average > programmer from another language. I think this may be the breakdown, however. By attempting to honor the expectations of users from another language, you are encouraging them to bring over related concepts as well. If Ruby were a statically-typed language, this would be a great idea. But dynamic- typing is a completely different beast from static-typing, and that needs to be clear. IMO, it is thus important that anything we do that hints at type is thus very syntactically different from systems which declare type.