What is considered primitive in a programming language?

Asked

Viewed 450 times

8

What is considered primitive in a programming language?

Only the types or other language resources are also primitive?

1 answer

9


The term is not very well defined so it may be what someone says it is, so it may be other things, but we’re not going that far.

On primitive types what is considered more is the type that has concrete representation in the processor, so the real primitives would be the basic numeric types with 1, 2, 4 or even 8 bytes, being integers or floating point, including the unique boolean character that is still a numerical type, although some of them may need a construction on some architectures. So they’re scalar and noncompound types.

There is another current that says that the primitive type is the one that language gives special treatment, is considered builtin. It is not always possible to indicate what special treatment is, so even if it is a compound type it can be considered primitive type. By that definition string can be a primitive type, or a decimal type or a date that is not a scale, but with special treatment that the processor does not read directly.

Some definition may determine that the primitive type is the type by value and not by reference, but I see it happening less and probably wrong.

Confusion made by languages

Java used this term a lot and where it has a more specific meaning. Java has always been sold as a fully object-oriented language, even if it is not even close to the truth, and everything should be object and represented by a class. But for performance reasons they had to make an exception and have numerical types that were not classes, the primitive ones.

In future version (who knows current when it is beautiful this) it should have the possibility to create types by value (struct) and we will have types that have always been types by value and types by value created by the user. I want to see what they’re going to call these types because they’re not objects as they defined types by reference and they’re not primitive because they don’t have special treatment of language, and they’re not scalar. That’s what I say when you define something wrong.

C# has always had struct and so she never used the idea of the primitive type, only of type per value, where some have optimizations for the concrete type of processor.

C# has some library types with nickname in the language, so some consider them primitive, but until string that’s how it is, then I don’t think it can be considered primitive, since it is composed and by reference, even if it has semantics of value. But some say he is, as well as decimal is, even if it is a composition and type by value. But not DateTime who doesn’t have a alias type and is a composition and is by value equal to decimal. So it is complicated to define what a primitive is in fact, each language can have its definition.

In general a primitive type is immutable, but since it doesn’t have a formal definition I don’t know if it’s a requirement.

Because of all this people confuse primitive type with type by value. Yes, every primitive type is a type by value, but not every type by value needs to be a primitive type. At least by one definition. Another considers string a primitive type by reference.

I don’t know if other languages use the term, but keep in mind that each one can conceive it in a different way.

See more on the subject at:

  • This C# struct is the same as C?

  • He’s good-looking, but C# is much more powerful.

  • This conversation about primitives reminded me that in Java there are the "primitives" of concurrent programming (wait(), notify(), etc) on which other competition mechanisms are developed.

  • Primitive comes from primate, it is to say that the content is "ancient" or initial. It can also be associated with disused or depreciated state.

  • There is a reference to this called primitives: Synchronized, Wait and notify, which are basically states.

  • To be exact, find the primitive within a context, and consider that in an algorithm, the most primitive would be the number itself, and in its structure, within its context, the number, the primitive would be the type: null, Boolean.. etc. Primitive is very similar to premise.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.