Click here to Skip to main content
15,922,533 members
Home / Discussions / C#
   

C#

 
GeneralRe: Identify caller of a function Pin
User 665827-Nov-05 6:01
User 665827-Nov-05 6:01 
QuestionUnable to see underlined shorcuts in main menu Pin
TheBlindWatchmaker26-Nov-05 7:38
TheBlindWatchmaker26-Nov-05 7:38 
AnswerRe: Unable to see underlined shorcuts in main menu Pin
Dave Kreskowiak26-Nov-05 8:19
mveDave Kreskowiak26-Nov-05 8:19 
GeneralRe: Unable to see underlined shorcuts in main menu Pin
TheBlindWatchmaker26-Nov-05 8:32
TheBlindWatchmaker26-Nov-05 8:32 
Questionproperties vs public fields Pin
hypermegachi26-Nov-05 7:04
hypermegachi26-Nov-05 7:04 
AnswerRe: properties vs public fields Pin
Colin Angus Mackay26-Nov-05 7:23
Colin Angus Mackay26-Nov-05 7:23 
GeneralRe: properties vs public fields Pin
hypermegachi26-Nov-05 12:13
hypermegachi26-Nov-05 12:13 
GeneralRe: properties vs public fields Pin
Colin Angus Mackay26-Nov-05 13:53
Colin Angus Mackay26-Nov-05 13:53 
hypermegachi wrote:
but if you know with 90% confidence that you won't need to do any checks or extra operations, why not just make them public fields as default?


Two reasons.

1. That last ten percent.

2. Because you screw the encapsulation of the object. You are allowing external entities know about the internals of the object. If at some future date you need to change that, you have a hell of a lot of code to fix that expects the internals of your object to look a certain way. Never ever underestimate the amount of work it will take to fix a problem like that. All it takes is 30 seconds (less if you are using VS2005 because it can automatically encapuslate fields for you if you want) work, that can save days or even weeks worth of work down the line. (If the project is large enough it might event save months of work)


hypermegachi wrote:
with the 10% of the time, if you need the extra operations, you can convert the fields into properties, without needing to change libraries that use it, since the syntax would be the exact same


Not if you follow the guidelines they won't. Properties are always Pascal cased. That means that each word in the property name starts with a capital letter. Fields should be camel cased, which means that the first word is lower cased, each subsequent word is upper cased. So they won't have the same names. Also, some development shops have their own standards like prefixing fields with an underscore, or "m_" (harking back to MFC standards) and so on.

The bottom line is that if you want to be employable you must write code that is easy to understand and maintain. Maintenance costs can skyrocket on a badly written project. Making fields public, innocent as it might sound, is a step that will quickly make a project a maintenance nightmare. I certainly wouldn't want to have to clean up the mess, and neither would you - it is an almost soul destroying part of software development.




My: Blog | Photos

"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious


GeneralRe: properties vs public fields Pin
hypermegachi27-Nov-05 6:43
hypermegachi27-Nov-05 6:43 
GeneralRe: properties vs public fields Pin
Colin Angus Mackay27-Nov-05 13:24
Colin Angus Mackay27-Nov-05 13:24 
GeneralRe: properties vs public fields Pin
hypermegachi27-Nov-05 16:53
hypermegachi27-Nov-05 16:53 
GeneralRe: properties vs public fields Pin
Colin Angus Mackay27-Nov-05 20:26
Colin Angus Mackay27-Nov-05 20:26 
GeneralRe: properties vs public fields Pin
hypermegachi28-Nov-05 3:58
hypermegachi28-Nov-05 3:58 
QuestionUrgent:Marshalling BSTR* Pin
rana7426-Nov-05 6:23
rana7426-Nov-05 6:23 
QuestionISR in C# Pin
mostafa.hk26-Nov-05 5:21
mostafa.hk26-Nov-05 5:21 
AnswerRe: ISR in C# Pin
Stanciu Vlad26-Nov-05 5:39
Stanciu Vlad26-Nov-05 5:39 
Questionregex Pin
Sam 200626-Nov-05 5:12
Sam 200626-Nov-05 5:12 
AnswerRe: regex Pin
Guffa26-Nov-05 8:50
Guffa26-Nov-05 8:50 
AnswerRe: regex Pin
Curtis Schlak.26-Nov-05 10:30
Curtis Schlak.26-Nov-05 10:30 
QuestionControl apperance in VS 2005 Pin
ON7AMI26-Nov-05 4:17
ON7AMI26-Nov-05 4:17 
AnswerRe: Control apperance in VS 2005 Pin
Sam 200626-Nov-05 5:17
Sam 200626-Nov-05 5:17 
GeneralRe: Control apperance in VS 2005 Pin
ON7AMI27-Nov-05 7:22
ON7AMI27-Nov-05 7:22 
Questioninserting images in word document from c#? Pin
Hiral Patel26-Nov-05 2:52
Hiral Patel26-Nov-05 2:52 
QuestionHow do I know that how many users are online? Pin
asifhameed126-Nov-05 1:31
asifhameed126-Nov-05 1:31 
AnswerRe: How do I know that how many users are online? Pin
MoustafaS26-Nov-05 1:51
MoustafaS26-Nov-05 1:51 

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.