In a recent VB.NET project, I adopted the naming conventions that I use for use in C #. Namely, often calling a variable the same name as the class it refers to, only with a different case, for example.
Foo foo = new Foo(); // C
I find that this is often the best way to write code, especially for small methods. This coding style obviously works fine in C #, being case sensitive, and due to the syntax highlighting provided by Visual Studio, it is very easy to see that the class name and variable name are different.
However, to my surprise, this also worked fine in almost 100% of cases * in VB.NET. The only problem was that instead the variable name received several identifiers. Namely, it can be used to call instance methods and general (static) methods of the Foo class. It really didn't cause any problems, but it meant that Intellisense would provide a list containing both static and instance methods after you click ".". after the variable name.
Again, to my surprise, I discovered that this did not actually lead to any confusion in my project, and it was very successful! However, I was the only person who worked on this particular project.
Here is a slightly longer example:
Dim collection as Collection = New Collection() For Each bar As Bar in Bar.All() collection.SomeInstanceMethod(bar) Next collection.SomeSharedMethod()
* The only problem I encountered was that sometimes the rename refactoring tool got confused, i.e. if you rename a class, he would have renamed the variables with the same name as the class, in their Declaration line ( Dim foo As... ), but no other references to this variable, causing the compiler issues (duh). They are always easy to fix.
Another minor annoyance is that the VB.NET syntax syntax does not allocate class names other than variable names, which makes it not entirely pleasant, as when using it in C #. I still found the code very readable, though.
Has anyone else tried to resolve this in a command environment? Are there other possible problems with this naming convention in VB.NET?