Re: Authors and Computer Scientists Scared of Definitions?
Posted: Sep 10, 2006 3:49 AM
> > Above, you said: "I mean how the data in question is to
> > be
> > used along with what operations are valid on it."
> > "int" is a representation of integral numbers. The
> > operations on it loosely matches those you may do in
> > mathematics on integral numbers.
> > I think describes it as a type, just fine: It's a type
> > that may be used to model integral numbers.
> Yeah, but using integral numbers for their sake alone is
> very seldom done unless you're into number theory. Every
> time I use a number, it's meant for a specific purpose,
> yet I know of no one that would define another type just
> to qualify its use. The reason for this is simple. It
> adds nothing to the execution and take extra time to write
> out, not to mention that many languages don't have
> facilities for this or at least don't define a standard
> way to do this.
Well, it adds intention and type checking to the code, and is in particular useful for entities that in itself are insufficiently represented by an int (such as your example "distance", which is meaningless without a unit, such as "meters"), and failure to account for this can lead to tremendously expensive bugs, such as the $125 million loss of the Mars Orbiter... (http://www.cnn.com/TECH/space/9909/30/mars.metric/)
As for people often not doing this (using specific types for concepts): Unfortunately, no...
> > > Is it a distance, pixels, socket number, etc?
> > Those are different concepts, and typically better
> > modelled by separate types.
> Like I said, who actually does that? And no, they are not
> different concepts. They are still numbers. They just
> have additional interpretations.
I think we should make a distinction between the concepts and their representation. "distance" may be _represented_ by an int, or preferably by a type incorporating both numerical value and unit. However, I'd still argue that "1 meter" is a different concept than, say "1 pixel". Yes, they both use "1", but that's about it. :)
> > > If that were also defined, then it'd
> > > be more of a true type, IMNSHO. Classes don't
> > > because the members don't tell anything to the
> > compiler.
> > Huh? Classes tell the compiler what operations may be
> > possible on them, and their results, if any. In other
> > words, how values of a given class may be used.
> No they don't. Add a member to a class and the compiler
> can't infer anything from that member. All it knows is
> that there's an extra value there. Classes don't tell
> what operations are possible on them, their methods do. I
> find this to be a half solution too. Double dispatch for
We may be talking on cross purposes, here: When I talk about "classes", I include of course its member variables and functions/methods, which means that "classes" (or more accurately, the compiler) indeed "knows" what possible operations can be done on instances of this class, the types of any parameters, and their return value types (in a statically typed language).
As for double dispatch: Yes, it's a shame that's not available in more of the mainstream languages. There's a proposal for it for e.g. C++, but with all the committee has on its plate (in particular support for "concepts"), it's unfortunately not much of a chance of it making it into the next C++ standard...
> > > You can overload operators, but it's an ad-hoc
> > solution.
> > Why is that an ad-hoc solution, and solution to what?
> To specifying operations. Methods are also ad-hoc. We
> really have to get away from this Turing concept that
> everything is a mini-machine. We have to stop telling the
> machine what to do and instead specify what operations
> need be done (and their dependencies) and let the machine
> figure out what resources it has available to accomplish
> theses tasks in the best way and order it sees fit.
I have a little difficulty following you, here. Could you perhaps give a concrete example (both showing things as done today, and how you think it could improved)? You may have a good point, I just have a problem seeing it.