Summary:
Anders Hejlsberg, the lead C# architect, talks with Bruce Eckel and Bill Venners about C# and Java generics, C++ templates, constraints, and the weak-strong typing dial.
The ability to add new comments in this discussion is temporarily disabled.
Most recent reply: December 13, 2007 5:12 AM by
|
Anders Hejlsberg, the lead C# architect, talks with Bruce Eckel and Bill Venners about C# and Java generics, C++ templates, constraints, and the weak-strong typing dial. Read this Artima.com interview with the creator of C#: http://www.artima.com/intv/generics.htmlWhat do you think of Anders' comments?
|
|
|
> The thing you realize about typing is that it's a dial. The higher you place the dial, the more painful the programmer's > life becomes, but the safer it becomes too. But you can turn that dial too far in either direction. Does the dial go from weak to strong, or from static to dynamic? I have personal experience of the pain of representing certain designs in C++, a strongly- and statically-typed language, so would agree with that. And once the compiler had bludgeoned me for half an hour, I suppose that the code was safe in certain limited respects. And turning the dial in the other direction, in languages such as Python, Ruby, or Smalltalk, I agree I was amazed at how /little/ pain was involved in clearly representing concepts in the code. But were they 'less safe'? I for one don't think so. I tend to agree with Bruce Eckel's position (at http://mindview.net/WebLog/log-0025) that strong and static typing are both missteps towards unit-tested code. The sorts of assurances that typing can give you are really not that useful compared to unit-tests which check that a method's semantics are correct.
|
|
|
> Issue number two, and I think this is probably > an even bigger issue, is that because Java's > generics implementation relies on erasure of > the type parameter, when you get to runtime, > you don't actually have a faithful representation > of what you had at compile time. While Java's generics use erasure, the specification (available from http://www.jcp.org/aboutJava/communityprocess/review/jsr014/index.html) states that there is attribute added to the bytecode to enable reflection to work without breaking compatibility with existing VMs. Regards, Richard
|
|
|
Does the dial go from weak to strong, or from static to dynamic?'So what is strong typing? As best as we can tell, this is a meaningless phrase, and people often use it in a nonsensical fashion. To some it seems to mean The language has a type checker. To others it means The language is sound (that is, the type checker and run-time system are related). To most, it seems to just mean, A language like Pascal, C or Java, related in a way I cant quite make precise. For amusement, when someone mentions the phrase strongly typed at a cocktail party, ask them to define it, then sit back and watch them squirm. And please, dont use the term yourself unless you want to sound poorly-trained and ignorant. Use the terminology of this course instead.' Chapter 24 Type Soundness p205 Programming Languages: Application and Interpretation http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/PDF/all.pdf> I have personal experience of the pain of representing > certain designs in C++, a strongly- and statically-typed > language "C and C++ do not have sound type systems. That is, the type system may define certain abstractions, but the run time system does not honor and protect these." p205 > And turning the dial in the other direction, in languages > such as Python, Ruby, or Smalltalk, I agree I was amazed > at how /little/ pain was involved in clearly representing > concepts in the code. I've used Smalltalk for over 10 years and like it. However, there are expressive statically checked languages: ML, Haskell, Nice http://nice.sourceforge.net/index.html, Scala http://scala.epfl.ch/index.html ... > But were they 'less safe'? I for one don't think so. I > tend to agree with Bruce Eckel's position (at > http://mindview.net/WebLog/log-0025) that strong and > static typing are both missteps towards unit-tested code. > The sorts of assurances that typing can give you are > really not that useful compared to unit-tests which check > that a method's semantics are correct. It seems that folk experienced with expressive statically checked languages have a different programming style - they write code to actively use the type system to find errors, to them the type checker is another tool they can use to make their program better.
|
|
|
> Anders Hejlsberg, the lead C# architect, talks with Bruce > Eckel and Bill Venners about C# and Java generics, C++ > templates, constraints, and > the weak-strong typing dial. "A Comparative Study of Language Support for Generic Programming" This paper reports on a comprehensive comparison of generics in six programming languages: C++, Standard ML, Haskell, Eiffel, Java (with its proposed generics extension), and Generic C#.http://www.osl.iu.edu/publications/pubs/2003/comparing_generic_programming03.pdf
|
|
|
I was quite impressed with the research language Xen. As mentioned a.o. at http://www.theserverside.net/news/thread.aspx?thread_id=23460 because it features some scale of type-inferencing. A feauture that I only know of languages like Ocaml. Maybe that will bring something new to the age-old debate between dynamic- and static typing. :-) If it will ever make it into a major MS supported programming language of course: I remember my excitement over the MS Research project Intentional Programming that suddenly disappeared of the face of the internet as if it contained some secrets of state. Another interesting feature is ofcourse the way it handles relational- and xml-data. groetjes, Joost de Vries
|
|
|
some scale of type-inferencingLocal type inference is also a feature of open source languages targeting the JVM (and inter-operating with Java) like: Nice http://nice.sourceforge.net/index.htmlScala http://scala.epfl.ch/index.htmlMaybe that will bring something new to the age-old debate between dynamic- and static typingWe can hope ;-)
|
|
|
Scala and Nice look interesting. I'm a bit sceptic though about Nice's capability to prevent nullpointerexceptions in the case where data is originated from external sources like the user or a database. So that will be interesting to try out. But then there are a lot of interesting features in Academic languages. The point where it gets exciting to me is where these cross over into the mainstream of languages that are used in the enterprises. Since then I can actually use it in everyday development. But there's hope: it seems that one of the people behind Scala, Martin Odersky, was also behind the Pizza generics compiler. So maybe this will be of influence too. I seem to recall that James Gosling expressed some interest in type-inferencing. So, let's see, how long did it take for generics to make it into Java? Hm........
|
|
|
Nice's capability to prevent nullpointerexceptions in the case where data is originated from external sources like the user or a database
It's called Nice - not Magic ;-)
The programmer prevents NullPointerExceptions in these (and all other cases). Nice just provides a way to isolate the situations in which values may be null.
In Nice, the type String does not include null values - the type check will fail if we try to assign null to a String variable. The type ?String does include null - so we can bring in data as ?String, check that it isn't null and from then on use it as String.
But then there are a lot of interesting features in Academic languages Yes, and in research languages generally - as you pointed out, there's plenty of language research taking place within Microsoft and other companies. It's wonderful that so many of those implementations are openly available.
cross over into the mainstream of languages Sure, it just takes soooo long.
Which is a reason to be interested in the language implementations that target jvm and clr (and interoperate with Java & C#) even though the implementations may suffer from limitations in those VMs - we can sometimes pretend to be using the mainstream language.
|
|
|
Guy is genius. I like ruby, I think they (C# team steal a lot from Ruby) , but compare with c++ and java c# generic implementation is superiors.
|
|
|
nothing compare with C++ Templates when you are developing computational geomitric applications or math algorithms , see CGAL or Blitz++ libraries as an example.
"a programming language is a tool for a especific porpouse", said stroustrup in The C++ Programming language... or something like this ;-)
and c# generics could be god in the more comun types of aplications but not in all of them
what about??: metaprograming, active libraries, traits tecniques, compile-time expansions, function objects ... and some other atractives c++ templates aspects
anyway c# is a new good language with many interesting things, but i was expecting more of C# exception and templates mechanism
|
|
|
I can totally understand the design decisions the C# designers took and overall really like C#'s generics but, coming from C++ templates, there's a lot of stuff you cannot do with generics that you can do with templates. I'm thinking of generic algorithms a la STL, expression templates, pretty much any of Alexandrescu's stuff. Of course there are many people who will argue that that's a good thing.
It'll be interesting to see what kind of generics-based libraries will surface for C#.
Andrew
|
|
|
Generics has not been released in final form for etiher C# or Java, right?
Regarding the distinctions he made between C# and Java ...
I agree that there will potentially be a runtime disadvantage, but depending on how they implemented the extra information in the class file, it may not be bad. C# is at an advantage being able to design the CLR with generics in mind. However, I think it doesn't make a whole lot of difference to the programmer (for compile-time issues, at least).
For the second issue, when you get to runtime, you don't actually have a faithful representation of what you had at compile time, I'm not sure how often this will be a cause for problems for programmers. I guess the question is how much benefit do you get from compile time checking, and then how much additional benefit do you get from run time checking?
|
|
|
> Generics has not been released in final form for etiher C# > or Java, right?
The spec has been out now for over 2 years for Java templates - changes could still occur at this stage but I imagine that they wouldn't be major.
> > Regarding the distinctions he made between C# and Java > ... > > I agree that there will potentially be a runtime > disadvantage, but depending on how they implemented the > extra information in the class file, it may not be bad.
According to the Java spec, runtime information on templates is added to the class file using named attributes. This is a backward compatible mechanism.
> For the second issue, when you get to runtime, you > don't actually have a faithful representation of what you > had at compile time, I'm not sure how often this will > be a cause for problems for programmers. I guess the > question is how much benefit do you get from compile time > checking, and then how much additional benefit do you get > from run time checking?
As I mentioned in my post above, this statement by Anders is incorrect (unless he knows something that is not in the public spec). Attributes are added and the classes involved in relfection have been modified to take advantage of this information.
Regards, Richard
|
|
|
> Does the dial go from weak to strong, or from static to > dynamic? > > 'So what is strong typing? As best as we can tell, this > is a meaningless phrase, and people often use it in a > nonsensical fashion. To some it seems to mean The > language has a type checker. To others it means The > language is sound (that is, the type checker and run-time > system are related). To most, it seems to just mean, A > language like Pascal, C or Java, related in a way I cant > quite make precise. For amusement, when someone mentions > the phrase strongly typed at a cocktail party, ask them > to define it, then sit back and watch them squirm. And > please, dont use the term yourself unless you want to > sound poorly-trained and ignorant. Use the terminology of > this course instead.' > > Chapter 24 Type Soundness p205 > Programming Languages: Application and Interpretation
'Hence, typeful programming advocates static typing, as much as possible, and dynamic typing when necessary; the strict observance of either or both of these techniques leads to strong typing, intended as the absence of unchecked run-time type errors.' (emphasis is mine)
Typeful Programming, p3 Luca Cardelli
BTW I'm in the static typing camp but I find amusing that people usually ignore this definition.
|
|