[program-l] Re: C# attributes

  • From: "Shaikh, Saqib, VF UK - Technology" <Saqib.Shaikh@xxxxxxxxxxxxxxxxx>
  • To: <program-l@xxxxxxxxxxxxx>
  • Date: Mon, 21 Mar 2005 14:41:44 -0000

Thanks for confirming my suspicions! While it's nothing new from a technical 
viewpoint I was just curious to try and understand *why* people choose to do 
things the hard and long way (as in the three cases we've discussed).  I guess 
the answer is this:

humans don't write code: Forms Designer does <grin>

Of course I'm being silly and exagerating, but unlike in the Unix or Mac worlds 
I guess in DotNet people don't write GUI (or many other types of code) by hand. 
 Want an event: click here.

But thanks for clearing things up for me.  For the moment I'll continue using 
my own unofficial naming conventions and style; one day no doubt I'll give into 
the mighty IDE and let it do all the work for me, even if it does make the code 
messy <grin>.

Saqib


Saqib Shaikh
Business Analyst
Wholesale Delivery

Telephone: +44 (0)1635 682958
Mobile: +44 (0)7747 461634
Email: saqib.shaikh@xxxxxxxxxxxx

> Vodafone Limited
> Registered Office: Vodafone House, The Connection, Newbury, Berkshire, RG14 
> 2FN
> Registered in England No 2227940


-----Original Message-----
From: program-l-bounce@xxxxxxxxxxxxx
[mailto:program-l-bounce@xxxxxxxxxxxxx]On Behalf Of David Lant
Sent: 21 March 2005 14:31
To: 'program-l@xxxxxxxxxxxxx'
Subject: [program-l] Re: C# attributes


Hi Saqib,

The thing about .NET, is it is *very* generous. <grin>  You can fully
qualify if you like.  But you don't have to.  In C#, to avoid having to code
System.Windows.Forms.Label, you can put the following at the top of your
code:

Using System.Windows.Forms

Then you can simply refer to Label like:

Label l

The only reason I fully qualified in my message, was because there is more
than one Label class known to the .NET CTS, and so just saying Label
wouldn't have made that clear.  E.g. there are System.Web.UI.Lable classes I
think.

As for the This or Me keyword, I think that is personal preference and
removing ambiguity.  I tend to go for unique variable names, rather than
duplicate but qualified ones.  Both systems work, but it is down to how you
like it.

David Lant

I.T. Consultant 
Consultancy & Development
ICT Services
Tel: (01392) 382464

Devon County Council accepts no legal responsibility for the contents of
this message. The views expressed do not reflect those of Devon County
Council.


-----Original Message-----
From: Shaikh, Saqib, VF UK - Technology
[mailto:Saqib.Shaikh@xxxxxxxxxxxxxxxxx] 
Sent: 21 March 2005 14:18
To: program-l@xxxxxxxxxxxxx
Subject: [program-l] Re: C# attributes


Thanks once again David

I'll probably stick with using properties for now; and maybe one day I'll
start using the forms designer.  Hopefully The express editions for 2005,
which I'm guessing are likely to retail for about £100, will be fully
accessible with JAWS.

But on a related topic, why do so many Dot Net programmers (including the
code created by the Forms Designer) use fully qualified namespaces?  E.g.
system.windows.forms.label l=new system.windows.forms.label();
I guess it could potentially be to avoid namespace clashes, but again it's
messy to listen to <grin>.  I suppose my problem is that I've been use a
porper's tools (command line compilers with Notepad/Textpad) for way too
long!

And a second related question: is the fact that so many programmers fully
qualify "this" something to do with properties again?
this.Text="something";
rather than
text="something";

Thanks for your help.

Saqib


Saqib Shaikh
Business Analyst
Wholesale Delivery

Telephone: +44 (0)1635 682958
Mobile: +44 (0)7747 461634
Email: saqib.shaikh@xxxxxxxxxxxx

> Vodafone Limited
> Registered Office: Vodafone House, The Connection, Newbury, Berkshire,
RG14 2FN
> Registered in England No 2227940


-----Original Message-----
From: program-l-bounce@xxxxxxxxxxxxx
[mailto:program-l-bounce@xxxxxxxxxxxxx]On Behalf Of David Lant
Sent: 21 March 2005 14:07
To: 'program-l@xxxxxxxxxxxxx'
Subject: [program-l] Re: C# attributes


Hi Saqib,

Yes, you were referring to properties. <smile>  On that basis, I think the
second part of my message would apply.  Notably, that the restriction on the
constructors of a Label class is a feature of the .NET CTS, rather than of
C#.

If you feel you are likely to want to frequently define labels and specify
properties at the point you create them, then I would suggest it would be
worth your while creating your own custom label class that inherits from the
System.Windows.Forms.Lable class, and add your own overloaded constructors.
Then you could even set your own defaults.  E.g. the standard label class
has the AutoSize property set to False.  But you could decide to have it
default to True, and thus avoid setting such things.  Or you could use the
PreferredHeight and PreferredWidth properties likewise.  I *think* that's
what they're called anyway. <smile>

David Lant

I.T. Consultant 
Consultancy & Development
ICT Services
Tel: (01392) 382464

Devon County Council accepts no legal responsibility for the contents of
this message. The views expressed do not reflect those of Devon County
Council.


-----Original Message-----
From: Shaikh, Saqib, VF UK - Technology
[mailto:Saqib.Shaikh@xxxxxxxxxxxxxxxxx] 
Sent: 21 March 2005 13:57
To: program-l@xxxxxxxxxxxxx
Subject: [program-l] Re: C# attributes


Hi David

Thanks for your quick reply.  It's quite possible that I have got the
terminology wrong and I actually mean properties instead of attributes,
e.g.:
label.text="text";
label.font=bla bla bla

It is quite possible that using the form designer would help me but I don't
have the money to ffork out on VS - about £750 or more I believe.  I've just
graduated from uni and started my first job - it'll be many many many years
before I can afford that kind of software <grin>.  I bought VS6 many years
ago but of course that is now showing its age.

Saqib


Saqib Shaikh
Business Analyst
Wholesale Delivery

Telephone: +44 (0)1635 682958
Mobile: +44 (0)7747 461634
Email: saqib.shaikh@xxxxxxxxxxxx

> Vodafone Limited
> Registered Office: Vodafone House, The Connection, Newbury, Berkshire,
RG14 2FN
> Registered in England No 2227940


-----Original Message-----
From: program-l-bounce@xxxxxxxxxxxxx
[mailto:program-l-bounce@xxxxxxxxxxxxx]On Behalf Of David Lant
Sent: 21 March 2005 13:43
To: 'program-l@xxxxxxxxxxxxx'
Subject: [program-l] Re: C# attributes


Hi Saqib,

Firstly I'll qualify anything I'm about to say with the caveat that I am
neither a Java nor a C# programmer.  However, having got into .NET a fair
bit, I think I may have some input.

Part of the problem may be nomenclature.  I understand attributes to be
something very different than parameters to functions.  Attributes as I
understand them are qualities of the class itself that can be specified at
design time, such as whether the class is serializable or supports some
Enterprise Services feature or other.  E.g.

<Serializable()> Public Class MyWidget()

However, the sample code you supplied looks more like constructors for a
class than anything.  If so, then you can indeed do that with C#, as long as
the object you are instantiating has the overloaded constructor defined to
allow you to specify those parameters.  Since both VB and C# use the same
class libraries for controls, I can check to see if Labels do indeed have
constructors as you indicate.  And on looking, I see that the Label class
does not have any overloaded constructors to allow this.  So, on that basis,
you are right in that you need to individually specify the properties of the
label.

However, You could always create your own Label class which inherits from
the standard class, and set your own overloaded constructors to make your
coding life easier.  It would only be a one-off effort.

Lastly, I would ask why you don't use the form designer to lay out the
controls?  That way, Visual Studio would generate the necessary lines, and
as they are placed within the form generated code section, you can collapse
that region of code so you don't need to browse through it all the time.
This may simply be a matter of preference, and I can respect that.

Just some of my uninformed musings...  Do with them as you will. <smile>

David Lant

I.T. Consultant 
Consultancy & Development
ICT Services
Tel: (01392) 382464

Devon County Council accepts no legal responsibility for the contents of
this message. The views expressed do not reflect those of Devon County
Council.


-----Original Message-----
From: Shaikh, Saqib, VF UK - Technology
[mailto:Saqib.Shaikh@xxxxxxxxxxxxxxxxx] 
Sent: 21 March 2005 13:21
To: program-l@xxxxxxxxxxxxx
Subject: [program-l] C# attributes


Hi

I've been programming in C/C++ for about ten years and Java (my current
prefered language) for about 5).  I recently started developing in C# and
the problem is that it is too similar to Java.  This lulls me into a false
sense of security; but every so often I find something different.  Syntactic
differences are ok, but what is ahrder is the philosophical differences.

A case in point: what I believe are called attributes.  If I'm right, it
feels like C# gives one the ability to say classname.attributename instead
of classname.getAttributename() or set as well.

This is kind of nice, but at the end of the day if I am right it is nothing
more than syntactic sugar.  What do other people think?  I'd much rather say
something like:
Label l=new Label("some text", Orientation.CENTER, new Font("arial",
Font.BOLD|Font.ITALIC));
Component.add(l, x, y);

In C# the way I see it written this would take up at minimum six lines; I'd
also have to specify the size of the label (I hate doing this), and also the
tabstop order, etc, giving about nine or ten lines of code in totoal.  As a
blind person who cursors down through code this is highly annoying.

Can anyone enlighten me as to why this is a good idea?  Are parameters to
functions old-fashioned? <grin>

Saqib

Saqib Shaikh
Business Analyst
Wholesale Delivery

Telephone: +44 (0)1635 682958
Mobile: +44 (0)7747 461634
Email: saqib.shaikh@xxxxxxxxxxxx

> Vodafone Limited
> Registered Office: Vodafone House, The Connection, Newbury, Berkshire,
RG14 2FN
> Registered in England No 2227940
> 
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: