![]() ![]() It seems like a stupid little thing but I'm very jazzed about it. Outdenting (it's a word!) the bulk of your code also makes life easier when you copy code listings into documentation, book manuscripts, slide decks, etc. And the real signals (indents for methods, ifs,loops, try-catch) are less pronounced as a result- Steve "ardalis" Smith October 7, 2021 ![]() If the entire file (essentially) is always the same, there's no signal there - it's just noise. I like indentation for programming logic and scoping, but it needs to provide a signal. If the entire code section of the file is all indented the same amount because of a namespace, it's only adding noise, not signal. But they're only useful if there's variation. Think of how many whitespace characters could be saved!Īlso, it's worth noting that indentation and whitespace are useful signals in your codebase. But every other file could just use a one-line namespace statement and outdent the entire contents of the file (minus using statements above the namespace of course) by one indent level. Those files would continue to use the current syntax that we've had since C# 1.0. Sure, it wouldn't work for a handful of files that do use multiple namespaces in the file. What if you could just declare the namespace on a single line, and that namespace would affect the rest of the file from that point onward? Which means that the vast majority of the lines of code in that file was indented, typically by 2 or 4 characters, for the entire file (minus some using statements). NET Rocks that over 99% of all C# files on GitHub have just one namespace. The lead designer of the C# language team at Microsoft, Mads Torgersen, recently commented on. NET developer and you're not yet familiar with file-scoped namespaces, I'm sure you'll probably encounter them in the very near future. I do share a few extra tips in the video toward the end: File Scoped Namespaces in C# 10 I recently recorded a short video demonstrating how to use the new dotnet format tool on a real project, including how to apply one of my favorite C# 10 features, file scoped namespaces, throughout a codebase. editorconfig file, and can ensure things like spacing, indentation, and whether certain characters appear on their own line are applied consistently throughout your codebase. It's used to format your codebase using rules specified in an. If you don't know the dotnet format tool, it's available as a separate install in previous versions of. NET 6, and you can use it to easily adopt the new file scoped namespace feature that ships with C# 10. The dotnet format tool is now a part of the dotnet CLI with. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |