C#, did Microsoft just want to be different?

The coalesce operator ?? and the elvis operator ?: are functionally the same.

Basically it’s a limited form of coroutine. It is very useful for people who want to write implementations of Iterator; I haven’t seen many other uses for it.

I think C#'s approach to lambdas is slightly better than Java’s, although both of them would be improved (for the user - maybe not for the compiler implementer) by being more functional. Effectively they both require you to define a placeholder (respectively a delegate or a one-method interface) for the type. I would rather just be able to specify something of the form (String, String) => int as the signature.

Exactly :wink: Sorry, irony not clearly specified!

Ah, but then how would you write the receiving end, as it were? Gotta start from something in Java - that’s just the nature of the beast. I can live with it.

You know what else would be nice? Blocks of declarations:


public static final {
..vars here...
}

private {
...
}

That’d save a lot of boilerplate typing that you literally see everywhere in Java code.

Cas :slight_smile:

[quote]All exceptions are unchecked
[/quote]
Forgot that. Not really a killer feature but I like that too.

[quote]Coalesce
[/quote]
As ? is already an operator I don’t find it that evil. But I understand your concerns. Nice thing is that you don’t need to use it.
And the definition what it does in c# is very clear.

[quote]For various reasons but mostly because it hides stuff I like to know.
[/quote]
This is as I said before… If you use it wrongly you can hide stuff. But there are still many places you can use to shorten the code without losing information. This is also a very controversial topic in the c#/.net
community, so you are absolutely not alone with your dislike for var. There are some stack overflow discussions about this topics… Probably might give
you some different perspectives on the topic:


I need to check but I’ve read an interview with one of the language creators where he explains why they introduced var and what it should be used for. But not really sure where I read that. Google yielded no good results :wink:

[quote]Nullable Types
[/quote]
Sure, you can do something similar in java. It is still nice not having to declare a reference type to hold a value type. Also I find it’s notation (? ) very nice to read, for example if you use it on a data model, entity or so. For example, when you’re used to c#, you read “int? value” automatically as “nullable int value”. Just a tiny improvement, but if it helps by not having to implement some wrapper classes, I’m happy to use it. (also things like entity framework use this notation to set db constraints).

[quote]Extension methods. Seem like a great idea but I started to get an uneasy feeling about them after a while.
[/quote]
I think this is because they change the way you program. In c# the introduction of extension methods lead to an increase in “functional” style libraries, code examples etc. classic c# (.net 1.1 - 2.0) is very similar to java 1.6/1.7. But since the 3.5 .net framework release a lot has changed. The code is less and less control code (for, if, switch) and more and more just “functions” and lambdas etc. Extension methods are used by many libraries to do very clean, decoupled libraries with nice tools that can be enabled by just including a namespace. Extension methods are now an integral part of the .net framework, and even if you don’t create them directly, it is hard to not come around them. So it is good to know how they work (think you already know that), if you are required to use them.

[quote]Type erasure
[/quote]
It’s not the end of the world, but actually it can be very handy to be able to instance a type based on the generics parameter. It makes some things (data generation/mocking, factories, IOC, dependency injection) simpler to do. I don’t say that you can’t do it with java, but with java you require some more boilerplate code to setup certain things. I don’t come accross problems with this often, but when I’m usually annoyed about what I have to do to get it running with java. But now I usually try to avoid situation where I would need this info in java.

[quote]Things that are in Java which are excellent ideas: the <> operator, which removes large tracts of crappy redundant typing static import, ditto lambda syntax, ditto, plus bells and whistles final, which works in a lovely consistent way for instead of foreach. Consistent use of keywords!
[/quote]
The <> is actually a nice addition. Would like var even more… But true, c# doesn’t have an equivalent (because most cases are handled by var :wink: ). Static import: This one is actually nice. But also, in many cases where you would use this, c# uses extension methods, which I find even niftier :wink: Lambda Syntax: Don’t really know the java lambda syntax. I like the one from c#. final: Yes, final, readonly, etc. is a bit of a mess. foreach: I disagree on this. For me this is semantically a different operation (and I don’t like it if you have a keyword that does two different things, see final XD). I don’t prefer one way or the other, but I don’t see a problem with the foreach naming.

[quote] The ability to specify byte and short literals with suffixes a la longs (dunno if C# has these)
[/quote]
Nope, doesn’t look like it: http://stackoverflow.com/questions/5378036/literal-suffix-for-byte-in-net

I’m not really sure if this is the same. Can you do this with the elvis
operator:


return valueA ?? valueB ?? valueC ?? valueD ?? valueE ?? valueF ?? "defaultValue";

It is a compiler hack which let’s you implement IEnumerable without having to implement anything (the compiler substitutes the required classes). This can be very useful if you are processing large streams of data or lists. Also, nothing java could not do, but it is nice that this is implemented as language feature.

[quote]dynamic
[/quote]
Dynamic is nice because it let’s you create dynamic objects. Imagine doing a SELECT * FROM BLA and directly mapping the results to objects, without having to know the column names at run time. The micro orm dapper (which is developed by the stack overflow creators and as far as I know used as orm for stack exchange) makes heavy use of this feature.

Ah I forgot one feature I really love about c#. The using statement. C# has an interface IDisposoble. If you have an object that implements this interface, your can wrap your operations on this objects in an using statement. When the code exits the using block, all used resources are being disposed automatically.
how this looks like:

 
Table table = new Table(); 
using(var connection = new SqlConnection(".")) 
using(var command = new SqlCommand(connection))
using(var adapter = new SqlDataAdapter(command)) {     
	command.CommandText = "pr_LoadData";     
	command.CommandType = CommandType.StoredProcedure;
   	adapter.fill(table); 
} 
return table; 

In this example, connection,
command and adapter are all classes that have resources that need to be
disposed. This happens automatically, once “adapter.fill” has run.

[quote=“pjt33,post:41,topic:52128”]
This is the approach taken by Kotlin, if you’d like to try that in a JVM language.

According to this presentation by Brian Goetz, they started exploring lambdas with functional types and later redesigned it to the current functional interface convention. The reasons are solid and the solution surprisingly suitable for the Java ecosystem. Oracle did a fantastic job with Java 8 imho and I’m nothing short of excited for what’s coming next (projects Valhalla & Panama).

The slow but steady progress of Java the language is a good thing. There are also tons of options, so many different JVM languages, if we’re just talking about language features. Most have perfect interop, you can just use whatever you need to use to be productive and can always fallback to Java when you have to. Exploring different languages and programming approaches is also a good thing.

Type erasure sucks. The only cool thing about type erasure is the hack to convert a checked exception into an unchecked one. The real problem here (for me) is the “knowns” available to back-end compiler.

Actually, I’m lying. Type erasure just sucks. Consider type refinement.

Seems Valhalla awaits and is the end to all our woes, and includes endless feasting and maidens too.

Cas :slight_smile:

Some of the new features in C#6

http://www.dotnetcurry.com/showarticle.aspx?ID=1042

Getting increasingly messy, hm. Some good things in there… some facepalmy stuff.

Cas :slight_smile:

Most of this stuff seems like attempt to avoid boilerplate code… By adding unreadable code. :slight_smile:

yet, operator overload beats it all.

Actually, I don’t think “workspace” is any kind of de-facto standard. In IntelliJ Idea, for example, the equivalent of an Eclipse “workspace” is called a “project”, and the equivalent of an Eclipse “project” is called a “module.”

http://blogs.msdn.com/b/dotnet/archive/2014/12/04/introducing-net-core.aspx

[Quote] NuGet as a first class delivery vehicle
[/quote]
Wohooo :smiley:

I’ve been using C# for three years, and I think the implicit operators are my favorite thing that Java still has to catch up on. And, that Winforms visual editor is kick butt.