Re: Language enhancement idea: C# method instance fields

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Actually the other methods suggested, like Restrict to method or Scoping may
improve the usability of the other variations. As it is VERY often that I
want to restrict access to a variable to a set of methods (many times too few
to break out to a seperate class).

So some variation of this allowing you to specify the set of methods the
variable should be allowed to be accessed in would be a great way to clearly
indicate in code, member variable intention which is lacking in many
languages including C#.



"Nicholas Paldino [.NET/C# MVP]" wrote:

I think that you are thinking a little bit too much into it. The
feature would be for 99% of the use cases, where you are going to have that
state be applicable to only that method, nothing else.

It is intended to be very, very specialized. Granted, with the way that
the OP suggests, it leaves an option open to be expanded. I don't think
this is the right way to do this.

First, you can not apply attributes to variables inside of the method
body. To say that now you could do so would introduce a whole new set of
rules and conditions that have to be formulated (what are the conditions and
how does a variable in a method react, what are the changes to the CLR and
the Reflection namespace that have to be made) in order to accomidate this.

This is why the keyword is better (I recommended "static"). It doesn't
allow for expansion (you can pass parameters to an attribute, but the
keyword applies to what it is modifying, without the ability to
"parameterize" it like an attribute), and it is very specific in its
application.

Second, using the "static" keyword keeps feature in line with the same
feature in C++.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx



"kh" <kh@xxxxxxxxxxxxxxxxx> wrote in message
news:D76B5835-BB99-4664-81BD-53E1C7682B50@xxxxxxxxxxxxxxxx
I'm still not convinced, although I recognise the issue you are
describing.
In many ways you are may just be creating a new set of problems with
regards
to the correct decoration of fields with your new attribute. For example,
what if I want one writer but multiple readers for this data? It starts to
get a bit messy, although not totally unmanageable.

Personally if I have state which is highly specialised but still related
to
my class as a whole I would implement as a nested class (for example,
think
Enumerators, which must own and manage the current position of the
enumeration).

Interesting suggestion though. Will be interesting to see how a discussion
on this topic progresses.

kh




.



Relevant Pages

  • Re: Language enhancement idea: C# method instance fields
    ... You forgot that in 99% of the usual cases you just want to restrict *one* ... soon find yourself moving methods and variables around, from one scope block ... This feature will certainly not increase any productivity:) ... This is why the keyword is better. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PHP] Whats wrong the __autoload()?
    ... just because you don't want to invest 20 minutes in getting your ... I actually prefer to use a site prepend and append, then in the prepend file is where I throw all my requires and such. ... Not using language features because some developers might not know about it is going to restrict you to the sort of instruction set you get in Assembler. ... I've been working with PHP for a very long time and I certainly don't claim to know everything about it or about every feature it has. ...
    (php.general)
  • Re: generator expressions: performance anomaly?
    ... you could also restrict what theese prebuilding ... *IS* a useless feature, but I think it's possible to make it work. ...
    (comp.lang.python)
  • Re: Why is the kfree() argument const?
    ... "restrict" is the C99 keyword for such requirement (or better ... The restrict keyword controls aliasing, ... inserting const there would do anything at all. ... that a function taking a const pointer argument will not modify the memory ...
    (Linux-Kernel)
  • Re: SELECT and RESTRICT statements
    ... As long as you stay in the SQL World, ... RESTRICT is part of SQL's data definition language subset. ... keyword is analogous to relational algebra's "project" operation. ... Relational algebra term Relational algebra symbol SQL keyword ...
    (comp.databases.theory)