9 ms·
Get Ready For C# 4.0
- kolektiv 16y agoHave we not been getting ready for C# 4 for some time? It's been in CTP and Beta variants for most of the last year. Some good new features exist of course.
- javery 16y agoThis article is also a month old.
- flatline 16y agoI'm not sure I like the overloading of the "out" keyword for covariant type parameters, but otherwise, pretty cool.
- andrewdavey 16y agoI find it easier to remember the difference between "out" and "in", compared to "covariant" and "contravariant".
- SanjayU 16y agoYeah, I'm not a huge fan of named parameters, either. Seems a bit superfluous.
- seasoup 16y agoNamed parameters are awesome. The equivalent pattern in javascript is passing in an options object. foo({ 'name': 'bar', 'title': 'Bar' }); This means not having to look up what the exact order of options are, nor having to pass in a bunch of null parameters because the one you want is the last parameter. Very cool. }
- bruceboughton 16y agoNamed parameters will be particular useful when calling methods which take bools (rather than a intention revealing enum).
- TeHCrAzY 16y agoBingo. You can also avoid the fun Enum.IsDefined that comes with it.
- rhythmAddict 16y agoI agree that it makes it "more readable", but that only would matter if intellisense wasn't working. I see the parameters, and they are strongly typed. In JS, this isn't the case, so it is much more helpful (e.g, I can completley screw up types/params and they will probably materialize as some strange behavior. As far as bools, I generally try to avoid having more one or two bools as an argument, unless it's required, and it rarely is. Obviously, all IMO.
- InclinedPlane 16y agoDo you have intellisense in your eyes? A line of code with a handful of named parameters reveals its intentions (and possibly also its correctness) for more readily than a line of code with a laundry list of parameters that you need to mouseover then do a bit of mental juggling to line up which value lines up with which parameter. In doing so you've likely interrupted and degraded your reading of the code and you've definitely degraded your ability to readily spot the difference between correct and incorrect code.
- rhythmAddict 16y agoActually, you guys are right. I realized the flaw in my thought process right after I read seasoup's post. I do, however, have intellisense in my eyes.
- j_baker 16y agoNamed parameters make code more readable when used properly. For example, which is more readable? var c = new Cube(1, 2, 3) or: var c = new Cube(height: 1, width: 2, depth: 3);
- InclinedPlane 16y agoThe real advantage of named parameters is the ability to have optional parameters as well. Which means that instead of: var c = new X(3, "blue", null, null, null, null, false, true, null, 1, null); (which, sadly, is an all too common implementation pattern), you can have: var c = new X(foo: 3, bar: "blue", baz: false, quux: true, wibble: 1); Which seems quite a bit better. Another advantage of named/optional parameters is that you can use them in the construction of immutable objects, whereas you don't get that advantage if you use settable properties.
- jules 16y agoThe in/out naming for covariance and contravariance is pure genius! It's much easier to learn and to determine which one to use compared to notations in other programming languages. It would be even better if out weren't already in use for something else, I agree.
- deleted 16y ago[deleted]
- frou_dh 16y agoBuh... I haven't read Jon Skeet's C# In Depth for C# 3.0 yet. Can I pass?
- WorkerBee 16y agoI have Jon Skeet's "C# In Depth" for C# 4.0 on pre-order. It's not out just yet.
- solutionyogi 16y agoI haven't read C# In Depth for 4.0 yet, but I would suggest that you should not pass on the 3.0 version. Here's why. C# In Depth is not like a technical reference book where the author rehashes the same information what you can find on your own at MSDN. Jon discusses the evolution of language starting from C# 1.0 up to 3.0. I sincerely wish that all technical books were written like this. If you are still not convinced and want the cofnirmation from someone more authoritative, let me point you to Eric Lippert's forward for the book. http://blogs.msdn.com/ericlippert/archive/2008/04/28/c-in-depth.aspx http://blogs.msdn.com/ericlippert/archive/2008/04/28/c-in-de... Eric Lippert is a senior developer on the C# compiler team and his blog is a must read for all C# developers. Coming to the main point, my guess is that Jon may be skipping on some details in the new version of the book which he has already covered in the current version. And I think it would be great idea to learn about the choices/compromises made by the language designers. Good luck.
- frou_dh 16y agoThank you. It occurred to me that it would be nice if the pre-generics artefacts were somehow erased from history. (They're essentially clutter in a space that's getting fuller and fuller, right?)
- jacquesm 16y agoI think I'll pass. I've passed on anything coming out of microsoft since about 2003 or so, and I feel much better for it. No more stacks of MSDN cds, no more 'support events' and so on. No more viruses, worms, trojans, piles of malware and other nonsense, besides license fees, subscriptions to stay up-to-date, re-installs every 3 to 5 months. Open source all the way for me these days, and I feel much happier for it. It's possible that C# is a great language and that I'm missing out on something that would improve my life in a way that I can not currently imagine but there always seems to be a price for that.
- kaddar 16y agoAlthough it was perhaps understandable, your cognitive bias has led you to avoid a useful modern programming language. C# works in Linux with Mono, and so although Microsoft controls the language, you can reap the benefits on a platform without the Microsoft stack of technologies, if desirable. Personally, I love C#, and use it at home for hobby programming, but not professionally.
- jacquesm 16y agoI'm aware of mono, but the 'heritage' has really put me off. The way microsoft has behaved in the past is such that if I can avoid using stuff that they have a hand in I will. It's true that that may 'hurt' me in the sense that C# is probably a great language, but there are so many 'great languages' that this was a luxury problem anyway. Between Python, Clojure and more exotic stuff like Erlang and Haskell there isn't enough time already. If microsoft had been a little nicer in the past they might have had an advocate in me, but enough really is enough. With some other big companies, such as for instance IBM I've got the feeling that they really understood and have changed their ways, with microsoft I've never lost the feeling that they still don't get that they were in the wrong and are still just trying to dance their way around the real problems without admitting that they were wrong and bettering their ways. I think that they will only change when the last of the 'old guard' at microsoft have stepped down from day to day management positions.
- 16y ago
- bfung 16y agoThe funny thing I come back to question myself with after seeing ExpandoObject and not needing to declare types (var blah = ), is, why not just go all the way to Ruby instead of being stuck inbetween?
- cema 16y agoAs they used to say, why not just go all the way to Lisp instead of etc? Just so as not to scare people off.
- rbanffy 16y agoOr Python, or Lisp... The use of .NET and C# (and Java) is often mandated by management levels, specially in large companies. For those unlucky folks, even a tiny little progress is a move in the right direction. Even if you want a .NET-like environment, you could use JRuby, Jython or Clojure and have a far better programming experience on top of the JVM. I really see no reason to even consider C# or .NET.
- jacquesm 16y agoMan the moderation in this thread is biased. Would whoever modded this down please explain how this is worth modding down instead of writing why you disagree with it?
- mquander 16y agoI didn't mod it down, but it seems intentionally shortsighted. I use both C# (for work) and Clojure (for fun) regularly; I'm a big Lisp weenie, and even I don't feel like I'm having a "far better" programming experience with Clojure than with C#. The language is somewhat better, but the tooling is somewhat worse, in my opinion. Saying those things are "far better" is just flamebait. If you're going to write such criticism, it's up to you to justify your statements, not up to other people to defend against a non-existent argument. EDIT: Stop modding me up, holy shit. This is off-topic and it's not important. Why do you want to highlight this self-evident comment so much that you're giving it a bunch of points? If I could have just messaged jacques instead of posting, I would have done that.
- urza 16y agohttp://channel9.msdn.com/pdc2008/TL16/ http://channel9.msdn.com/pdc2008/TL16/ Although from 2008, this is still an interesting talk from Anders Hejlsberg - the lead architect of the C# programming language. He outlines the future (now mostly present) of C# and describes the many forces that influence and shape the future of programming languages and explain how they fit into C#. In the end he talks a little bit about what is beyond 4.0 and he demonstrates the "compiler as a service", which is something I am looking forward to see :) In fact guys from Mono already moved things forward a little bit: http://www.mono-project.com/CsharpRepl http://www.mono-project.com/CsharpRepl I like where this is heading.
- mquander 16y ago2003, Guy Steele: "And you're right: [the designers of Java] were not out to win over the Lisp programmers; we were after the C++ programmers. We managed to drag a lot of them about halfway to Lisp. Aren't you happy?" 2008, C#: Three quarters of the way to Lisp!
- pbz 16y agoHere's a more recent one: http://channel9.msdn.com/posts/matthijs/Anders-Hejlsberg-Trends-and-Future-Directions-in-Programming-Languages-DevDays-2010-Keynote/ http://channel9.msdn.com/posts/matthijs/Anders-Hejlsberg-Tre...
- urza 16y agoThanks.
- statenjason 16y agoWe switched over in our shop on release week, and I must say that I'm enjoying the new features of .NET and C# 4.0. COM interop with Office Communicator is cleaner. IronRuby + Sass for css with ASP MVC rocks. Optional parameters have killed off many pass-through overloads. Also, DynamicObject and IDynamicMetadataProvider give potential for the dynamic keyword goes far beyond ExpandoObject. It opens up possibility for new DSLs within C#. Although likely to be misused, having the power to manipulate the meaning of the language is an impressive feature.
- motters 16y agoI have written a fair amount of C# code, although not so much recently. I think Microsoft are in danger of crowbarring too much into this language. Ideally I think they ought to start looking at rationalising and simplifying the syntax rather than adding ever more stuff to it.
- TeHCrAzY 16y agoThere isn't a great deal of actual "new" features. Alot of the fixed, such as "IEnumerable<Object> objects = new List<String>();" are just filling out gaps in implementation. I have a large amount of just written code that is dying for the above feature, not to mention optional+ named parameters!
- preek 16y agoMy 2c on that topic: http://blog.dispatched.ch/2010/05/10/c-40s-dynamicity/ http://blog.dispatched.ch/2010/05/10/c-40s-dynamicity/