C
C# Learner
A recent discussion in here has got me reflecting on the "private"
keyword. As I mentioned in the discussion, I find the keyword
problematic, in that it looks too similar to "public" and therefore
makes quickly scanning for public members among private ones, hard.
This kind of thing wasn't so important in a language like C++ or Delphi,
where class member declarations were separate. However, since C#
members aren't declared ahead - but defined in place - I feel this is an
issue in this language.
Consider the following code:
class Test
{
public void Foo()
{
Blah();
}
private int Blah()
{
Bleh();
return 0;
}
private SomeType Bleh()
{
Foobar();
return new SomeType();
}
public string Blow()
{
Fewbar();
return String.Empty;
}
private void Fewbar()
{
F00Bar();
}
private bool F00Bar()
{
Bl4h();
return true;
}
}
In the above, can you, while quickly scanning, indicate which methods
are public?
I know I can't. I'd imagine others would agree.
"private" is too similar to "public".
It could be renamed to, for example, "concealed".
Here's the above code edited to use "concealed" instead of "private".
class Test
{
public void Foo()
{
Blah();
}
concealed int Blah()
{
Bleh();
return 0;
}
concealed SomeType Bleh()
{
Foobar();
return new SomeType();
}
public string Blow()
{
Fewbar();
return String.Empty;
}
concealed void Fewbar()
{
F00Bar();
}
concealed bool F00Bar()
{
Bl4h();
return true;
}
}
In my opinion, it is an order of magnitude easier to tell which are the
public methods in the above.
Whadda ya think?
keyword. As I mentioned in the discussion, I find the keyword
problematic, in that it looks too similar to "public" and therefore
makes quickly scanning for public members among private ones, hard.
This kind of thing wasn't so important in a language like C++ or Delphi,
where class member declarations were separate. However, since C#
members aren't declared ahead - but defined in place - I feel this is an
issue in this language.
Consider the following code:
class Test
{
public void Foo()
{
Blah();
}
private int Blah()
{
Bleh();
return 0;
}
private SomeType Bleh()
{
Foobar();
return new SomeType();
}
public string Blow()
{
Fewbar();
return String.Empty;
}
private void Fewbar()
{
F00Bar();
}
private bool F00Bar()
{
Bl4h();
return true;
}
}
In the above, can you, while quickly scanning, indicate which methods
are public?
I know I can't. I'd imagine others would agree.
"private" is too similar to "public".
It could be renamed to, for example, "concealed".
Here's the above code edited to use "concealed" instead of "private".
class Test
{
public void Foo()
{
Blah();
}
concealed int Blah()
{
Bleh();
return 0;
}
concealed SomeType Bleh()
{
Foobar();
return new SomeType();
}
public string Blow()
{
Fewbar();
return String.Empty;
}
concealed void Fewbar()
{
F00Bar();
}
concealed bool F00Bar()
{
Bl4h();
return true;
}
}
In my opinion, it is an order of magnitude easier to tell which are the
public methods in the above.
Whadda ya think?