Denaes Posted March 10, 2004 Posted March 10, 2004 Ok, I learned from a teacher who's been programming since he was punching holes in cards at 16 years of age. What was I taught? Begian is it? three letter abbrebiation followed by a description in uppercase: txtName, cboList, etc Now I'm reading this awesomely written book on OOP in vb.net by O'Reilly. Anyways, it says the microsoft standard is Pascal and Camel Pascel: CustomerName Camel: customerName Pacal is upper cases all across for the first letter. Camel is lowercase for the first letter, then uppercases. The author gives good reasons why you'd want to use real names, one being passing arguments. You want to be told to enter strName as string, or Name as string. He also says that the old way isn't needed anymore and is ugly and redundant. This is a real general question (as opposed to a Random Thought) that would apply to programmers today. Even before reading the book I was feeling it. There were places it just looked stupid or out of place to have a 3 char prefix, especially were classes were concerned. To tell the truth, I still feel more comfortable using a prefix on component names. When you have a form with 30+ controls mixed between labels, textboxes, buttons and comboboxes/listboxes (a common for data entry), it just does help to have the textboxes all lumped together on the intellisense, and to know that its the textbox and not the label (if you name them that is) or button. Anyone else have opinions, thoughts, theories, etc? Quote
Administrators PlausiblyDamp Posted March 11, 2004 Administrators Posted March 11, 2004 Personally I've always hated prefixing variable names with the variable type (strName, iID, lValue etc). This type of naming can cause more trouble than anything - a fairly frequent occurence is the variable type changes but nobody has the urge to go and rename every instance of the variable in case they screw something else up, the number of times I've seen variables (especially in VB6) like iID which is a long (not an integer), the name is misleading. If the variable is declared so far from the point of usage that you don't know what it does then perhaps a better name / code structure may be in order, plus intellisense and a decent IDE make a lot of the reasons redundant anyway. As to using camel case etc at first I found it a bit of a pain switching to it but now I tend to do it second nature and it makes sense, I can tell a Method from a Parameter from a local variable from a class variable at a glance - plus if you are creating a re-usable library then it makes sense to follow Microsoft's guidelines. However I do find it useful to use a prefix for controls, I guess some old habits die hard..... If you are serious about this kind of thing then you may find FxCop a useful tool. also for another (humerous) opinion on hungarian style names have a look here point 29 especially. :D Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
DR00ME Posted March 11, 2004 Posted March 11, 2004 (edited) : Use constant names like LancelotsFavouriteColour instead of blue and assign it hex value of $0204FB. The color looks identical to pure blue on the screen, and a maintenance programmer would have to work out 0204FB (or use some graphic tool) to know what it looks like. Only someone intimately familiar with Monty Python and the Holy Grail would know that Lancelot's favorite color was blue. If a maintenance programmer can't quote entire Monty Python movies from memory, he or she has no business being a programmer. :D personally I use a lot of camelStyle... and three letter prefixes like txtName lblInfoText etc....but like plasibly stated using a type- prefix in the variable names is ridiculous... e.g. devicesCount looks much better than intDevices... since there cant be half devices...there should 'bling' something in the brains... Edited March 11, 2004 by DR00ME Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Heiko Posted March 11, 2004 Posted March 11, 2004 My problem with camel or pascal style is that you can quickly end in a "name overload". variables, methods and type may have the same name. And, no, there isn't always a "better" name for a variable. I do have some very generic subroutines :) Also, for controls I still use the prefix. It doesn't happen awfully often that a Label turns to a Textbox or a Listview to a Combobox or whatever. But it helps with the programming, just enter txt, hit space, and you see all textboxes on your current form. Plus, I always use a prefix for member variables. Maybe out of habit. But I think it is just safer. (Plus: Just enter me.m, hit space and .... ) my 2c Quote .nerd
*Gurus* divil Posted March 11, 2004 *Gurus* Posted March 11, 2004 http://www.irritatedvowel.com/Programming/Standards.aspx These are the naming conventions you should be using with .NET. You should ensure you comply with these for all public or exposed members at the very least, but it's probably best if you just comply completely. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.