473,699 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A couple questions of style

I'm always curious on some of these style issues if there seem to actually
be objective reasons for doing things one way or the other, so here goes for
a little lighter discussion.

1) Default constructors. Do you always write a constructor for every
class, even when it doesn't do anything special, or do you "trust" the
default one that will be generated?

2) Regions. I really really like the region feature for organizing code
and reducing noise in the IDE. I've seen quite a bit of code where people
put all the private class variables together right at the top of the class
in their own region. Lately I've seen code where they are scattered in the
various regions where they are actually used - near the corresponding
property code, for example. The latter seems a bit more useful for someone
like me who loves regions.
Nov 15 '05 #1
14 1339
Hi Daniel,
1) Default constructors. Do you always write a constructor for every
class, even when it doesn't do anything special, or do you "trust" the
default one that will be generated?
I usually write a constructor myself (to be more exact, when you add a new
class from the IDE, the empty constructor is already written for you).
2) Regions. I really really like the region feature for organizing code
and reducing noise in the IDE. I've seen quite a bit of code where people
put all the private class variables together right at the top of the class
in their own region.
This is the style I prefer. In my classes, I usually organize code like
this:

Constants
Private members
Constructor(s)
Public methods
Public properties
Public events
Protected methods
Protected properties
Protected events
Internal methods
Internal properties
Internal events
Private methods
Private properties
Private events

If there are some static members, they go before the instance ones in the
order outlined above.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Daniel Billingsley" <db**********@N O.durcon.SPAAMM .com> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l... I'm always curious on some of these style issues if there seem to actually
be objective reasons for doing things one way or the other, so here goes for a little lighter discussion.

1) Default constructors. Do you always write a constructor for every
class, even when it doesn't do anything special, or do you "trust" the
default one that will be generated?

2) Regions. I really really like the region feature for organizing code
and reducing noise in the IDE. I've seen quite a bit of code where people
put all the private class variables together right at the top of the class
in their own region. Lately I've seen code where they are scattered in the various regions where they are actually used - near the corresponding
property code, for example. The latter seems a bit more useful for someone like me who loves regions.


Nov 15 '05 #2

Hi Daniel,

Thanks for posting in this group.
Personally, I think:
1). Because the compiler will generate a default constructor for you, there
is no matter whether you create a empty constructor or not.
2). I think if one class variable is only for property usage, I prefer to
create the variable just above the property definition. I will place other
non-static variables in the same region.

This is just a personally programming style, let's hear some others'
suggestion.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
Daniel.... I would lean to explicitly writing an empty constructor if I
wanted to support an empty constructor. If someone updates your code
and adds a custom construtor, the default constructor will be silently
removed!

I usually declare variables at the top. If the variable is _only_ used
in a
local section of code, then I would put it close to the code. This is
the
"principle of proximity," Code Complete, Mcconnell.

Regards,
Jeff
1) Default constructors. Do you always write a constructor for every

class, even when it doesn't do anything special, or do you "trust" the
default one that will be generated?<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4
"Daniel Billingsley" <db**********@N O.durcon.SPAAMM .com> wrote in message news:<##******* *******@tk2msft ngp13.phx.gbl>. ..
I'm always curious on some of these style issues if there seem to actually
be objective reasons for doing things one way or the other, so here goes for
a little lighter discussion.

1) Default constructors. Do you always write a constructor for every
class, even when it doesn't do anything special, or do you "trust" the
default one that will be generated?
I like my code lean and mean, so I delete everything unnecessary. It
saves me the trouble of thinking "... ok, default constructor that
doesn't do anything..."

2) Regions. I really really like the region feature for organizing code
and reducing noise in the IDE. I've seen quite a bit of code where people
put all the private class variables together right at the top of the class
in their own region. Lately I've seen code where they are scattered in the
various regions where they are actually used - near the corresponding
property code, for example. The latter seems a bit more useful for someone
like me who loves regions.


I would rather see the member declarations collected at the top, so I
can think "ok, this class has abc and provides services xyz".
Nov 15 '05 #5
Agreeing with Kevin, whats the point of a default constructor that does
nothing, yet leaves the object in an invalid state?

COM forced us to perform initialization through a myriad of Property setting
or via an uncommon "Initialize " or Init or whatever the component designer
decided on, which was always a "bad thing" since Components that rely on
particular states can become very hard to program and henceforth hard to
debug if the only way to achieve the proper state is through setting
multiple, possibly "un-grouped" properties before the Component is in a
valid state to do something...

I also get somewhat irritated with some of the .NET Framework functions,
specifically the WebServices where an object that is passed via parameter or
return value from the web service is REQUIRED to have a default constructor
and settable properties, instead of utilizing a Serialization [via
ISerializable] technique to remove this "defalt constructor" requirement.
--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]
"Kevin Cline" <kc******@hotma il.com> wrote in message
news:ba******** *************** ***@posting.goo gle.com...
"Daniel Billingsley" <db**********@N O.durcon.SPAAMM .com> wrote in message

news:<##******* *******@tk2msft ngp13.phx.gbl>. ..
I'm always curious on some of these style issues if there seem to actually be objective reasons for doing things one way or the other, so here goes for a little lighter discussion.

1) Default constructors. Do you always write a constructor for every
class, even when it doesn't do anything special, or do you "trust" the
default one that will be generated?


I like my code lean and mean, so I delete everything unnecessary. It
saves me the trouble of thinking "... ok, default constructor that
doesn't do anything..."

2) Regions. I really really like the region feature for organizing code and reducing noise in the IDE. I've seen quite a bit of code where people put all the private class variables together right at the top of the class in their own region. Lately I've seen code where they are scattered in the various regions where they are actually used - near the corresponding
property code, for example. The latter seems a bit more useful for someone like me who loves regions.


I would rather see the member declarations collected at the top, so I
can think "ok, this class has abc and provides services xyz".

Nov 15 '05 #6
Eric Newton wrote:
Agreeing with Kevin, whats the point of a default constructor that
does nothing, yet leaves the object in an invalid state?


The assumption of course is that calling a parameterless constructor
yields an object whose state is not valid. Such should not be the case.

Personally, I prefer to code my own constructors simply to make the
design clear. Why force readers to wonder where a default constructor
originates in your object hierarchy when you can answer the question
with a single line of code?

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #7
EventArgs constructors.

I normally block the parameterless default ctor in favour of enforcing event
parameter rules on the constructor rather than propertys (they are still
available) but i enforce minimum construction.

"Frank Oquendo" <fr****@acadxpi n.com> wrote in message
news:uO******** ******@TK2MSFTN GP12.phx.gbl...
Eric Newton wrote:
Agreeing with Kevin, whats the point of a default constructor that
does nothing, yet leaves the object in an invalid state?


The assumption of course is that calling a parameterless constructor
yields an object whose state is not valid. Such should not be the case.

Personally, I prefer to code my own constructors simply to make the
design clear. Why force readers to wonder where a default constructor
originates in your object hierarchy when you can answer the question
with a single line of code?

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)

Nov 15 '05 #8
Indeed! This is one of those points that is both good and objective I was
talking about (as opposed to purely personal style) and hadn't considered.

"Jeff Louie" <je********@yah oo.com> wrote in message
news:e5******** ******@TK2MSFTN GP12.phx.gbl...
Daniel.... I would lean to explicitly writing an empty constructor if I
wanted to support an empty constructor. If someone updates your code
and adds a custom construtor, the default constructor will be silently
removed!

Nov 15 '05 #9
Indeed Frank. In fact, I think declaring the simple constructor also has
the side-effect of explicitly announcing that the object will be in a valid
state at that point, doesn't it? That seems like a good thing to me.

"Frank Oquendo" <fr****@acadxpi n.com> wrote in message
news:uO******** ******@TK2MSFTN GP12.phx.gbl...
Eric Newton wrote:
Agreeing with Kevin, whats the point of a default constructor that
does nothing, yet leaves the object in an invalid state?


The assumption of course is that calling a parameterless constructor
yields an object whose state is not valid. Such should not be the case.

Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1203
by: dasacc | last post by:
(1) How do I perform a search for "word" and have it return every line that this instance is found? (2) How do I perform a search for "word" and "wordtwo" at the same time to return every line these instances are found so that the order in which these lines are in are left intact. If there's another standard module more suited for this let me know, and no I dont want to use sed :)
2
1546
by: PointNot | last post by:
I'm coding in Dev C++ by bloodshed my questions are.... I want to learn to create GUI windows interfaces, can I do it in here. I've never learned the visual aspect of C++ yet, and would like to learn, any good sites to help me out. THanks
3
983
by: jy836 | last post by:
1) When using images for an application (such as in an ImageList or as the image for a button), are the images embedded in the application or must the image files be included in the setup package? 2) Is there a way to adjust the individual column widths of a DataGrid which has no TableStyles or GridColumnStyles? Also, is there a way to make it impossible for the user to resize the columns and rows?
0
8617
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8884
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7751
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.