Re: Using underscores in type names

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



Accutrol wrote:
_mytype="empty" in Visual Studio.NET 2005 produced many errors.

camelCase, huh? Well, I used underscores because I present the
names of the test functions (which are synonymous with the class
names) to the user in a test sequence editor. I just instantiate an
object of the type selected by the user.

There's nothing wrong with the underscores per se. It's just that since VB.NET auto-generates class members using the same "set_..." template you used for your type name, _and_ because VB.NET is case-insensitive, you get the collision, _and_ because you happen to have a type name that looks like the setter method name for another type name you've declared.

It really is a very unusual and unlikely coincidence, as Armin pointed out.

And for what it's worth, if you don't like a language auto-generating names in your code that might collide with the names you've chosen, you should probably not be using VB.NET. Fundamental to the way it works in providing implicit access to certain kinds of objects (e.g. default instances of your Form subclasses) is to create the potential for these kinds of collisions, however rare they may be.

There are a number of other languages suitable for use with .NET. Of course, each of those may have features that also may cause confusion or frustration. That's just part of learning new languages.

I have heard of style guides for naming conventions, but I did not
realize that these had the same force as speed limit signs.

They don't. Certainly, had you avoided the use of underscores in your type names, you wouldn't have seen this problem. But it really is just an unusual conjunction of a variety of factors that caused this. The underscores per se aren't really the problem.

I thought it was just for ease of following one another's coding
conventions. I have never heard of restrictions on choosing
names for classes, objects, variables, methods, properties,
enumerations, structures, etc., other than stay away from
reserved words. I was not aware that name collisions could
occur based on appending stuff to a name.

In VB.NET, because it is auto-generating class members for you, based on types you've declared yourself, you have additional potential for name collisions. Again, this isn't about coding conventions per se. In fact, in some sense this is just a variation on the rule "stay away from reserved words". That is, the setter method is always called "set_<typename>" so you should not be making any types or other potentially colliding names that follow the same pattern.

Lacking any other input, I will build a map of My_Name to
className and rename all of my test function classes to
className convention. Then I can perform a lookup from
My_Name and return className and then use Reflection
on className.

Note that if you follow the convention suggestion your new class name will be "ClassName", not "className". In the .NET convention, camel-case (the latter) is used for variables and arguments, while Pascal-case (the former) is used for type names, method names, and property names.

Pete
.



Relevant Pages

  • Re: Using underscores in type names
    ... names of the test functions (which are synonymous with the class ... I have heard of style guides for naming conventions, ... className and rename all of my test function classes to ... It may not help with your existing code, but using underscores as a type ...
    (microsoft.public.dotnet.framework)
  • Re: Using underscores in type names
    ... names of the test functions (which are synonymous with the class ... you'd still be able to do that without the underscores. ... className and rename all of my test function classes to ... using camelCase for private/internal names and PascalCase for ...
    (microsoft.public.dotnet.framework)
  • Re: How to call module functions inside class instance functions?
    ... it is some sort of naming convention for me. ... The two underscores are exactly the cause of your problem: ... the error message, the compiled has inserted the CLASS name (not MODULE ...
    (comp.lang.python)
  • Re: Naming convention
    ... When i said namming conventions i?m talking about how name the ... Variable names must begin w/ an alphabetic character and include only alphanumeric characters and/or underscores. ... About the only convention I recall TMW mention of is the one for all capital letters for global variables. ...
    (comp.soft-sys.matlab)
  • Re: Variable naming conventions.
    ... char *first_name; ... It's underscores against camel case. ... of that preference. ... predominating convention in most modern programming languages is mixed ...
    (comp.lang.c)