3

We separate out extension method classes by primitive types and complex types that we are extending. My question is simple. Would a Guid be considered a primitive type along with string, int, DateTime, etc? Or would it be considered a complex type when describing it?

Update

After reviewing the answers I much appreciate the clarification that I was able to glean from some answers. However, I am getting the impression that curiosity killed the cat got the cat murdered, so I am voting to close my own question.

CatDadCode
  • 58,507
  • 61
  • 212
  • 318
  • 1
    Define "primitive type" first :) – Oded Sep 19 '11 at 19:00
  • 1
    Define primitive and complex types. – David Heffernan Sep 19 '11 at 19:00
  • Well I guess that is the real question. How would you folks define it? – CatDadCode Sep 19 '11 at 19:01
  • The primitive types are typically those listed here: http://msdn.microsoft.com/en-us/library/ms228360%28v=vs.80%29.aspx ...correct? MSDN is calling them 'Built-In Data Types". – IAbstract Sep 19 '11 at 19:02
  • @IAbastract - As far as .NET is concerned, yes. – Oded Sep 19 '11 at 19:05
  • I would go to the person who made this policy and say 1) "Why?" 2) "Which is `Guid`" ? 3) "What's the decision procedure so I don't have to bother you next time this comes up?" Hopefully somewhere along the way enlightenment will dawn in you and/or them. – AakashM Sep 19 '11 at 19:05
  • @Alex Oh come on. You question is "Is GUID a primitive type or a complex type" where primitive and complex are terms that you also have to specify. That's silly. This is not a real question. – David Heffernan Sep 19 '11 at 19:06
  • @DavidHeffernan Calm yourself. I was simply curious how you guys would classify the Guid type. I did some googling and found conflicting results and conflicting definitions. – CatDadCode Sep 19 '11 at 19:08
  • 3
    @AakashM It's not really a big deal for the project. I was just curious what --you folks-- the rabid pack of dogs thought. – CatDadCode Sep 19 '11 at 19:09

4 Answers4

5

It depends on what you call a "primitive data type".

Wikipedia lists these two definitions:

  • a basic type is a data type provided by a programming language as a basic building block. Most languages allow more complicated composite types to be recursively constructed starting from basic types.
  • a built-in type is a data type for which the programming language provides built-in support.

According to the first one, Guid is a constructed type, not a primitive.

According to the second, it is also not a primitive type (as it is provided in the BCL, in the System namespace, and is not defined by any of the .NET languages).


Update:

This is what the IsPrimitive method of the Type class says:

The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single.

So, as far as .NET is concerned, it is not a primitive type.


In conclusion: According to the three separate criteria above, Guid is definitely not a primitive type.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
2

Guid would be a primitive by your definition. Its a struct like int, DateTime. Its also provided by the .NET Framework in the System namespace. Plus, its immutable, like string and DateTime.

By .NET's definion it isnt.

See http://msdn.microsoft.com/en-us/library/system.type.isprimitive.aspx

I would lump it in the same category as int, DateTime and string.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
2

The answer to this is somewhat murky.

The language specification states:

it is also possible to use structs and operator overloading to implement new “primitive” types in the C# language

which would seemingly imply that Guid is a "primitive" type. However Type provides a IsPrimitive property and typeof(Guid).IsPrimitive will return false.

Note, though, that Guid is not provided by the language but rather by the .NET Framework.

The language specification also states that the primitive types in C# are Boolean (bool), Byte (byte), SByte (sbyte), Int16 (short), UInt16, Int32 (int), UInt32 (uint), Int64 (long), UInt64 (ulong), IntPtr, UIntPtr, Char (char), Double (double), and Single (single) notably leaving out both DateTime and Guid.

I would lose the descriptor "primitive" altogether and just refer to Guid as a value type.

jason
  • 236,483
  • 35
  • 423
  • 525
  • Okay, I agree that it is not primitive. So if you had to describe a Guid, how would you categorize its type? – CatDadCode Sep 19 '11 at 19:02
  • I agree. C# specification clearly define term "primitive" and it would be messy if everyone would reinvent his own terminology and call string as value type because it has value sematics. – Sergey Teplyakov Sep 19 '11 at 19:05
  • @Alex Ford: and why you need this distinction between primitive and non-primitive types at all? – Sergey Teplyakov Sep 19 '11 at 19:06
  • @SergeyTeplyakov I don't. I was simply curious. I'm getting the impression that being curious is a fault. – CatDadCode Sep 19 '11 at 19:10
  • @Alex: absolutely not. But it seems from your question that you're trying inveting the wheel:) BTW, DateTime is not primitive type;) P.S. there is a very simple way to check whether particular type primitive or not: Guid.NewGuid().GetType().IsPrimitive.Dump(); – Sergey Teplyakov Sep 19 '11 at 19:20
  • 3
    That first bit of the spec you quoted is confusing and I've asked Mads to remove it in a future edition. There's no need for the C# language spec to ever define "primitive type" and it is unfortunate that this language ended up in there. – Eric Lippert Sep 19 '11 at 20:42
0

It depends on what you call a "primitive type." The Type Fundamentals article says, "Any data types directly supported by the compiler are called primitive types.". I don't expect that the compiler "knows" about System.Guid.

The article Primitive data types in C# doesn't list System.Guid among the primitive types.

One could argue that it has to be a composite type, since it's a 128-bit entity that consists of multiple other primitives.

I'd say that GUID is NOT a primitive type, but you'll probably get others who disagree with me.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351