Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2013, 11:57 AM
Authorized User
 
Join Date: Jan 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
Default Variable naming conventions.

Most books I've read try to build on some kind of standard naming convention for fields and such. Buttons become btnButtonName, labels become lblLabelName, text boxes txtTextBoxName, etc.. This book doesn't do that. Is there a particular reason for it?

I started out renaming the examples as I worked through them, but when I saw that the book was going to use the same site from beginning to end I switched to using the format that you provided. I'd rather have been using that kind of convention, though, as it feels wrong to not have some kind of naming standard.
 
Old February 21st, 2013, 04:21 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The naming convention you are referring to is called Hungarian notation where the variable is prefixed with its type. So, an integer called Age would be iAge, a name would be sFirstName and so on.

Given the great capabilities in IDEs like Visual Studio, this is no longer recommended. You simply hover over the variable and you'll see its type. So you're recommended to use names like age and firstName instead. This makes your code easier to read and maintain.

You can use the same mechanism for web controls. When used in Code Behind, just hover and you see the type. For controls the naming mechanism is slightly more complicated. If you think of "Country" you can imagine it's a string data type so you wouldn't need to hover over the variable. But by which control is it represented? A TextBox? A DropDownList? You can't really tell and that's why I suffix them with the control, or a generalization of the control (e.g. GenreList represents the genres in some list control; I may not care that much about the exact control that's being used).

In previous versions of the book I did use prefixes such as btn and txt. In this version I only use the conventions described above, except for cases where the name doesn't really matter and I leave the default name in place (TextBox1, DropDownList2 etc).

Remember: this is just a naming convention. If you don't like it, pick something that works for you. Being consistent is far more important than the actual convention you choose.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Naming conventions Isakkirajan BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 1 July 13th, 2009 08:13 AM
Namespace Naming Conventions For Layerd Applicatio Muhammad Zeeshan General .NET 2 September 1st, 2007 02:03 PM
Variables in the four naming conventions FJInfante SQL Server 2000 3 May 1st, 2006 01:06 PM
Variable naming in Beginning PHP, Apache, MySQL We richard.york Forum and Wrox.com Feedback 0 April 12th, 2004 07:05 PM
Naming conventions jara VS.NET 2002/2003 3 June 22nd, 2003 04:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.