Replies: 11 comments
-
I think this makes code easier to write, but harder to read, which is not a good trade-off most of the time.
If you don't like how VS behaves, that's a reason to change how VS behaves, not change the whole language. Also, using the |
Beta Was this translation helpful? Give feedback.
-
A case for code generator? Something like:
|
Beta Was this translation helpful? Give feedback.
-
@svick As far as VS, that's a fair point, but it was an added motivation for the proposal for me. Even with one attribute it gets quite annoying, but that's an issue for another repo. As far as readability, that can be arguable. I find the separation much easier to read in my example. The presence of indentation could clearly show there's a code block going on even if the number of declarations is greater than the height of the screen. Now long attributes can cover variable names which makes the whole space cluttered when looking through our own code. There is a situation when a certain attribute is used quite often, and that just becomes visual clutter. @eyalsk Still lots of copy-pasting going on :) It's code duplication! |
Beta Was this translation helpful? Give feedback.
-
Yes, it isn't terse as your example but it's probably more readable. ;) p.s. I'd argue that code duplication as in text isn't bad (and we're doing it all the time), it's duplication of knowledge that is bad. |
Beta Was this translation helpful? Give feedback.
-
That would be a compiler error if |
Beta Was this translation helpful? Give feedback.
-
@Joe4evr Why would it be a compile-time error? they are derived from |
Beta Was this translation helpful? Give feedback.
-
Well yeah, that's the key thing, but I'm pretty sure a good majority of well-used attributes are restricted. Also, it just feels plain dirty to create an attribute class that isn't decorated with |
Beta Was this translation helpful? Give feedback.
-
@Joe4evr Do you realize this is an example? I really don't get what's the point of this.. you went from saying it won't compile to I don't like the code.. |
Beta Was this translation helpful? Give feedback.
-
"C++ access modifier blocks" ranks high on my list of things that I despise whenever I have to read C++ code. I like having the visibility information right there on the method definition where I don't have to go hunting for it. This syntax would open the door to that - for that alone, it gets a thumbs-down from me. |
Beta Was this translation helpful? Give feedback.
-
@atsushikan I can imagine it being pretty bad with methods, I thought only of fields / properties. |
Beta Was this translation helpful? Give feedback.
-
Inversely [Atr1]
[Atr2]
[CopyAttributesTo(nameof(myVar2),nameof(myVar3),nameof(myVar4))]
[Attr3] // not copied
public MyType1 myVar1 { get; private set; }
public MyType2 myVar2 { get; private set; }
public MyType3 myVar3 { get; private set; }
public MyType4 myVar4 { get; private set; } |
Beta Was this translation helpful? Give feedback.
-
Motivation
Currently attributes and access modifiers have to be specified for all members individually. This can lead to ugly and overly verbose declarations. Further, in VS attributes will be auto-corrected to be on a different line to a declaration, which makes it difficult to have attributes inline.
Solution
Allow blocks, somewhat similar to C++ access modifier blocks, with syntax like follows.
They have the following features:
:{
}
or}:
. The first means no suffixes and second means there is a suffix following, like accessors or default values.Beta Was this translation helpful? Give feedback.
All reactions