4 ms·
Every language has primitive types. Ruby for example lacks primitives, even integer numbers are actually objects of type Fixnum.
by kyllo 12y ago
Every language has primitive types.
Ruby for example lacks primitives, even integer numbers are actually objects of type Fixnum.
- JadeNB 12y ago> Ruby for example lacks primitives, even integer numbers are actually objects of type Fixnum. … but isn't Fixnum a primitive type? EDIT: I guess that it depends on what 'primitive' means, but there is some root to the inheritance hierarchy—for Ruby, it's BasicObject ( http://www.ruby-doc.org/core-2.2.0/BasicObject.html http://www.ruby-doc.org/core-2.2.0/BasicObject.html )—and surely that must be regarded as primitive.
- djur 12y agoI think the parent is using 'primitive' in the Java sense, which means 'a typed value that is not an object' -- that is, 'int' instead of 'Integer'. The distinction is meaningless for languages that don't have separate type systems for objects and everything else. Wikipedia makes the division between "basic types" and "built-in types": http://en.wikipedia.org/wiki/Primitive_data_type http://en.wikipedia.org/wiki/Primitive_data_type
- kyllo 12y agoYes, I am talking in the C++ or Java definition of primitive types, like int, char, float, double, long, bool. It's only meaningless to talk about primitive types in the context of Ruby because Ruby doesn't have primitive types. Every type in Ruby is an object type.
- ubernostrum 12y agoJava is the canonical example. Some types are termed primitive types; they are simply raw (numeric) values. They are not "object-like" in the sense that they do not have methods a programmer can access, they cannot be subclassed, etc. Other types are reference types, which are "object-like". For each primitive type there is a corresponding reference type which can (and in more recent versions of Java, automatically does) wrap an instance of the primitive type (known as "boxing", and as "autoboxing" when done automatically). C# calls these "value types" and "reference types". Python, once upon a time, similarly had two hierarchies of types: those which could be subclassed, and those which could not (the latter all types built in to Python). The unification of these, and elimination of the distinction so that all of Python's types shared common behavior and a common hierarchy, began in Python 2.2 (introduction of "new-style" classes inheriting from `object`) and completed with Python 3 (where "new-style" classes are the default).