Syntactical sugar to reduce repetition in using statements #1421
Replies: 10 comments
-
The proposed syntax is almost impossible to read (In my Opinion). And while you might be able to describe the current syntax as "verbose", it is non-ambiguous and is limited to a few lines at the top of every file (and the IDE adds half these via analyzers/code-fixes, so it's not a lot of typing required either). |
Beta Was this translation helpful? Give feedback.
-
The above example was intentionally minimal and the styling may not be appropriate. Another example and formatting:
Could be expressed as:
Which is much more concise than the above. |
Beta Was this translation helpful? Give feedback.
-
I like the idea (and will be very familiar to Javascript devs) but I do think it's a bit harder to read. Maybe if we disallow nesting? using System.{this, Diagnostics, IO, Reflection, Text, Xml};
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.{this, Controls, Input, Media}; |
Beta Was this translation helpful? Give feedback.
-
In this space I'd rather we invest on local using directives that actually enable things (#218), e.g. if you have ambiguous extension methods, you can import the desired one in the closer scope. This on the other hand, makes things less approachable. as @tannergooding mentioned, you don't usually type usings by hand. Also, the simple flat structure is the most copy/paste-friendly syntax, if you need to. |
Beta Was this translation helpful? Give feedback.
-
To draw a phrase from the python community "There should be one-- and preferably only one --obvious way to do it." |
Beta Was this translation helpful? Give feedback.
-
Another possible syntax inspired by Linq.
|
Beta Was this translation helpful? Give feedback.
-
How Scala-esque. But in Scala the set syntax only works on individual types, not packages. It's only really useful when you want to import a couple of different classes without having to import the entire namespace via wildcard. Scala syntax doesn't work on multiple packages that way, and wildcard imports put you into the exact same situation that you have in C#. If such a syntax were to be considered for C# I think I'd prefer breaking out the parent namespace, though. I don't like the look of using System;
using System.{Diagnostics, IO, Reflection, Text, Xml};
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.{Controls, Input, Media}; But then how might aliases work? Or |
Beta Was this translation helpful? Give feedback.
-
JSON rulez :) |
Beta Was this translation helpful? Give feedback.
-
Who writes usings block manually? |
Beta Was this translation helpful? Give feedback.
-
This is honestly where I've been with using directives for years. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Current implementation leads to blocks that are similar to the following:
It would reduce repetition in these types of statement groupings if a syntax similar to the following was possible:
Beta Was this translation helpful? Give feedback.
All reactions