473,378 Members | 1,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Compiler Error Request.

I have a request for the c# compiler one that is an obvious oversight in
my opinion. I'm not sure if this is already being implemented in
Whidebey, bu i would hope to find it in there, or in the next version.

Working with properties, and the neaming convention that Microsoft has
recommended for developing in C#, it is easy for one to have a circular
reference. This reference could easily be prevented by a Compiler error,
but as of 1.1 frameworks, it does not.

take the following code for example:

public class Foo
{
private int bar;

public int Bar
{
get{ return this.Bar; } // <-- this should be a
// compiler error.
}
}

This problem is further exaserbated by the fact that the VS.NET IDE's
Intellisense often chooses the Public version of a member before a
private as you are typing.

Another situation arises in which you are trying to access a private
member withing a class while using a property or method and end up using
a public Property. This is a problem because when you meant to access
the private member field, you access the Public Property method and
incur a performance penalty. Teh compiler should thorw warnings if it
detects such behavior.

Take this code for example:

public class Foo
{
private int bar;

public int Bar
{
get{ return this.bar; }
}

public int FooBar(int param)
{
// The following line should throw a warning.
return (this.Bar + param);
}
}
These are common mistakes i see happen in a development team using C#.
They are such subtle mistakes. Ones that a Compiler could pick up
easily. While i really enjoy proramming in this language, and developing
with it. i fear that this is one of the kinds of issues that come up
that makes C# often criticized for not being a language that is useable
in large development projects and teams.

I often feel this is not true, because I feel with some best practices
C# can be a great productivity enhancer. That is from experience in
developing large applicaitions in a team. But these subtle littpe
problems point to otherwise. Please fix this.

Sean
Nov 15 '05 #1
5 1299
On request 1, I agree, it would be nice if the compiler could determine
recursive calls like this. On the other hand, you will find this error
immediately the first time you access this property and you get a
stackoverflowexception.

As for #2, I disagree. Often you do want to use the property and not the
underlying variable. Perhaps you are doing something in the property that
is more then just retreiving a private member, and your function code would
want to use the property to have that code execute. But then there are
times when you want the raw variable data.

There is no way for the compiler to tell which situation it is, and it is
your job as the developer to make sure you are accessing the correct one.
You can make this easier, by not differing the property and the private
member by case only - but actually make them more different then that, so
you are always consciously picking the correct one.

You can't have the compiler do everything for you. It's not unreasonable to
expect people to be aware of these things - and this is no way reflects on
how useful the language is. If these small issues make the language
unusable for your team for large projects, then I think there is a bigger
problem at hand.

But in either case, after you make this mistake once or twice, you will just
become aware of it, and you won't need the compiler to catch it.

"Sean Wolfe" <no*****@please.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
I have a request for the c# compiler one that is an obvious oversight in
my opinion. I'm not sure if this is already being implemented in
Whidebey, bu i would hope to find it in there, or in the next version.

Working with properties, and the neaming convention that Microsoft has
recommended for developing in C#, it is easy for one to have a circular
reference. This reference could easily be prevented by a Compiler error,
but as of 1.1 frameworks, it does not.

take the following code for example:

public class Foo
{
private int bar;

public int Bar
{
get{ return this.Bar; } // <-- this should be a
// compiler error.
}
}

This problem is further exaserbated by the fact that the VS.NET IDE's
Intellisense often chooses the Public version of a member before a
private as you are typing.

Another situation arises in which you are trying to access a private
member withing a class while using a property or method and end up using
a public Property. This is a problem because when you meant to access
the private member field, you access the Public Property method and
incur a performance penalty. Teh compiler should thorw warnings if it
detects such behavior.

Take this code for example:

public class Foo
{
private int bar;

public int Bar
{
get{ return this.bar; }
}

public int FooBar(int param)
{
// The following line should throw a warning.
return (this.Bar + param);
}
}
These are common mistakes i see happen in a development team using C#.
They are such subtle mistakes. Ones that a Compiler could pick up
easily. While i really enjoy proramming in this language, and developing
with it. i fear that this is one of the kinds of issues that come up
that makes C# often criticized for not being a language that is useable
in large development projects and teams.

I often feel this is not true, because I feel with some best practices
C# can be a great productivity enhancer. That is from experience in
developing large applicaitions in a team. But these subtle littpe
problems point to otherwise. Please fix this.

Sean

Nov 15 '05 #2
Sean Wolfe <no*****@please.com> wrote:

I agree with your first suggestion but not with your second...
Take this code for example:

public class Foo
{
private int bar;

public int Bar
{
get{ return this.bar; }
}

public int FooBar(int param)
{
// The following line should throw a warning.
return (this.Bar + param);
}
}


What if Bar was implemented like this:

public int Bar
{
get { return someFlagIsSet ? bar : 0; }
}
Nov 15 '05 #3
C# Learner wrote:
Sean Wolfe <no*****@please.com> wrote:

I agree with your first suggestion but not with your second...

Take this code for example:

public class Foo
{
private int bar;

public int Bar
{
get{ return this.bar; }
}

public int FooBar(int param)
{
// The following line should throw a warning.
return (this.Bar + param);
}
}

What if Bar was implemented like this:

public int Bar
{
get { return someFlagIsSet ? bar : 0; }
}


I guess I do agree with you guys on the Second issue that this can
clearly be a best practices issue. But the first one is just an
oversight by the compiler. Whether or not it gets caught the first time
that it's run, or get a stack overflow, the call clearly shouldn't
compile. Compilers these days are smart enough to know such things.
Also having Intellisense choosing the Public item first doesn't help.

Sean
Nov 15 '05 #4

Hi Sean,

Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.

Based on my understanding, you have tabled 2 proposals for C# compiler
error checking.
===============================================
For your #2, I agree with what Marina said, the compiler gives you the
flexibility to use Property validation, etc, so I think it is by the design
goal.

For your #1, I think C# is a case-sensitive language, and the case type
error is a use error in your code, so I think you should be careful of this
issue in your programming work.

But I also know your concern, you feel that C# compiler should be more
convinient for the developers and reduce more fallible possibility. I think
your concern also makes sense, so I suggest you provide your suggestion and
concern to Microsoft at:
http://register.microsoft.com/mswish/suggestion.asp
you also can email to: ms****@microsoft.com

==============================================
Thank you for your patience and cooperation. If you have any further
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5

Hi Sean,

Does my reply makes sense to you?
Do you still have concern? Please feel free to feedback to me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Fisher | last post by:
I'm seeing an error when I try to run/debug a web service. Although it doesn't happen every time, it does occur more than half of the times I hit F5. It appears to be returned by the the JIT...
8
by: jon morgan | last post by:
OK, I'm going to be brave. There is a bug in VS.Net 1.1 that causes random compiler errors. I have raised this issue in posts at least three time in the past couple of months without attracting...
1
by: JTrigger | last post by:
When I compile my project using the IDE on a development machine it works just fine. When I compile it on the server using csc.exe, I get the following error when I try to bring it up in the web...
3
by: Robert | last post by:
Every time I navigate to any .aspx file on my computer, I get the error below. According to MSDN this indicates that my CLR is corrupt, but I've re-installed the .NET framework with no help. Also...
3
by: Hamilton | last post by:
Hi there, I've seen this error appear a few times in newsgroups but unfortunately I haven't found one that actually provides a solution. I'm basically deploying a new website into an area at a...
2
by: mudge | last post by:
Hi, I'm getting some very strange problems with some C# code. We're running an ASP.NET application on a local server in a DMZ. If I access it using the internal address, the application works...
7
by: Mark Carrington | last post by:
I'm developing a web app in .NET 2 using C#, and occasionally see this error, apparently something to do with the theme used on the site: Compiler Error Message: The compiler failed with error...
0
by: Ken | last post by:
Anyone know how to fix this error? Server Error in '/' Application. -------------------------------------------------------------------------------- Failed to load JIT compiler Description:...
3
by: dancer | last post by:
I am using Framework 1.1.4322. Who can tell me why I'm getting this error? My code follows Compilation Error Description: An error occurred during the compilation of a resource required to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.