19 ms·
Thoughts on C# and .NET
For those of you who have experience developing in C#, what are your thoughts on modern C# and .NET? If you have experience with ASP.NET Core, can you please provide some random thoughts about it? Did you or do you enjoy developing with C# or ASP.NET Core?
- the_only_law 4y agoModern C# is a decent language. But legacy projects are still everywhere, and not only are they frustrating because outdated language version, but Microsoft is actively removing downloads for old .NET versions I need to maintain those legacy projects.
- Guid_NewGuid 4y agoThe bad: - Web framework is not quite on-par with Django/Rails. Particularly with auth/OIDC. - Job market is very sector dependent. Startups just don't seem to use C# whereas big enterprises do. - Some design decisions in the early days seem to prevent some features being added, e.g. structural typing or union types (not certain this is the reason). - Some days, like yesterday, your IDE updates and gets messed up and then it's back to writing full variable names like a medieval monk. - .NET is not really viable for non-server work. There is embedded/desktop stuff but you're going to have a headache outside of servers. The good: - When it's working properly the developer experience is like those dreams where you're flying. Rider or VS + Resharper make typing anything seems an incredibly antiquated way of developing. Intellisense means you barely ever need to type more than 2 characters to express your intent. Unlike my experience in Go or Python I just think about intent/data shapes and the tools fill in the rest. No language I've ever worked in comes close to reducing the ideas -> implementation effort barrier. - Type system. This is non-negotiable for me, plenty of syntactic sugar to make overhead of typing lower but because it's compulsory, types save so much mental effort and our production systems never wake us up, feeds into the above. You don't just have to reimplement a compiler badly through unit testing saving a lot of time. - Tooling, full framework used to be hell and very tied to the (paid) tools. Now with Core the tooling is great and Linux support is fantastic. Overall I don't want to work in any other language if I can stick to C# but the fact startups don't use it mean I might have to enter scripting language hell, again.
- aliswe 4y agoThis is poetry! Spot on.
- cweagans 4y ago> - .NET is not really viable for non-server work. There is embedded/desktop stuff but you're going to have a headache outside of servers. As an outsider to this ecosystem, desktop development is one of the things that has me interested in C# at all (built in windows stuff + Avalonia + Xamarin and the like). Can you elaborate this?
- Guid_NewGuid 4y agoSo I think the current/new desktop approach is MAUI, maybe, it's hard to keep track. When evaluating Microsoft/.NET stuff I think the safest approach is to ignore anything they come out with and check back in 4 years to see if it still exists. Desktop is the worst for this. Winforms and WPF are still solid choices if you need a Windows only UI and I think Avalonia is still going and might be good, I haven't really had an opportunity to evaluate it. But I think desktop still lacks a compelling cross-platform solution post-WPF and adopting early solutions from Microsoft will cause you many headaches and much sadness.
- WorldMaker 4y agoMAUI is the continuation/rebrand of Xamarin, most especially Xamarin Forms (as some of what used to be Xamarin is now just baked into .NET at lower levels). It's still more cross-platform mobile focused (iOS and Android seem to be the best tested platforms), though with support for full WinUI 3 and macOS Catalyst the lines are blurrier than ever between mobile and desktop development, especially if you are trying to write a cross-platform app. The biggest missing link for cross-platform desktop development in MAUI is Linux. (There's at least one open source fork working on a GtkSharp implementation/backend for Linux, but I don't know the ETA on that shipping.)
- ocdtrekkie 4y ago
- Raminj95 4y agoI love using C# to create games in unity as a way of keeping my love for programming alive. I dont know if its because its different from my daily job where i mostly write typescript and python as a dataengineer but I just really just enjoy the feeling of writing code in C# right now its just so refreshing. Its refreshing to have types and have to say what the return type is without it being some type of pseudo enforced type as mypy or typescript. But as others have said, c# in the wild is most likely for big enterprise software which is not always the most fun thing to work on.
- romanhn 4y agoAfter a long, intentional break break from the Microsoft ecosystem (more on this below), I recently kicked off a side project and was faced with the tech stack decision. After agonizing over Python vs Elixir, I landed on C#, unexpectedly. Reasons: static + strong typing is better for long-term maintenance IMO, extensive core library, solid database management, LINQ, excellent IDE, cross-platform support. The stack is ASP.NET Core with .NET 6 on the backend, React on the frontend, Postgres as the database. Not in production yet, but planning to make a lot of use of AWS, particularly Lambda. I'm loving it, feeling very productive and trying to take advantage of many of the new language and framework features. The biggest downside I've run into is that so much of the documentation and online material is geared towards older versions and older patterns. It makes sense given .NET's long history, but it's definitely been a journey trying to figure out modern best practices without ending up in an overarchitected mess (repository pattern everywhere!). The other thing I would say about C# is that I would never again interview with it, unless it was for a .NET position specifically. All the typing benefits work against it in a timed interview environment. Long time ago I picked Python up for interviews specifically and it was a much better tool for the "job". Now for some context. I developed in .NET exclusively for ten years, from 1.1 to 3.5. The development environment was great, but over time the Microsoft ecosystem began to feel stifling. Everything had to be done the Microsoft way, if you step off the rails, you'd be in a world of pain. It was a mega monoculture spanning the entire stack, with high tolerance for throwing away previous standards (so much churn with Webforms/MVC, LinqToSQL/various Entity Framework versions, all the WPF/WCF stuff, and I'm sure much more since then). In the mean time the open-source world was moving fast, developing new patterns and technologies, with Microsoft attempting to follow, slowly. I left the ecosystem in 2014 vowing never to return. Yet... the .NET Core cross-platform push intrigued me and the ability to write C# purely for backend APIs that can be deployed outside of Windows felt like a win-win. Time will tell, but so far so good.
- Ducki 4y agoWorking with ASP.NET Core full time (on a Mac with Rider), for me it is the most productive language/framework that I ever used.
- planarhobbit 4y agoEarly comment in the thread but I wonder if the overall “zeitgeist” opinion of C#/.NET/Microsoft has changed. Used to be in /. days that a lot of people stayed away from Microsoft stuff, preferring Python, Ruby. Then Stack Overflow came and things slowly started shifting. I do internal dev tooling in C#. It’s one of the best languages out there for raw “get shit done” prowess. I’ve used many languages throughout the decades, some more elegant than others. Like others, I’m a bit wary of the explosion of syntax shortcuts and alternatives, but whatever, its no big deal. It’s a great all-around, general purpose language. I would love to use F# more but I don’t think some decisions they’ve made would go over well with many people.
- jb1991 4y ago> I don’t think some decisions they’ve made would go over well with many people I'd love to know more about what you think and are referring to.
- BlargMcLarg 4y agoAt least looking at job boards, there's a problem with .NET mostly being stuck in its own stack with little overlap while many jobs existing scoff at the idea of e.g. letting Java and .NET devs jump from one to another. Which leaves .NET in a weird position of having to go all-in, even if it has a high market share. Without that stigma it's fine, .NET has a lot of answers to various things even if you have to deal with the Microsoft flavor. Similar to Java which still dominates most of the market in the same space.
- thedayisntgray 4y agoI had an internship where we worked with C# and .NET, and recently i inherited and application written on this stack. I would say I much rather would develop in Rails. Why? Currently, I don't have a ton of time to maintain the app and I was hoping to migrate it off of aws (since I don't have a ton of aws experience and mostly don't want to mess with it/ manage it) so I was looking to deploy on heroku which doesn't support C# as of now. - https://help.heroku.com/PAT3YEDU/does-heroku-support-net-applications https://help.heroku.com/PAT3YEDU/does-heroku-support-net-app... If you get past my gripe, I think it's much harder for new developer to pick up. I think Ruby/Rails and Python/Django were created specifically for developer happiness and ease respectively. I don't think it's going to be easy to manage this asp app (even though it isn't a large code base) Simply due to the fact that there is a lot of stuff I feel like I'll need to catch up on. When I look at other apps written for the web I find them to be "easier", whatever that means.
- bpicolo 4y agoThe third party buildpacks work totally fine.
- thedayisntgray 4y agoOh sweet, thanks bpicolo, I hadn't thought about that! I'll check that out.
- uticus 4y ago> Thoughts on modern C# and .NET Pros: - Excellent documentation and widely used (not just modern btw, MS documentation is world-class and has been for the ~8 years I've been exposed to .NET API documentation) - Excellent code structure, supports very large/enterprise type code bases - Mostly sane improvements, with regular rollouts - Now cross-platform (although ref [0] for what it's like to develop in a non-Windows environment) - IDE support is 5-star. MS own IDE is at least 4 star, and Rider (JetBrains) seems to be very popular as well. I've used three versions (pre-2019, 2019, and now 2022) at different paid levels, no big gripes. You get great debugging, profiling, REPL, etc. - Mostly opinion/experience: Allows for a range of styles, while IMHO balancing correctly with consistency that is easy to pick up and collaborate with. It is possible to write confusing code, but not as much as other languages (ref [1]). Cons: - It is cross-platform according to the docs, but in reality it comes from and is relied on mostly in a Windows world. - Testability - if you like unit testing, you will need to make everything testable also exposable - if not publicly, at least within the same assembly. > If you have experience with ASP.NET Core... Yes. It's pretty good. Apart from a question specific to the language or framework, you will need to quickly become familiar with how stuff works behind the scenes. It might also be beneficial to look into how deployment works, depending on your target (IIS, Azure, AWS, etc). > Did you enjoy developing... Yes, for larger projects that need collaboration. Otherwise I use Ruby. [0]: https://news.ycombinator.com/item?id=31520399 https://news.ycombinator.com/item?id=31520399 [1]: https://www.ioccc.org/ https://www.ioccc.org/ * edited for formatting
- monadmoproblems 4y agoJust on your point on Testability, I don’t believe this is the issue you make it out to be: my standard approach is to make all the types/methods I need to test ‘internal’ and then expose them to my unit test assembly using this assembly level attribute, https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.internalsvisibletoattribute?view=net-6.0 https://docs.microsoft.com/en-us/dotnet/api/system.runtime.c...
- feoren 4y agoI don't understand this logic. Test things that are public. You made them public for a reason. Those are what your class says it will do. Confirm it does what it says it will do and you're done with testing. I'm not sure I've ever used the "internal" keyword in 12+ years of C#. Assemblies are about deployment; public/private is about the contract your code is agreeing to. They have nothing to do with each other, so internal is an inappropriate conflation of concepts, by definition.
- starik36 4y agoI love it, but then I've been doing C# since the beginning. The language does appear to show its age though. I recently tried teaching it to my kid and realized that it has grown quite a bit of cruft. There are a ridiculous amounts of ways to declare a variable. Employee employee = new Employee(); var employee = new Employee(); Employee employee = new(); And that doesn't even count the initializers {}, records, dynamic, etc... All this makes it difficult for a new develop to jump into it.
- foepys 4y agoThe first two are not necessarily equivalent. If your class implements an interface you can type the variable as this interface and have different behavior if the interface methods were declared explicitly [1]. You can also use it to interact with for-each loops and some legacy (2.0 and prior) APIs and save yourself an explicit cast. The last one is a very recently added shorthand which, honestly, I think was just implemented because an intern needed a feature on master to get hired or something like that... I don't get it either. 1: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/interfaces/explicit-interface-implementation https://docs.microsoft.com/en-us/dotnet/csharp/programming-g...
- Semaphor 4y agoThe last one is great for field initializers where you can't use var.
- melony 4y agoThe first way is no longer recommended. You are encouraged to only use the latter two for readability (except for the interface object type situation mentioned in the other thread). > The language does appear to show its age though. Come to Java land. It takes decades to add a single feature. Grass is always greener.
- deleted 4y ago[deleted]
- ivraatiems 4y agoI'm a full-time C#/.NET developer, and have been for about five years. Here are a few observations: 1) As time goes on, C# is increasingly just F# with different syntax. LINQ, closures, records/immutable structures, and so on - you can write code in C# that is more functional than it is object oriented these days. This is mostly a good thing; it also means that (to my eyes) the language has become much more elegant over time. 2) The level of cross-platform compatibility you can get if you're using .NET Core or .NET 5/6 is pretty fantastic. Performance has also improved dramatically. C# is in no way limited to Windows as an environment anymore - unless you have a dependency on .NET Framework. 3) Everybody has dependencies on .NET Framework. Those who don't have dependencies on unmanaged Windows DLLs. 4) Great debugging/developer tools, as others have mentioned. VS and Rider are both top-of-the-line IDEs. 5) C# is not and will never be cool, sexy, or the thing of the moment. It is a language for getting things done in an easy-to-comprehend way and that's just about all it is. I like it very much.
- 62951413 4y agoHow realistic or common is it to mix C# and F# in one code base? As an example, even though Java and Scala run on the same JVM their ecosystems have mostly diverged. In contrast to the Scala situation F# has been officially supported by MSFT for years so it's probably different on the .NET.
- ocdtrekkie 4y agoThe compiler won't build a project using multiple languages, it doesn't understand. For a long time, VB code and C# code were 100% interchangeable, and they of course, both compile down to IL. (Identical IL code, in theory, if literally the same code reflected in different languages.) In theory, you would imagine that you could include .cs and .vb files in a single project, and the compiler could link them, but alas, it is not possible. There's no issues using a library written in one .NET language from another .NET language though, so if you can break the project up a bit more, you can work in multiple .NET languages.
- ivraatiems 4y ago
- brokenkebab2 4y agoIt's really hard to get an objective view of a lang asking for a random thought :-) C# has a decent number of fans acquired because of Intellisense mostly, there's also not an insignificant amount of people who find it "meh" (boring, Microsoft etc.) If you are asking to evaluate it as an investment - it seems to be a pretty solid choice, though employability of a C# dev differs between locations. If it's just for fun/pet project, then it's better just to give it a try.
- jayd16 4y agoC# is great and improving. A well designed and very pragmatic language. The dotnet core changes cleaned things up and made it feasible to build and deploy cross platform apps. I mostly use it for Unity and server code. I hope the AOT story continues to evolve and come down in size so I can start writing small utilities in it.
- cm2187 4y agoI think the language is great, if you can tolerate windows, it's a great way to write in the same language desktop applications, CLI and websites, and with wasm even web clients. It's the right mix of performance and high level language for my taste, and the tooling (visual studio) is fantastic. The integration with Windows makes a lot of things easy within a windows ecosystem. Also the self contained nature of the binaries makes deployment a lot easier than say python (everything is xcopy compatible with little dependencies on the client). However in term of recent evolution, I feel that under Anders Helsberg there was a focus on simplicity. Then Anders moved on, and anarchy followed, with multiple frameworks, multiple attempts to combine them into one framework, and ultimately the greatest of all sins for a language: breaking backward compatibility (.net 4.8 vs 6). And it feels everything is getting complicated, command line first, async everywhere which makes everything multithreaded, prone to deadlocks and hard to debug. The original c# had a great set of core libraries, however it has now fossilised. I think the owners of C# feel it is not their job to "update the batteries". So for instance their drawing library still doesn't support HEIC and might never do, they only added a json serialiser recently (yaml probably never). Instead you need to rely on a myriad of third party libraries with version conflicts, dozens of assemblies, and god knows if they will be available or maintained 10 years from now. So while I am heavily invested in C# myself, probably too much to switch now, if I had to start from scratch now, I don't know that C# would be my first choice. But the need to rewrite everything for .net 6 might give me the opportunity to do that however I really don't have the time for that now.
- timmytokyo 4y ago>I think the language is great, if you can tolerate windows I do most of my C# development on Linux. Not sure why you need to tolerate Windows to enjoy C#.
- cm2187 4y agoBecause you are missing out on the desktop UI capabilities of the language which is a great feature at least if you use it as a hobbyist like me. And Visual Studio. To me the IDE matters as much as the syntax of the language. And when I was a beginner having an IDE that can interact with my code as I type it is a massive help to progressing.
- Architrixs 4y agoJust wanted to add... C# being strongly typed language, some times can be a pain. Just spent an hour trying to parse a JSON String; changing its parts and again de-serializing it... working with JObject, JToken, etc..so on; Though i'm just getting familiar with it.
- setr 4y agoYou should be able to simply use Json.Deserialize<T>() ? The beauty of types in this case is that the JSON structure has a natural way to be expressed in C#… we just need to utilize it Or a JsonNode if you don’t know the structure
- WorldMaker 4y agoThis is where the C# `dynamic` keyword sometimes shines. It's a lesser known feature from a project called the DLR that tried to shake up the CLR to better support more languages like IronPython and IronRuby. Both IronPython and IronRuby kind of got scrapped/pushed aside, and the DLR never quite got the love it deserved, but what remains is still sometimes useful. If you are still using JSON.NET (Newtonsoft.JSON) (which you did mention its JSON LINQ JObject/JToken, etc.), it still supports the `dynamic` operator for working with JSON "more naturally": dynamic jsonObject = JObject.Parse(someJsonString); jsonObject.some.deep[1].propertyName = "Updated string"; return jsonObject.ToString(); // re-serialize the updated JSON You don't get much IntelliSense when using dynamic, but it makes it much easier to write what you want/expect to write with a JSON object than if you were navigating the JSON LINQ (JObject/JToken/etc) objects by hand. The documentation still includes pages on dynamic, even though dynamic has become a mostly forgotten feature and there are still developers that would never use dynamic. For example: https://www.newtonsoft.com/json/help/html/QueryJsonDynamic.htm https://www.newtonsoft.com/json/help/html/QueryJsonDynamic.h... I appreciate that dynamic exists in C#. I've done some wild things with dynamic over the years. It sometimes makes me sad how under-appreciated a tool it can be. ETA: Obviously dynamic is not type-safe, it's a great escape hatch from type safety for small cases where "just do what I want" is nicer/more natural than type safety. As the sibling comment points out, if you still prefer type safety there are type deserializers that can be easier to use. These days with records in C# 9+ writing quick types to deserialize to is even relatively painless.
- pipeline_peak 4y agoComfortable language, great ecosystem. But it’s Microsoft Java, so to make a career out of C# inevitably means boring enterprise work. There are exceptions like Game Development of course.
- SantiagoElf 4y agoI have used C# for almost 21 years, so far. Written for .NET Compact Framework, ASP.NET 1.1+, WinForms, MSMQ, back-end server code, you name it. Nothing beats this language for getting REAL work done in my books. Tooling - Visual Studio absolutely unmatched. Core Lib/Type System - one of the best. ASP.NET Core - great rewrite of the old ASP.NET. Very fast. Runs everywhere. C# as a language has evolved very, very nicely and I try to use the new feature whenever it makes sense.
- kumarvvr 4y ago.NET Core and C# are an awesome way to program a plethora of apps and services. The bloat is a bit much, but once you get used to it, its a damn good eco-system. Bloat is also being rapidly shed with many improvements. .NET 7 (the upcoming version) is going to be even better. The programming and architecture practices recommended by MS are great for most apps.
- bertylicious 4y agoI've been developing with C# professionally since 2012. I'm using dotnet core since the 3.1 release. Pros: - Superb IDE. Nowadays even without Resharper, which was a must have in my early C# days. - Massive standard library and extensive documentation makes for a very productive development experience (especially backends). - dotnet core was a huge leap forward in terms of dev tooling (sane cli, 3rd party integration) and framework flexibility (configurability in general, config by code instead of XML) - Microsoft keeps adding language features copied from functional programming languages. Cons: - Enterprise culture is very pattern-centric and produces much boiler plate code. That's the main reason I want to move away from dotnet. - Desktop apps are not cross-platform and I don't trust their newer stuff to deliver on that promise. The older WPF is outdated (e.g. no inbuilt support for "newer" features like async/await) because of their focus on Xamarin and MAUI or whatever new fad they come up with. - Microsoft seems to swallow open source libs by integrating them or copies of them (e.g. Newtonsoft.Json) into the standard lib. I'm not sure if this is a good thing. I know I'm contradicting the "massive standard lib" pro from above. But here I'm thinking long-term. - New language features are sometimes done half-assed for backwards compatibility. E.g. nullable reference types that are just syntax sugar instead of a proper maybe monad with language integration.
- ocdtrekkie 4y agoI think the absorbing into .NET behavior of their standard library is the standout reason to use .NET: You aren't going to have to shim basic functionality out to some random third party who might or might not abandon the code, and could inject malware or telemetry down the road without telling you. The .NET approach of ensuring you can do nearly everything an app might need basic functionality-wise in the standard library probably sets .NET as one of the most secure platforms to develop with. It's the anti-NPM, and NPM is terrible for security.
- rossnordby 4y agoI can't comment on the ASP/web side of things, but C# matches up with my atypical use cases extremely well. The high points: 1. Fast compile times for most of development. I'm fine with waiting a while to do a special highly optimized deployment, but getting 95-100% of optimal performance with 0-3 second build times is really nice. 2. Controllable memory access through value types. Nothing getting in the way of C-like contiguous buffers and managing cache line or load alignment. 3. GC that gets out of the way. C# has a GC, but in most of my applications the GC never has to run because I rarely allocate GC-managed instances. It's definitely a nonidiomatic use of C#, but the fact that it's pretty still pretty easy to do is nice. And when I don't have to care about the GC's overhead, the presence of the GC just makes everything easier developmentally. 4. Ability to actually make use of the hardware. The compiler's improved massively in the last several years, and the way vectorization is exposed actually feels a lot nicer than my experiences in C++-land. And less relevant to my own needs, but still interesting, nowadays you can directly link a C# library into a C/C++/Rust application just like any C library. Among other things. Almost a decade ago, I was considering exiting the ecosystem in favor of C++/D/not-yet-even-1.0 Rust/etc, but the open source push and a sudden focus on performance basically made the jump unnecessary. C# occupies a really nice sweet spot.
- mohaneds 4y agoYes! I suspect (but I don't know for sure) that C# has the highest performance sealing of all the VM-based languages with a tracing garbage collector. structs, Span<T> and ReadOnlySpan<T> for type-safe access to contiguous regions of memory allow us to do a lot without touching the heap. C# also has hardware intrinsics for non-cross platform SIMD instructions if you're interested in that kind of thing.
- kaba0 4y agoPerhaps it can be manually optimized the best indeed, but the JVM still has a better GC if I’m not mistaken. Value types are indeed very cool, and I really hope they will get implemented sooner on the Java side as well. Just as a note, Java recently got a SIMD API as well.
- JohnDeHope 4y agoI’ve been a C# developer since the beta. I started off mostly WinForms, then moved along to asp.net, then MVC, now Blazor. I don’t have anything specific to say. It’s a perfectly reasonable language, standard library, community, etc. I have never been frustrated by it, and have enjoyed 15+ years of continual improvements. I think knowing what your specific questions are would be helpful.