3

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).

4thSpace
  • 43,672
  • 97
  • 296
  • 475
  • 2
    Who says "typed class"? All classes are types.. – Blorgbeard Jun 19 '13 at 22:15
  • This comes up when talking about generics and type inference. "typed object" is another one. – 4thSpace Jun 19 '13 at 22:15
  • 1
    @4thSpace can you link to or quote an example? – Blorgbeard Jun 19 '13 at 22:16
  • Not online. These conversations are in person. – 4thSpace Jun 19 '13 at 22:18
  • If I were talking about generics and type inference I would still never phrase anything like that. I would say "this is a generic method that accepts objects which implement MySuperCool interface, the first type argument is used as the key, the second as the value" or "How is this objects type inferred by the compiler?" or "How does the compiler implement type inference?" I don't know who you're talking to but they don't speak like any of the academics I know around these parts. – evanmcdonnal Jun 19 '13 at 22:19
  • Academics? Ok. As a side question, is "object" considered a type? – 4thSpace Jun 19 '13 at 22:20
  • 2
    See http://ericlippert.com/2012/10/15/is-c-a-strongly-typed-or-a-weakly-typed-language/ – Eric Lippert Jun 19 '13 at 22:33
  • In addition, it sounds like you're not super clear on what a type is in the first place. This might help: http://blogs.msdn.com/b/ericlippert/archive/2011/08/29/what-is-this-thing-you-call-a-quot-type-quot-part-one.aspx\ – Eric Lippert Jun 20 '13 at 00:57
  • The opposite [does-untyped-also-mean-dynamically-typed](http://stackoverflow.com/questions/9154388/does-untyped-also-mean-dynamically-typed-in-the-academic-cs-world?rq=1) – nawfal Jul 24 '14 at 02:01

4 Answers4

6

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.)

Theodoros Chatzigiannakis
  • 28,773
  • 8
  • 68
  • 104
3

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?

Community
  • 1
  • 1
Matthew Cox
  • 13,566
  • 9
  • 54
  • 72
  • No, that's not the question. I'm very familiar with the differences between weak/strong types. I hear people mention "typed" and "strongly typed" as if they are interchangeable. Again, this is in reference to C# only. – 4thSpace Jun 19 '13 at 22:14
  • Based on your edit, the best thing is to ask someone to clarify what they mean by just "typed"? I always implied they meant "strongly typed". Maybe that was wrong to do. – 4thSpace Jun 19 '13 at 22:17
  • Of course there's such a thing as a typed language and an untyped language. For example, the typed lambda calculus is a typed language and the untyped lambda calculus is an untyped language. – Eric Lippert Jun 19 '13 at 22:34
  • I can't say I'm an expert on the topic but I was pretty sure untyped was equivalent to dynamically typed. http://stackoverflow.com/questions/9154388/does-untyped-also-mean-dynamically-typed-in-the-academic-cs-world – Matthew Cox Jun 19 '13 at 23:13
  • What if a language has *no types whatsoever*? How can it be "dynamically typed" in that case? – Eric Lippert Jun 20 '13 at 00:58
  • [An interpreter for the untyped lambda calculus](http://codegolf.stackexchange.com/questions/284/write-an-interpreter-for-the-untyped-lambda-calculus). – jason Jun 20 '13 at 02:41
1

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.

Mishax
  • 4,442
  • 5
  • 39
  • 63
0

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.