In C#, is there any reason to say strongly typed vs just typed? When someone says typed class, I think of some type other than object. Nearly everything except object is typed in C#.
Once you define a class that is not object, that class is a type. It doesn't get anymore typed from there.
By the way, this isn't a question about type safety (valid memory access and object assignment compatibility).
-
2Who says "typed class"? All classes are types..Blorgbeard– Blorgbeard2013年06月19日 22:15:00 +00:00Commented Jun 19, 2013 at 22:15
-
This comes up when talking about generics and type inference. "typed object" is another one.4thSpace– 4thSpace2013年06月19日 22:15:28 +00:00Commented Jun 19, 2013 at 22:15
-
1@4thSpace can you link to or quote an example?Blorgbeard– Blorgbeard2013年06月19日 22:16:12 +00:00Commented Jun 19, 2013 at 22:16
-
Not online. These conversations are in person.4thSpace– 4thSpace2013年06月19日 22:18:07 +00:00Commented Jun 19, 2013 at 22:18
-
2See ericlippert.com/2012/10/15/…Eric Lippert– Eric Lippert2013年06月19日 22:33:52 +00:00Commented Jun 19, 2013 at 22:33
4 Answers 4
The terms strongly and weakly typed refer to the rigidity of the rules of the language regarding implicit type conversions. A strongly typed language is much more strict on what implicit conversions it accepts, while a weakly typed one is more relaxed. In other words, lots of languages have types, but only a subset of them have strong typing.
You might be confusing those terms with the terms static and dynamic typing, which refer to knowledge of types at compile type or at runtime, respectively. In this sense, perhaps you've heard the term typed as a shorthand for statically typed. (Although I can't say that I agree with using the term typed, I think it's the only interpretation that seems to make sense.)
Comments
Your nomenclature is incorrect. it is not strongly typed vs just typed
It's strong vs. weak typing
Once you talk about it in those terms, then there is a big distinction to be made.
You can read about it all over teh Googles.
http://en.wikipedia.org/wiki/Strong_and_weak_typing#Definitions_of_.22strong.22_or_.22weak.22
Edit:
There is no such thing as just a Typed language. You have Dynamic vs Static and Weak vs Strong typing which are addressing two different types of issues. Another reference article
What is the difference between a strongly typed language and a statically typed language?
6 Comments
Be aware, the latest C# language specifications do not actually use the term "strongly typed" in their description of the language. This in contrast to, for instance, the Java language specification where they are very explicit in stating it is strongly typed.
Since the C# language specification does not use the term, it also does not define it. This is one of the reasons you're having a hard time getting an answer to your question. You can make a case however that even though by its specification, C# is not explicitly a "strongly typed" language, it does nevertheless have most of the characteristics of a strongly typed language.
To answer your C# question, I recommend taking a look at the Java language specification (Java resembles C# very closely and many of the fundamentals are very similar if not identical). In Chapter 4 it states:
The Java programming language is also a strongly typed language, because types limit the values that a variable (§4.12) can hold or that an expression can produce, limit the operations supported on those values, and determine the meaning of the operations. Strong static typing helps detect errors at compile time.
I'm providing this answer while I recognize other answers provide links to information on Wikipedia about strong typing in general, the question concerns C# specifically. I find the Java definition is more useful and to the point to the OP.
1 Comment
Another angle that is not trying to define if a language is strong or weak or static or dynamic.
I am guilty of saying 'strongly typed'. Especially when I am working with a particular project that we are maintaining. This horrible codebase uses DataTable for pretty much everything and values are fetched as object, from columns by index with a lot of casting in the application code. And there are no comments explaining what the hell is going on.
Part of this system are now being rebuilt using EF and Linq. And now we are projecting queries into pocos/dtos. So having a service with a method that returns as generic list of a certain type is what I refer to when I say strongly typed. It's the service and its methods that are strongly typed, I am not talking about C# itself.