473,842 Members | 1,958 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 8932
Brandon J. Van Every wrote:
Andreas Huber wrote:
Brandon J. Van Every wrote:

Simple: If you don't understand it, don't use it and everything will
be well. If you happen to maintain somebody else's code using the
private virtual idiom it should become obvious very quickly how it
works. If not, post an appropriate question to comp.lang.c++ ;-).
I really fail to see how private virtuals hurt "industrial
robustness".
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# ;-).
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.
People get paid
looooooootsa money to understand each and every one of C++'s
weirdnesses.


I've never seen such people. I'd rather say people get paid loads of money
to do proper software engineering. Yes, C++ has it's shady corners I'd
rather not have in the language but private virtuals is not one of them.
TMK, no C++ expert has ever mentioned private virtuals in this respect.

Regards,

Andreas

Nov 15 '05 #51
n!
> > there are times when it's useful.

Name one :-).


Can I just note, I wasn't trying to argue for or against private virtuals,
just noting why they're different to protected virtuals :) However, Jim
Hyslop and Herb Sutter wrote a nice article that provided a reasonable
example: http://www.cuj.com/documents/s=8000/cujcexp1812hyslop/

I actually regularly develop using both C++ and C#, I haven't especially
missed private virtuals (the times when I may have used them, attributes
have made much better alternatives). :)

n!
Nov 15 '05 #52
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.
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.
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.

Mantra:
Forest. Trees. Forest. Trees.

And I'm not talking inheritance.

--
Cheers, www.indiegamedesign.com
Brandon Van Every Seattle, WA

20% of the world is real.
80% is gobbledygook we make up inside our own heads.

Nov 15 '05 #53
"Brandon J. Van Every" <reverse it com dot indiegamedesign at vanevery>
skrev i meddelandet news:u%******** ********@TK2MSF TNGP12.phx.gbl. ..
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.


I don't understand your way of thinking here. C++ has no special case for
private virtual member functions. Private means what it always do, it limits
the access to it's own class. Virtual means what it always do, it can be
overridden by derived classes. The combination is no special case. It seems
like it's C# that has a special case for the combination by not allowing it.

--
Dag Henriksson
Nov 15 '05 #54
Dag Henriksson <da************ @hotmail.com> wrote:
I don't understand your way of thinking here. C++ has no special case for
private virtual member functions. Private means what it always do, it limits
the access to it's own class. Virtual means what it always do, it can be
overridden by derived classes. The combination is no special case. It seems
like it's C# that has a special case for the combination by not allowing it.


Not at all - it's just that C#'s idea of "private" is a lot simpler
than C++'s: "Private means nothing outside the class knows it's there
at all" effectively.

--
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 #55
<.> wrote in message news:<uI******* ******@TK2MSFTN GP11.phx.gbl>.. .
You call having to DUPLICATE method signitures (prototypes) as good coding?
Its to make up for the bad design in the compilers.
Sorry, I haven't got a clue what you're talking about. How do private
virtual functions duplicate method signatures?
These days our Tools work for us not we work for them. Welcome to the REAL
world.


Well, C++ compilers have always worked for me and they still do(the
same goes for the C# compiler). I don't see how that could ever be the
other way round.

Regards,

Andreas
Nov 15 '05 #56
> Not at all - it's just that C#'s idea of "private" is a lot simpler
than C++'s: "Private means nothing outside the class knows it's there
at all" effectively.


Aha, I see. In C# public/protected/private controls visibilty, in contrast
to C++ where it controls accessibility.

--
Dag Henriksson
Nov 15 '05 #57
If its private its for that class as you state, if its inherited from that
base class, its nolonger the same class so private should not be visible to
the inherited class.

Thats logic.
"Dag Henriksson" <da************ @hotmail.com> wrote in message
news:bv******** ****@ID-200546.news.uni-berlin.de...
"Brandon J. Van Every" <reverse it com dot indiegamedesign at vanevery>
skrev i meddelandet news:u%******** ********@TK2MSF TNGP12.phx.gbl. ..
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.


I don't understand your way of thinking here. C++ has no special case for
private virtual member functions. Private means what it always do, it

limits the access to it's own class. Virtual means what it always do, it can be
overridden by derived classes. The combination is no special case. It seems like it's C# that has a special case for the combination by not allowing it.
--
Dag Henriksson

Nov 15 '05 #58
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.
"Andreas Huber" <ah****@gmx.net > wrote in message
news:3e******** *************** ***@posting.goo gle.com...
<.> wrote in message news:<uI******* ******@TK2MSFTN GP11.phx.gbl>.. .
You call having to DUPLICATE method signitures (prototypes) as good coding? Its to make up for the bad design in the compilers.


Sorry, I haven't got a clue what you're talking about. How do private
virtual functions duplicate method signatures?
These days our Tools work for us not we work for them. Welcome to the REAL world.


Well, C++ compilers have always worked for me and they still do(the
same goes for the C# compiler). I don't see how that could ever be the
other way round.

Regards,

Andreas

Nov 15 '05 #59
visibility and accessability are one of the same. If you cant see it you
cant do jack with it. What you cant see you cant access. Obviously.

C# doesnt have the concept of "funtion prototypes" in header files because
the compiler can take care of that, why duplicate code for every method?
That is the fault of the design of C++ compilers so we have to do the work
for it.

Function prototypes are simply a hack for a bad compiler.
"Dag Henriksson" <da************ @hotmail.com> wrote in message
news:bv******** ****@ID-200546.news.uni-berlin.de...
Not at all - it's just that C#'s idea of "private" is a lot simpler
than C++'s: "Private means nothing outside the class knows it's there
at all" effectively.


Aha, I see. In C# public/protected/private controls visibilty, in contrast
to C++ where it controls accessibility.

--
Dag Henriksson

Nov 15 '05 #60

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
10942
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
9452
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...
1
7855
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
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...
0
5884
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
2
4088
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3142
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.