Click here to Skip to main content
15,898,222 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
PIEBALDconsult23-Nov-08 5:57
mvePIEBALDconsult23-Nov-08 5:57 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Paul Conrad23-Nov-08 6:45
professionalPaul Conrad23-Nov-08 6:45 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
WilliamSauron23-Nov-08 7:22
WilliamSauron23-Nov-08 7:22 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Paul Conrad23-Nov-08 7:26
professionalPaul Conrad23-Nov-08 7:26 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
WilliamSauron23-Nov-08 7:34
WilliamSauron23-Nov-08 7:34 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Paul Conrad23-Nov-08 7:38
professionalPaul Conrad23-Nov-08 7:38 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
PIEBALDconsult24-Nov-08 5:41
mvePIEBALDconsult24-Nov-08 5:41 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
WilliamSauron24-Nov-08 10:43
WilliamSauron24-Nov-08 10:43 
Ok, it's time for a little nitpicking then Smile | :) (or, as we say in French, cutting hairs in four). Beware, I've 44 years of experience at that game Smile | :) It means that everything I say here has absolutely no importance at all, and is by no way an attack on anyone. It's just saying something for the pleasure of saying something.

The ".ctor" is not a C# name, it is a CLR/MSIL/whatever name. When I write a constructor for my C# class, I dont type ".ctor", I type the name of my class as the name of the method. Now, whether the compiler has an urgent need to create MSIL code named ".ctor" or "Groborozgruduruk" is totally irrelevant. When I program in C#, and also when I read C# code written by anyone else, I know that if a method is declared that has the same name as the class, it is a constructor. In Delphi, type casts use the same syntax as a function call, so having a function and a type with the same name is not a good idea there neither. Other languages may still have other good reasons to abhor that. This is a good reason why I agree with the compiler when it insists that I don't call my method the same name as the class.

This brings the second question: as the compiler internally creates a method named "Item" as the implementation of the default indexer, does it really impose an unbearable burden on the creativity of programmers? Of course, it means that you cannot have a class named "Item" that has an indexer. But wait! Do you really think a good design would involve a class named very generically "Item" that has a default indexer (and so is itself composed of a collection of something else.) What are these called then? "SubItem" maybe? What if SubItem has itself an indexer? "SubSubItem"? "YetAnoterSubItem"? If you don't give meaningful names to your classes and methods, you are of course welcome to do so, but please don't say the compiler is restricting your creativity Smile | :)

On the other hand, now we know where the coding horror is Smile | :)

-- Quidquid latine dictum sit, altum sonatur.
http://streambolics.flimbase.com

S. L.

GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
PIEBALDconsult24-Nov-08 15:12
mvePIEBALDconsult24-Nov-08 15:12 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
WilliamSauron24-Nov-08 21:27
WilliamSauron24-Nov-08 21:27 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
PIEBALDconsult25-Nov-08 3:20
mvePIEBALDconsult25-Nov-08 3:20 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
WilliamSauron25-Nov-08 4:05
WilliamSauron25-Nov-08 4:05 
GeneralRe: 'Item': member names cannot be the same as their enclosing type [modified] Pin
PIEBALDconsult25-Nov-08 7:51
mvePIEBALDconsult25-Nov-08 7:51 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
leppie26-Nov-08 2:12
leppie26-Nov-08 2:12 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
WilliamSauron26-Nov-08 9:08
WilliamSauron26-Nov-08 9:08 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
leppie26-Nov-08 9:15
leppie26-Nov-08 9:15 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
WilliamSauron26-Nov-08 9:20
WilliamSauron26-Nov-08 9:20 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Redwan Albougha26-Nov-08 8:16
Redwan Albougha26-Nov-08 8:16 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
leppie26-Nov-08 2:10
leppie26-Nov-08 2:10 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Redwan Albougha26-Nov-08 8:21
Redwan Albougha26-Nov-08 8:21 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Camilo Sanchez26-Nov-08 17:55
Camilo Sanchez26-Nov-08 17:55 
GeneralRe: 'Item': member names cannot be the same as their enclosing type Pin
Redwan Albougha27-Nov-08 2:04
Redwan Albougha27-Nov-08 2:04 
GeneralC++ Gem Pin
Tom Delany11-Nov-08 11:53
Tom Delany11-Nov-08 11:53 
GeneralRe: C++ Gem Pin
Rob Grainger11-Nov-08 22:33
Rob Grainger11-Nov-08 22:33 
GeneralRe: C++ Gem Pin
PIEBALDconsult12-Nov-08 5:05
mvePIEBALDconsult12-Nov-08 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.