Recently, I went back to C# for a smaller project. The .NET ecosystem certainly has its advantages compared to the “wild west” of NPM, which includes Visual Studio/JetBrains Rider.
My main problem was that the language feels so dated at this point. Why can’t I make local variables immutable? Why are there still no algebraic types? Why do the new nullability rules feel so inconsistent and tacked on, with “String?” and “DateTime?” behaving completely differently?
I realize not everybody cares about these “modern” features as much as I do, but once you’ve wired your brain to think about program composition in a way that simply feels better to you, it’s very frustrating to go “back”.
.
Edit: It’s not like the C# team is unaware of or in any way against these proposals. There just seems to be little visible progress:
Algebraic types: https://github.com/dotnet/csharplang/issues/113
Const locals: https://github.com/dotnet/csharplang/issues/188
It is basically: if we introduce it, it gives us a tiny benefit for a gigantic amount of noise during every single code review. It boils down to comparing developer productivity vs. language safety.
I find the argument a bit weak since code review guidelines can end this conversation AND C# has already quite some code analysis code fixes to auto-fix language usage stuff (like file scoped namespaces or nullability checks). And that case of const and readonly can be algorithmically checked.
But there are other groups at Microsoft which keep them on track with their real needs.
I suppose you can emulate it today with variable prefixes/suffixes and check the AST with a custom linter yourself
How it'd work in such a case:
You declare immutable variable "a" which's an instance of a class
and then you execute "DoSomething" method which mutates under the hood?
Compilation error? runtime error?
Anyway have you tried records?
Js has const, C has const, Java final.
Imho it'd be awesome if mutability were not the default and we would have to mark mutability, but until then any variable that doesn't need it, is final. Which also helps skimming code
C# has readonly and const
>Imho it'd be awesome if mutability were not the default
If they decided one day that - "let's make immutable by default", then it'd be performance hit - wouldn't it?
codeflo means to declare a local variable that cannot be reassigned later.
void Foo() {
// this is possible in C# today, but only for compile-time constants
const int Bar = 42;
// this is what codeflo wants: variables that cannot be changed after declaration, but can hold runtime values
readonly string text = $"Blah: {Bar + System.Environment.ProcessorCount}";
// with such a variable, you wouldn't be able to reassign it later:
text = "Some other text";
// the line above would be a compile-time error, just like trying to reassign to a readonly field.
}Not really. It's just a syntactic default, reassigning local variables should be discouraged from except for iterators etc. It just fosters bad habits.
For example, A list can still be mutated like usual, the reference however may not change. This usually allows compilers to do optimizations in multithreaded situations. But that's not why I code that way, it reduces the cognitive burden of keeping track which variables are actual moving parts as opposed to context/names etc.
> C# has readonly and const
Haven't written C# in a few years, GP was talking about variables as far as I can tell and their lack of immutability.
To your last question: Yes, records are really nice syntactic sugar for classes that want to behave like values.
And can be edited without unloading the project first.
I'm asking because I do use extensions like Roslynator for refactorings I'm not sure what I'm missing, what fancy Rider has?
Code formatting tool support was substantially better (although still not ideal) in rider than VS, and VCS backed project settings mean that we can have developers auto format locally rather than building out tooling to enforce it.
Cross platform support, with remote editing is also a huge one for me. I have a windows workstation and a Mac as a secondary workstation. Before, I had to remote into the mac and use XCode to debug/build issues on the mac, now I use rider with remote support for 95% of my mac needs, and on occasion when I do need to drop back to the mac, I'm using the same tool rather than xcode.
Until 2022 (which granted I haven't used), VS was 32 bit which despite MS's frequent assurances wasn't a problem, was. Running OOM was a regular occurance on large projects for me over the last 10 years.
I've been a happy R# customer since 2006. Since then I converted to JetBrain's all products subscription - DataGrip is a really nice database management GUI that supports nearly every database you could ever want (from SQL Server to Postgres to MongoDb!) If you do any frontend development Webstorm is IMO a much better experience than VSCode.
I'm not spending as much time as I like coding C# nowadays but keep the R# subscription up, it's invaluable when I need to get back up and running.
Since .net 6 things are changing more. Eg. The first time with a minimal API needs a bit of exploration. In general it's explained by global static functionality.
Blazer is c# and a different way of writing websites.
Asp.net MVC 4.5/webapi and before did not have IoC build-in.
I think you should reread what I said.
It wasn't there before, it is now. I didn't say anything about if it should be there.
Eg. I know an older developer who still doesn't see the benefit. So it's useful to mention that it's in there now.
Learn .NET Core (nowadays called just .NET). It is a fresh breeze to your memory. So easy, so rewarding compared to the complexity of Java or Node dependency trees.
How do Java dependencies differ much from C#?
Nice to read about all the changes in C#, I've been thinking a lot about going back to .NET, but at this point I would probably need some training. There are things like Blazor or .NET Core that I'm absolutely unfamiliar with.
I kind of miss Visual Studio for some reason, after what feels like a lifetime of web development in other open source tech stacks.