4 ms·
What is an example of a really good codebase written in modern C#? There are quite a few appealing things about the language, but I'm having trouble shaking th
by jeffdavis 6y ago
What is an example of a really good codebase written in modern C#?
There are quite a few appealing things about the language, but I'm having trouble shaking the feeling that it's kind of like Java. I know both languages have evolved a lot, but some codebases might get stuck in some old patterns.
- _-david-_ 6y agoMy understanding is that the dotnet runtime and powershell are both decent codebases. https://github.com/dotnet/runtime https://github.com/dotnet/runtime https://github.com/PowerShell/PowerShell https://github.com/PowerShell/PowerShell
- jeffdavis 6y agoLooking at a random file in Powershell, the first thing I see is: private string _typeName; /// <summary> /// Add new type name to the specified object for TypeNameSet. /// </summary> [Parameter(Mandatory = true, ParameterSetName = "TypeNameSet")] [Parameter(ParameterSetName = "MemberSet")] [Parameter(ParameterSetName = NotePropertySingleMemberSet)] [Parameter(ParameterSetName = NotePropertyMultiMemberSet)] [ValidateNotNullOrEmpty] public string TypeName { set { _typeName = value; } get { return _typeName; } } -- https://github.com/PowerShell/PowerShell/blob/15c2245af9748659643626db863540aed4d4f72e/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs#L93 https://github.com/PowerShell/PowerShell/blob/15c2245af97486... Honestly it seems like just a lot of code and very little meaning. I can't help but think that there's a better way of expressing the solution. I could have picked the wrong file, but I was poking around in lots of directories before I found any significant C# code at all. It seems like there's a whole 'nother level of boilerplate in the directory structure.
- LandR 6y agoMost C# is boilerplate code!
- joshschreuder 6y agoLooking at object getter/setters in any OOP is likely to be pretty uninspiring :) There's no logic there, this is basically just boilerplate for some other code to set properties on an object. Something that actually has some business logic will be much more interesting to read, eg. https://github.com/PowerShell/PowerShell/blob/15c2245af9748659643626db863540aed4d4f72e/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs https://github.com/PowerShell/PowerShell/blob/15c2245af97486...
- jeffdavis 6y agoYeah, clearly there's some code somewhere that does something. I just don't understand why there are so many files and so much code that does nothing and means nothing. I'm fine with verbosity. I'm fine with lots of data type declarations, annotations, things that make the compiler happy, etc. But a file full of getters and setters? I can put up with it, but I don't understand why.
- contextfree 6y agosince c# 3 (2008) this would normally be expressed as public string TypeName { get; set; } not sure why it's not here, could just be older code. The [Parameter] etc stuff is all powershell-specific metadata that defines how to use it from the powershell language.
- jeffdavis 6y agoThank you. That's why I asked for modern c#. It would be nice to see if some other codebases managed to free themselves from some of this cruft and make something more approachable.
- oaiey 6y agoPowershell is itself a language, a kind of ide (consider completion/help/etc). It is not a representive code base. The .NET runtime either. Its pure scale is beyond beauty.
- jmarolf 6y agoI would point to https://github.com/dotnet/roslyn https://github.com/dotnet/roslyn itself as an example of a modern codebase. We try to adopt and use all of the new language features there as we write them to try and determine if the ergonomics are good.