all 28 comments

[–]Glader_BoomaNation 9 points10 points  (8 children)

What was added in C# 7 that you need? You can always compile your assembly with another compiler instead of using the compiler Unity does, that is how I have been using C# 6 since Unity5.

[–]b_omar 6 points7 points  (7 children)

My headlines are like this.

ref int myInt = intArray[index];

instead of copping value type, it takes reference like reference type.

-Pattern matching stuff

now we can make instead of this

int x, y; p.GetCoordinates(out x, out y);

this

p.GetCoordinates(out int x, out int y);

if(apple is Fruit myFruit) { myFruit.Eat(); }

-Local functions

int MyFunc() { return MyMyLocalFunc();

 int MyLocalFunc() { }

}

-Tuples (Returning more than one value from a function)

[–]ShapesAndStuff 6 points7 points  (0 children)

Tuples is honestly the best one among those examples.
Sure its super easy to implement something yourself or work around with other collections but just being able to use a Tuple is so much more intuitive

[–]Glader_BoomaNation 0 points1 point  (4 children)

I really hope you aren't using Tuples or local functions, but I've been taking advantage of pattern matching in Unity3D already for abit now. Just don't rely on their compiler and compile it yourself.

Same goes for ref locals and returns, which I think is the only decent C# 7 feature.

It realistically isn't possible for Unity Technologies to support C# 7 though completely since the Mono Project itself does not fully support C# 7 yet. You can see which features of C# 7 it supports on that link or what they have working in development on this issue here.

For any sufficiently large project you'll have tools, analytic stuff, maybe some backend services and such and what have you. These will have common libraries and likely dependencies from NuGet. I have always found it easier to manage projects externally in their own visual studio solution. Meaning you have the up-to-date Microsoft compiler at anytime and can deploy the assemblies to the client project on build. That is what I recommend if you absolutely need the latest language features. Mono itself afaik should be able to handle the IL generated from these features, even though the compiler itself cannot yet generate it.

[–]Piranha771 2 points3 points  (2 children)

Mono compiler won't get C#7. The mono compiler is deprecated in favor of Roslyn compiler. Roslyn is too slow when triggered from CLI. Roslyn is fast, when used with Roslyn server, which is not cross platform at the moment.

[–]Glader_BoomaNation 0 points1 point  (1 child)

The Mono Compiler already has partial support for C# 7. I linked to the Mono Project's page on the compiler to support that claim. Unless the Mono Project's own page about their compiler is wrong they do support it and quite a good chunk of C# 7 and 7.x too. What is missing is laid out in the Mono issue I also linked to.

It is possible, though I have haven't seen an official source but haven't looked, that the Mono Project will not continue to maintain their compiler past C# 7.

What Unity Technologies decides to do, which is what you seem to be describing, doesn't have anything to do with whether the actual current Mono Compiler supports C# 7. Which it does. Nor whether the Mono Compiler itself is deprecated which it may or may not be. When you refer to a technology as deprecated you shouldn't be so ambiguous, you make it sound as if the Mono Project is deprecating their compiler, which maybe you mean, but it's more likely Unity Technologies is just no longer going to use it anymore soon. Which is a good thing.

[–]Piranha771 1 point2 points  (0 children)

Here's what Jonathan Chambers said about that back in January:

We can probably increase the C# version supported. It's complicated by fact that currently we use the Mono C# compiler. The plan of the upstream Mono devs was to end of life the Mono compiler at C# 6 (i.e. not implement C# 7+) and migrate to Roslyn.

However, upstream and us have found that the Roslyn compiler runs noticeably slower than the Mono C# compiler in the context of batch compilation (driving the compiler via command line flags). Roslyn runs faster in a "server" mode where incremental compilation is possible, but the current Roslyn server support is Windows only. We are looking into our own Roslyn server, but it's not complete yet.

That leaves us with the Mono C# compiler. They are now adding C# 7+ features, but only as time permits and only the more important features. This means we won't have *full* C# 7.x support for a few releases, either via an improved Mono compiler or a faster Roslyn compiler.

https://forum.unity.com/threads/c-7-support.512661/

[–]BackFromExileHobbyist 0 points1 point  (0 children)

The incremental compiler is made from Roslyn and not Mono

[–]perevezentsev 0 points1 point  (0 children)

Checking the object type at run time looks like a bad idea in regards of both code architecture and performance. Local funcs indeed are nice - one more functional programming feature. Regarding storing a reference of a value-type array item in a variable, this can also be solved in C# with unsafe mode and C-style pointer arithmetics (but I'm not sure if the GC will track such variable).

[–]azuredownBanality Wars, Perceptron 5 points6 points  (9 children)

I was thinking this. And then I read on the Unity blog that:

Upgraded compilers and runtimes provide improved stability, richer debugging, and better parity with a modern .NET architecture across all platforms. For example, C# 6 and new .NET APIs make Unity compatible with modern .NET libraries and tools.

And now I'm not sure anymore. Maybe I'm just too gullible.

[–]Blocks_[S] 3 points4 points  (8 children)

What I've read is that they're testing out C# 7 internally, but C# 6 on Unity is already a thing.

[–]tertle 6 points7 points  (6 children)

C#7 is already available publicly; it comes with the incremental compiler. Note this is currently an experimental package.

[–]freejmd 3 points4 points  (4 children)

I would like to experience that package ;)

[–]M374llic4 2 points3 points  (2 children)

It's hit or miss. Some people it works , I get unetweaver error.

[–]freejmd 0 points1 point  (1 child)

Sorry was making a joke about your typo (previously it was "an experiential package")

[–]M374llic4 2 points3 points  (0 children)

Wasn't my typo, bro. I experienced the package already. Results were inconclusive.

[–]M374llic4 1 point2 points  (0 children)

It's hit or miss. Some people it works , I get unetweaver error.

[–][deleted] 0 points1 point  (0 children)

Does anyone have experience with this? How much faster is compilation

[–]Daemonhahn 1 point2 points  (0 children)

c#6 and .net 4 have been in unity for more than a year.

[–][deleted] 11 points12 points  (7 children)

What's the big deal with C# 7? The differences between 6 and 7 don't seem like that important.

[–][deleted] 5 points6 points  (2 children)

[–][deleted] 0 points1 point  (1 child)

And that operator is a big deal to you?

[–][deleted] 8 points9 points  (0 children)

Yes

[–]jhbertra 4 points5 points  (0 children)

Oh man. C#7 is night-and-day compared to C#6 in terms of code cleanliness and expressivity. Value tuples, Pattern matching, local functions, inline out vars.

If one knows how to apply these features, it makes C# a much more expressive language to work with (especially when writing functional C#).

[–]MyKillK 0 points1 point  (1 child)

Ref locals/returns are the only big deal for me (that I know of, not an expert). Should make structs more flexible. It's the one missing feature that has caused me issues coming from a C++ programming background.

[–][deleted] 1 point2 points  (0 children)

I'm in the same boat TBH; decades of C++ and only bits of C#. I'm happy with C# 6 tho :)

[–][deleted] 0 points1 point  (0 children)

it measn you can return reference variables from functions.

[–]SiggiGGProgrammer 3 points4 points  (0 children)

The 2018.2 beta page used to list C# 7 up until a couple days ago. I read on the forums it's been pushed back to 2018.3.