views:

1355

answers:

15

This is a discussion that pops a from time to time in our team. While a few quickly learned C# 3.0 features, other stick with classical techniques.

Some never use Linq, think that lambda expressions are confusing and yield is "scary". Sometimes they can hardly understand code that is written by people using all the new features. We can just say that they do not master the language and should learn it.

But how hard should it be to learn a modern programming language? Everyone can solve the problems, everyone has many other problems to solve every day than to care about nicer ways to implement it. Training people is not for free. On the other hand, language features can make people more productive and code more maintainable.

Probably incomplete list of C# features

  • classes, structs, primitive types, arrays, boxing, interfaces, inheritance (abstract, virtual, new, sealed), properties, nullables
  • exceptions
  • generics
  • multi threading, locks
  • reflection
  • delegates, events, anonymous delegates
  • iterators
  • lambda expressions
  • extension methods
  • linq

Version 4 is coming soon including many additional features.

Personally I like almost every feature of C# and like the short and nice code I can write with this language. But I don't have to learn it from scratch.

I'm interested in your opinion and your experience with learning or teaching C#. Are there already too many features? Are still important features missing? Are the language features making the language easier to use or just harder to learn?

Please: No answers like "Language A is better than language B because...".

+7  A: 

In my opinion, C# does not have too many features. Almost any of the fancy newer features from 2.0 and 3.0 is of every-day use to me and my co-workers, and even the VB guy quickly picked them all up. Some of the new features make learning the language even easier, like using inline lambdas instead of delegates and the var keyword and object initializers, just to name a few from C# 3.0 (there is no C# 3.5, by the way, you're confusing that with .NET 3.5).

C# has been made simple in most cases and the powerful features are all easy to use, unlike C++, where the designers say that you can do absolutely everything with C++, but they never mention that many things tend to become a real pain, which happens because C++ just can do really everything, including many things that most programmers will rarely, if ever, use. Supporting everything means that many things are more complicated than necessary, making it harder to learn. That's the difference between a language where features make it hard to learn, yet very powerful and a language where features make it easier to use and improve productivity, even though being less powerful in theory.

And, in pure number of features, C# is far away from C++, especially if you include C++0x in this picture, making it easier to learn despite having "too many features" for some people. My point with C++ was rather that C# doesn't really have so many features, if you want.

OregonGhost
"Even the VB guy" . . . Dude, would you like to explain that?
Binary Worrier
BTW: My down vote is for the C++ portion of your arguement, which is poorly expressed, and fails to carry it's point, imho
Binary Worrier
The "VB guy" is a programmer that is used to develop in VB, and was therefore not really used to program curly brace languages like C, C++ or C#. But he quickly picked up C# with all the new features despite coming from a very different language background, that's why he serves as an example that the features in C# are not too much.
OregonGhost
Actually, I get the "difference between a language where features make it hard to learn, yet powerful and a language where features make it easier to use and improve productivity" bit (and I agree), but the bit that rambles between "unlike C++, where the designers say . . ." and your conclusion, doesn't really say anything
Binary Worrier
So the "VB Guy" could quite equally be the "Delphi Guy", or the "Small Talk Guy", OK. I was afraid it was an example of instutional VB programmer bashing that happens from time to time. I'm tired of people looking down thir noses when I say I work with VB these days (it's a job). I'm also a C, C++, Delphi, C# etc guy. Thanks for the clarification.
Binary Worrier
I tried to make the thing about C++ better. Not sure if my point is really understandable now, I'm likely biased because I perfectly know what I mean ;)
OregonGhost
I like the edit, makes things clearer, downvote removed. Apologies mate, I'm a little tightly wound this morning, and have come down harder than I should. Have a good day mate
Binary Worrier
@Oregon: It's hard to compare the amount of features of C++ with C#. But certainly C# has much more useful features, while C++ has this kind of hard-to-learn-but-doesn't-help-much features :-) @Binary Worrier: I thought you voted for closing the question?
Stefan Steinegger
A: 

The features are the reason we use C# and what make C# 'modern'. If C# didn't offer classes for example - or multi threading for that matter, would anyone use that? Assembly is an example of a language that really has no features. It's silly easy to learn as a language but no one wants to use it.

The small domain specific languages are really an extreme on this. Take the classic regular expression for example. It got a HEAP of features just for string manipulation. If it didn't have these, who would use it? These features are what make it so powerful and expressive. Same with more general languages.

It's not like all of these features are required for writing C#. Understanding C# code is where the problems appear. But if these were not features in C#, everyone would implement multi threading in their own way and instead of learning the one way to deal with multi threading, you'd need to learn several depending on the code you are reading.

Mikko Rantanen
+16  A: 

Yes, it is a risk - and it gets discussed a lot. It is getting to a point where it is very hard to pick up C# from scratch. Fortunately, things have stabilised a bit, and the language changes between C# 3.0 and C# 4.0 are relatively minor.

Actually, I've recently been doing a lot of work trying to fix a CF generics problem, and as part of the fix it might actually happen that the code reverts almost to C# 1.2 techniques (no, or very few, generics). So most problems can be addressed with the simpler language constructs. The point is: how hard should it be to do something?

For example - anonymous methods add a LOT of benefits for relatively little complexity. dynamic (4.0) adds some more for the COM interop scenarios. Iterator blocks are invaluable for LINQ-style code...

I see a lot of questions about the non-trivial parts of C#, and I think I would struggle to teach a beginner all of C# from the ground up. Books like Jon's C# in Depth are good for people who already know the basics (at least C# 1.2; ideally some C# 2.0) - but it is not really designed for newbies (I know Jon won't disagree).

A tricky one indeed. Fortunately, the C# team set the bar (for inclusion) very high; something new has be be very useful to make it into the language.

Marc Gravell
how hard should it be to do something? - Ideally it should be easy to do things right, and hard to do things wrong... YMMV
CurtainDog
Now define "right" and "wrong" in the context of code design... getting developers to agree is like herding cats.
Marc Gravell
@Marc: Thanks for your contribution. I hope it gets continued by the community.
Stefan Steinegger
C# is a great language with a lot of great features, however it does add a fair number of them at the expense of ease. The safest introduction for a new .NET developer is still VB.NET, which is much more descriptive/verbal than C# but shared many of the same features. Once VB.NET is fairly well understood then C# can be a truly enlightening language--and the efficiency gains can be best appreciated. C# is fine with its high barrier to entry, but the more advanced features are likely to be ignored by a green developer under they can grasp their purpose and gains.
STW
@Yoooder - personally, I not sure that a more verbal syntax is going to make a huge difference, but there we are...
Marc Gravell
C# ain't that hard. You don't have to use all the features, right? So learn some and keep expanding until you know them all. BTW: I couldn't imagine coding without lambdas :)
Alex Baranosky
Speaking from experience (I've been trying to jump from Java to C#) - I don't think it is too hard, at least not yet. I'm on day 8, and am getting to the point where non-trivial code is now fairly easy, taking advantage of lambdas, delegates, events, (no LINQ yet - haven't had a situation where I need it). I know I'm no expert yet, but getting in at the shallow end of the pool isn't hard.
ehdv
A: 

I'll try to answer your three main questions.

Are there already too many features?

In a short answer: I don't really think there is something as 'too many features' in a language, as long as the API / framework is consistent and clean.

Are still important features missing?

There are still things that would be a great addition to the language. From the top of my head: co- and contravariance, but we'll get that in C# 4.0. Support for immutable types would be nice. AOP-based features.

Are the language features making the language easier to use or just harder to learn?

Every new feature gives you something new to learn, but that doesn't make it harder. I'd rather program in a language where there is something new to learn every day, than a language that is never updated. Moreover, I think LINQ and Lambda expressions generally made C# 'easier' to use.

So in short, I think the new features are great. Personally, I can't wait for C# 4.0, nor any new version beyond.

Razzie
A: 

Yes , C# do has lot of features , and it is not my opinion , this is a fact, this is a rich platform. If anyone want to argue about that and claim that this language doesn't have lot of features , please show me a language that do have lot of features and explain why it has so much more features then C#.

Anyway, I don't see any problem with it. You can always chose the subset of the features that appropriate to you and use them. there is nothing wrong with a language rich of features , as long as the features are used correctly and not enforced to the code only because they exist.

That's the problem, you can't pick the subset of the features, because you won't understand the code written by others. You can't contribute in a team.
Stefan Steinegger
My local library has a children's section, a young adult section and an adult section. What about yours?
John Saunders
@yossi: Who is arguing about the amount of features? Don't really understand what you mean with the first paragraph. @John: not sure if you ask me. These sections are surely nice. But it is a library. Language features are always there and you need to know all of them.
Stefan Steinegger
@Stefan: no, you don't need to know all of them, unless your project is mismanaged. Maintainability is important, and allowing arbitrary use of all advanced language features throughout a code base is not maintainable, for the reason you cite. You don't expect junior programmers to maintain complex multi-threaded code using the most sophisticated lanaguage features. So don't _do_ that.
John Saunders
@John: Yes, I agree with what you say. But we are not talking about the same. It doesn't make sense to forbid programmers to use lambda expressions or linq or extension methods. They mostly need to do it, because they use interfaces which are based on it. For instance the RhinoMocks 3.5 makes use of lambda. Everything was simpler and beautiful, but some programmers didn't use it because of the "strange arrow". You know what I mean? I expect of everyone that he knows the language features if he wants to write applications with that language.
Stefan Steinegger
+2  A: 

You probably should read this blog post by Eric Gunnerson, a member of the C# compiler team at Microsoft.

He explains how new features make there way into the language. Basically they get "-100 points" in the beginning, "which means that it has to have a significant net positive effect on the overall package for it to make it into the language."

0xA3
+2  A: 

There is actually a lot of debate on how C# should evolve. Indeed, some consider that by adding a lot of new features the language becomes to difficult to learn, but most view C# as a multi-paradigm programming language. It is first of all a strongly-typed full-featured object-oriented language, but it does have concepts that until recently were restricted to functional and dynamic programming languages. These features, though they might seem confusing for a beginner, offer a lot of flexibility and power, and sometimes they might prove enough to keep you from using a domain specific language in the application and dealing with all the integration issues. You can always talk about what should be implemented in the language itself and what should be part of the framework, but keep in mind that most of the features you mention and consider as superfluous are actually the result of the developers' requests, and they do provide functionality that sets C# apart from other languages (Java comes to mind). Once a programmer gets uses to these features, he will come to realize their advantages.

You mentioned Linq, and I have to admit I was a bit skeptical at first, since I have always considered SQL to be quite a natural language to work with data, but now I really like and I do see the advantage of having queries evaluated at compile time. Lambda expressions are always nice, indeed they can make the code hard to read if used excessively, but sometimes they actually simplify it. I'm not a big fan of the 'var' keyword but sometimes it does come in handy, and let's be honest not using it when writing Linq would make the code difficult to read. I'm a beginner programmer myself, and I don't think it is difficult to learn these concepts. I also use Java a lot in school, and I really miss some features of C# (I'm not saying that Java is a bad language, on the contrary, in some regards I think it is better than C# - code contracts, especially for academic purposes).

iulianchira
I didn't consider anything as superfluous.
Stefan Steinegger
You mean Java has language-level code contracts, or is a framework feature?
Rafa Castaneda
A: 

Eventhough I'm only a casual C# user; with strong background in Delphi, C++, and Python; I can grasp C# features concept quite easily. C# is a properly balanced language in my opinion. The only annoyance is that I could hardly remember enough syntax (especially Linq-related) in my head to produce code in touch typing speed like I can in Python. My preference toward pascal syntax could also impeding me. However, with help from the almighty Visual Studio.NET Express, this is not a problem at all.

As long as they provide such an amazing tool for free, I believe C# with VS.NET is among the best coding environments available.

Sake
A: 

I too like most of the new features and quite honestly wouldn't want to lose extension methods and linq in general.

As far as ease-of-learning goes, I think the issue is more a problem for new starters - and from experience, getting them up to speed is definitely a case of selecting the biggest wins and helping them out when they stumble onto something else. Aside from multi-threading, understanding generics seems to be key to getting the benefit of the other features.

Each additional feature does definitely bring additional benefits. Eventually new languages will come along that make those same features easier to use, but that doesn't in any way mean we shouldn't try to improve the ones we have now.

chrisb
+1  A: 

I don't think learning the new language features is the part to worry about: learning the right situations in which to apply them is what takes decades.

Sometimes they can hardly understand code that is written by people using all the new features.

This is the real problem that you need to address. A code base fractured into different styles and not maintainable by everyone is an expensive code base to maintain. Using novel features to write "short and nice code" may not maximise the utility of that code for your organisation.

What's the root cause of your situation? Is it:

  • Some programmers don't understand the new features
  • New features have been used inappropriately
  • New features have been used to hack around design flaws (often the case with reflection)

I would bet money it will be a mixture of the above.

Alex
It's not that we have a big problem. But a typical situation is, that I ask someone why he does not use the new RhinoMocks interface, and get the answer "Oh, it's using this strange arrow." It's getting better day for day, but there are still other features to learn.
Stefan Steinegger
@Stefan: What's wrong with learning?
John Saunders
@John: Learning is brilliant. As a programmer I want to learn new language features / patterns / code smells every day. But from a business perspective things _may_ be different. E.g. in a coding environment with high-turnover and poor programmers, you would probably want to keep fancy features to the bare minimum, and ensure that everyone follows rigorous coding standards. Everything is a trade-off.
Alex
@John + @Alex, thanks for answering the question for me, Alex :-) There is nothing wrong with learning. But a programming language should not end in itself. You don't learn it to just master it, but to solve the business problems. Many programmers are working in a complex environment and their job only partially consists of writing code. They need to know the business, for instance logistics, chemistry, politics, finance etc. And they need to learn many tools. Human brain is limited. Or in other words: there are other, probably more important things to learn.
Stefan Steinegger
+1  A: 

Yes there are a lot of features - but that's what makes C# so powerful. But if people can't / don't want to learn these new features, then what are they doing? Is computer programming a career they should be undertaking? You're always going to have to stay on top of your game being a programmer, else you'll quickly turn into a dinosaur.

Mark Ingram
+1  A: 

Yes C# has a lot of features but that's why we use it! Anyone entering into a career as a programmer should expect to spend there career studying / learning new things and taking exams! As someone who loves learning new things, thats why we love it!

Personally, I find lambda expressions and extension methods for example, extremely useful. For creating larger scale distributed applications where I want to seperate data and logic I have found LINQ not to be so useful. But I look forward to c# 4 features such as optional parameters.

As @Alex mentioned, I think learning when to use features apropriately is the most challenging aspect. Horrah for those of us who have been with C# since the early days!

SiC
A: 

No

Long(er) answer: No. Its like saying can you have too much experience? you cant. You can pick and choose what features to use and learn and you can ignore what you dont need or dont want to learn/use. Features dont degrade a language. Using a feature poorly is using anything poorly. Until you break backwards compatibility or stop a better feature from existing then the feature is good (how ever it may not be that good).

acidzombie24
I don't fully agree. You can't compare the complexity you are facing with experience. And you can't pick just a few features and avoid the others, because you won't ever be able to work with code written by others. And who writes code all alone? You won't even be able to use API's that depend on these language features. So you always have to learn all of them, and you have to understand them well. Unless you should not say that you "know" the language.
Stefan Steinegger
I dont agree with the above. Theres tons of C# features i never used such as LINQ, events(is that what it is called), the yield keyword, etc. I never had a problem with a library yet. I call functions with the correct parameters as documented and use properties like they were member vars and so far not a single problem occurred. Although this is speaking as a programmer in a very small team (<=3) and not doing anything big with it.
acidzombie24
A: 

50% of the language features are useless

simpleprograms
As is 100% of your answer, and by extension 100% of my comment
Seth Petry-Johnson
I you don't want to get down-voted like hell, you should get a little bit more specific.
Stefan Steinegger
@Seth - I disagree. Your comment was quite useful to me.
Justin