473,842 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"All public methods should be virtual" - yes or no / pros & cons

I'm on a team building some class libraries to be used by many other
projects.

Some members of our team insist that "All public methods should be virtual"
just in case "anything needs to be changed". This is very much against my
instincts. Can anyone offer some solid design guidelines for me?

Thanks in advance....
Nov 15 '05
175 8930
> And what language do you think will be used most in the CLI world and
where
the jobs are :D C#


I wouldn't bet on it. There's a ton of C++ code that will be compiled with
/CLR at some point just to move it to a new platform. That is not likely to
be rewritten in C#.

Just because Microsoft is doing a good job plugging C# doesn't mean that all
of a sudden C++ is dead.

Furthermore, I suspect VB to be bigger (in terms of number of active
developers, code being written) than C# for years to come and I doubt that
C# will ever catch up.
Nov 15 '05 #71
Thats why we have C++/CLI managed extensions. I would imagine most new
projects would be C#, like the redesign of one I am on right now. C++/CLI is
pig fugly.

Im not saying its dead, Im saying thats where alot of work will be heading,
its going that way now and will continue to go. Alot of VB rewrites would
be C#. I am on a rewrite now of old VB6, the guy wanted C++ for its p.enis
extension coolness , i laughed and said no C# is what you are doing because
its perfect for the short dev time for this redesign and more than up to the
job. I would estimate I saved them months of work using it. We also have
non programmer backrounds on the team (specalists in vision) and definatly
because of that C++ = the bad.

He chose C++/CLI for the wrong reasons, coolness and putting hair on his
chest. Typical of an immature, egotistical arrogant developer.


"Martin Maat [EBL]" <du***@somewher e.nl> wrote in message
news:10******** *****@corp.supe rnews.com...
And what language do you think will be used most in the CLI world and where
the jobs are :D C#


I wouldn't bet on it. There's a ton of C++ code that will be compiled with
/CLR at some point just to move it to a new platform. That is not likely

to be rewritten in C#.

Just because Microsoft is doing a good job plugging C# doesn't mean that all of a sudden C++ is dead.

Furthermore, I suspect VB to be bigger (in terms of number of active
developers, code being written) than C# for years to come and I doubt that
C# will ever catch up.

Nov 15 '05 #72
> He chose C++/CLI for the wrong reasons, coolness and putting hair on his
chest. Typical of an immature, egotistical arrogant developer.


Ah, so that's what spoiled your mood, you didn't get your way. Well please
go for a walk next time, get a bit of air instead of disrespecting posters
just because your boss won't have you talk to him that way.
Nov 15 '05 #73
No, I got my way and chose C# for a very good reason, He wanted C++/CLI for
not good reasons ie., coolness factor and was not suited to the project in
hand.

I was just highlighting the kind of reasoning that people chose C++ wrongly
at times.
"Martin Maat [EBL]" <du***@somewher e.nl> wrote in message
news:10******** *****@corp.supe rnews.com...
He chose C++/CLI for the wrong reasons, coolness and putting hair on his
chest. Typical of an immature, egotistical arrogant developer.


Ah, so that's what spoiled your mood, you didn't get your way. Well please
go for a walk next time, get a bit of air instead of disrespecting posters
just because your boss won't have you talk to him that way.

Nov 15 '05 #74
Jon Skeet [C# MVP] wrote:
Anyway, the C++ approach has a cost too: private in C++ being not as
private as in C#/Java comes at the cost of namespace pollution. One of
the nice things about private methods etc is that whatever you call
them when you first write them, you can change that name later with
*no* impact to other classes (that aren't doing nasty reflection
things). No-one else knows about them, because they're private. (Even
the word "private" doesn't ring true with the C++ semantics, IMO.)


The C++ rule that name lookup occurs before access checks is a two-edged
sword. The reason it's done that way is to avoid silent breaking-changes to
derived classes when the public/private-ness of a base class function is
changed.

class A
{
public:
void f(int);
private:
void f(double);
};

class B : public A
{
public:
void g() { f(1.0); } // illegal under C++ rules
};

If access checks were performed before name lookup/overload resolution, the
call in B::g() would bind to f(int). Subsequently changing A::f(double) to
public (or protected) would then silently change the behavior of B::g()
since it would now bind to f(double). In the above example, C++'s rampant
implicit conversion rules conspire to make the situation more difficult as
well.

The flip-side is as you say: in Java/.NET, private parts are more truly
private.

This is definitely an area where C++ and C# are different in subtle ways.
:)
-cd
Nov 15 '05 #75
[still crossposting and asking for crosspost]

On Wed, 28 Jan 2004 00:21:47 +0100, Martin Maat [EBL] wrote:
I am not
saying that polymorphism and events are equivalent, I am saying that the
example provided by Carl is a good example of when you should not use
polymorphism if you do have a more natural alternative like events


Could you please provide example code in C#, with the same (or better ;)
) functionality as Carl's example ? It would be interesting to compare
idiom your are proposing with the one described by Carl.

TIA
B.
Nov 15 '05 #76
Den Wed, 28 Jan 2004 08:10:19 +0000 skrev Jon Skeet[ C# MVP]:
It appears later on that it doesn't actually give a valuable design
idiom, because the method can be called by the derived class anyway.


Well, if you override a method in the derived class you can of course call
that overridden function from within the dervived class. An access
specifier in a base class does not prevent that. THAT would be
counter-intuitive.
But still, you cannot access the method in the base class if it's declared
private, and that's valuable in many design idiom.

--
Dag Henriksson
Nov 15 '05 #77
Dag Henriksson <da***@quidsoft .se> wrote:
But still, you cannot access the method in the base class if it's declared
private, and that's valuable in many design idiom.


I can see that there are possibly a few times it would have value - but
I prefer the simplicity (and future-proofing in terms of naming) of the
C# version, myself.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #78
di********@disc ussion.microsof t.com wrote:
Yes because function prototypes in C are working for us, no no we are
not coding them to help the compilers bad design of not being able to
check usage.


Ahhhh there you were heading, you call the separatation of header and
implementation files bad design? Before posting more such ingenious insigts
I strongly suggest you read what the designer of C++ has to say to people
like you:

http://www.research.att.com/~bs/blast.html

Regards,

Andreas

Nov 15 '05 #79
Brandon J. Van Every wrote:
Andreas Huber wrote:
Brandon J. Van Every wrote:

Keep It Simple Stupid.


Hmmm, why then aren't we still programming in (pre-VB .NET) BASIC? To
me that's much simpler than C# ;-).


Lots of people *are* still programming in pre .NET VB. Languages
have many reasons for evolving other than simplicity and robustness
within a domain. C++ is clearly a kitchen sink language.


While I don't know what you mean by "kitchen sink language" (English is not
my mother-tongue) I think I have a faint idea. Here's what Bjarne Stroustrup
has to say about such blanket statements:

http://www.research.att.com/~bs/blast.html
If you don't understand how that affects
industrial robustness, you are a C++ tweak-head.


Call me whatever you want. You still fail to demonstrate how private
virtuals make things less robust.


It is far more strategic than that. Any time you make a language
with lotsa tweaky special cases you can do "kewl" things with, you
are increasing the number of things that software engineers have to
understand. Consequently, you are decreasing their ability to get
trained and communicate + coordinate effectively with one another.
Sheer dogpile of features will overwhelm engineering efforts, even if
each feature is individually not rocket science to understand.


You could say something similar about just about any spoken language
(English, German, ...). However, when you read a poorly written article
(using lots of little-known language constructs in the wrong places,
obfuscating meaning by making overly long sentences, etc. etc.) do you blame
the language for it? No you don't (at least none of the people I know do),
you blame the writer. Why people blame C++ when they see poorly written code
is beyond me.
It is only natural that you can obfuscate code more in a language that
offers more features helping abstraction. The Java designers once had the
idea of creating a really simple language that everybody can learn in a few
days. I guess I don't have to lecture you that this is no longer the case
with Java 1.5. C# had many more features than Java 1.0 right from the
beginning and they'll add more with the next version of VS. What does that
tell you?
TMK, no C++ expert has ever mentioned private virtuals in this
respect.


The fact of even needing C++ experts such as in
comp.lang.c++.m oderated says it all.


There *are* C# experts and from the sheer volume of traffic on
microsoft.publi c.dotnet.langua ges.csharp I'd say C#ers definitely need them.

Regards,

Andreas

Nov 15 '05 #80

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

Similar topics

164
8069
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be changed". This is very much against my instincts. Can anyone offer some solid design guidelines for me? Thanks in advance....
0
9870
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9715
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,...
0
10940
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10610
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10670
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
7030
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
5695
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
4499
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
3
3141
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.