views:

144

answers:

5

Is a data type a piece of code? In other words, is it software? I'm talking about fundamental data types like integer, char, etc. If so, does that indicate that objects in OOP programming are extensions of data types? That is, basically, have programmers taken data types to another level in creating objects?

A: 

According to the definition of webopedia, it is software indeed. I think 'extension' is not the right word, but you can state (with a bit of care and in the right context) that all objects exist out of fundamental datatypes. And all fundamental datatypes exist out of ones and zeroes.

Fortega
A: 

Objects are a way of implementing abstract data types (see Abstract Data Type on WikiPedia for a formal definition), but data abstraction is only one of the components that make up OOP (see Object-oriented programming language on Wikipedia). Other important OOP components are encapsulation, inheritance, and polymorphism.

Håvard S
+1  A: 

The question whether data types are "a piece of code": ultimately, yes. if not in the language itself, then in the language that was used to build the language you are programming in.

Regarding "fundamental datatypes": I think what you mean are "primitive types". What is and is not considered a primitive type is wholly dependent upon your programming language. You mentioned integer and char, but these are not present in many languages. Quite a few languages lump all kinds of numeric types together in a single numeric type. Some languages distinguish between signed and unsigned integers. Languages that lack a distinct char type may use a number or a single character string instead.

No matter what primitive types a language defines, you can't have "turtles all the way down" - languages always have some built-in "magic" (data types, operators) upon which you can build your code. And sometimes the language may support adding new types, or even changing built-in types.

Regarding the "objects in OOP as extensions of data types": I would certainly regard classes and interfaces in OOP languages as types. But I guess saying they are data types doesn't do justice to the fact that they may define behaviour too. And its possible that a OO class only defines static methods, allowing data to pass through it without retaining data itself.

Also, it depends on what you mean by "extends". In many OOP languages you can indeed extend an existing classes through inheritence, but it may not be possible to extend the primitive types. Finally, many languages allow you to define new datatypes through compostion. For example, a C struct is such a composite type. I would never call such a struct an extension of its constituent types, it is simply an entirely new type.

I would agree to say that some languages have an extensible type system: that is, it allows the programmer to create its own types. But like just illustrated for C structs, this is not confined to OO languages.

If you're interested in this topic, you can read a lot about it on the wikipedia: http://en.wikipedia.org/wiki/Primitive_data_type http://en.wikipedia.org/wiki/Type_theory http://en.wikipedia.org/wiki/Type_system

Roland Bouman
+1  A: 

Yes, it's code. Yes, it's software. You can think of all "fundamental" data types as being abstractions of functions that occur on bits inside your processor. To accomplish that abstraction takes a programmer somewhere -- the programmer of the language or compiler, etc. How far away that abstraction is from what happens electrically in the processor is dependent on the language. For example, a "fundamental" data type like an "integer" in C# actually is pretty complex in the way it's moved around in memory. For example, there's a concept called "boxing", which a language like C does not have. Implementing this functionality takes a programmer, therefore, it's software.

Dave Markle
+1  A: 

If you are ready for some really w00t brainfood you should check out this year's OOPSLA Onward! essay by William Cook: On Understanding Data Abstraction, Revisited. He discusses abstract data types and objects.

Adrian