C++ Coding Standards : 101 Rules, Guidelines, and Best Practices by
Herb Sutter, Andrei Alexandrescu is now a month or so away from
release. What is people's opinion on this...is it going to be a
seminal work or lackluster
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]
Jul 22 '05
27 3481
ma740988 wrote: 42 per the text. Dont give away your internals
Accessor and mutator as I understand it are - for the most part - design flaws. The example in the text shows a GetBuffer member function returing a char* In any event, when data needs to be shared among classes this accessor/mutator beats the alternative (public member data) so I've never quite understood this one. A host of get and sets - I suspect - are signs of poor design. I'd still like to see a concrete example that shows the solution.
OO design is about behavior. Classes should tell others what to do. If a
class takes data out of another, manipulates it, and puts it back in, then
the behavior is in the wrong class.
If you indeed share data, then this "data transfer object" should be a
separate thing, without any behavior, and the classes should pass it around.
--
Phlip http://industrialxp.org/community/bi...UserInterfaces
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]
Phlip wrote: OO design is about behavior. Classes should tell others what to do. If a class takes data out of another, manipulates it, and puts it back in, then the behavior is in the wrong class.
I don't know how widely shared that opinion is. One view of OOP is
expressed in Roman Mäder's _Computer Science With Mathematica_ as follows:
"An object is, therefore, a collection of data elements together with the
functions operating on them."
If you indeed share data, then this "data transfer object" should be a separate thing, without any behavior, and the classes should pass it around.
So, for example, and int should have a wrapper class called Integer?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]
Steven T. Hatton wrote: Phlip wrote: OO design is about behavior. Classes should tell others what to do. If a class takes data out of another, manipulates it, and puts it back in,
then the behavior is in the wrong class.
I don't know how widely shared that opinion is. One view of OOP is expressed in Roman Mäder's _Computer Science With Mathematica_ as follows: "An object is, therefore, a collection of data elements together with the functions operating on them."
Designing a program means organizing the relations between its structure in
memory and their behavior in time.
OO design is about partitioning that behavior with polymorphism.
I am aware that the entry-level tutorials describe objects as data and the
functions that operate on them. You can also find tutorials that say "OO
objects are like real-world objects". If you indeed share data, then this "data transfer object" should be a separate thing, without any behavior, and the classes should pass it around.
So, for example, and int should have a wrapper class called Integer?
Why?
It's the same question as before - what is an int's behavior? If it has only
a little, then it's a "value object", and unbeholden to any one class.
--
Phlip http://industrialxp.org/community/bi...UserInterfaces
Phlip wrote: Steven T. Hatton wrote:
Phlip wrote: > OO design is about behavior. Classes should tell others what to do. If > a class takes data out of another, manipulates it, and puts it back in, then > the behavior is in the wrong class.
I don't know how widely shared that opinion is. One view of OOP is expressed in Roman Mäder's _Computer Science With Mathematica_ as follows: "An object is, therefore, a collection of data elements together with the functions operating on them."
Designing a program means organizing the relations between its structure in memory and their behavior in time.
OO design is about partitioning that behavior with polymorphism.
Not all classes exhibit polymorphism. How do the so-called concrete classes
fit into your model?
I am aware that the entry-level tutorials describe objects as data and the functions that operate on them. You can also find tutorials that say "OO objects are like real-world objects".
What I quoted from is a textbook used at ETH in Zrich. Perhaps you've heard
of the University? It's where Einstein got his degree in Physics. > If you indeed share data, then this "data transfer object" should be a > separate thing, without any behavior, and the classes should pass it > around.
So, for example, and int should have a wrapper class called Integer?
Why?
It's the same question as before - what is an int's behavior? If it has only a little, then it's a "value object", and unbeholden to any one class.
I guess I'm confused about what you mean by shared data. Using set and get
methods is not typically considered sharing data. If I have a class called
Arrow which has different properties such as color, length, position,
rotation, etc., how am I supposed to manipulate objects of that class in
order to change these properties? Am I expected not to be interested in
the current value of these objects at runtime? If I am interested in
observing these values, then how am I expected to access them without 'get'
methods?
If I understand the opinion that I should not use set and get methods, it
means I should not have code such as that shown below. Is that what you
are trying to suggest?
class Light{
//...
virtual const array<GLfloat,4 >& ambient() const {return _ambient; }
virtual void ambient(const array<GLfloat,4 >& ambient_)
{
_ambient = ambient_;
}
virtual const array<GLfloat,4 >& diffuse() const {return _diffuse; }
virtual void diffuse(const array<GLfloat,4 >& diffuse_)
{
_diffuse = diffuse_;
}
virtual const array<GLfloat,4 >& specular() const {return _specular; }
virtual void specular(const array<GLfloat,4 >& specular_)
{
_specular = specular_;
}
virtual const array<GLfloat,4 >& ambientModel() const
{
return _ambientModel;
}
virtual void ambientModel(co nst array<GLfloat,4 >& ambientModel_)
{
_ambientModel = ambientModel_;
}
virtual GLenum light() const {return _light; }
virtual void light(GLenum light_)
{
_light = light_;
}
protected:
array<GLfloat,4 > _position;
array<GLfloat,4 > _ambient;
array<GLfloat,4 > _diffuse;
array<GLfloat,4 > _specular;
array<GLfloat,4 > _ambientModel;
GLenum _light;
};
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
Steven T. Hatton wrote: Designing a program means organizing the relations between its structure in memory and their behavior in time.
OO design is about partitioning that behavior with polymorphism. Not all classes exhibit polymorphism. How do the so-called concrete
classes fit into your model?
Another aspect of design is how easily it can change. Most methods should
not be virtual, and most re-use should be delegated, not inherited. I am aware that the entry-level tutorials describe objects as data and
the functions that operate on them. You can also find tutorials that say "OO objects are like real-world objects".
What I quoted from is a textbook used at ETH in Zrich. Perhaps you've
heard of the University? It's where Einstein got his degree in Physics.
I'm sitting on the same landmass as Cal Tech. Perhaps you have heard of Cal
Tech? It's where they invented something that I decline to look up with
Google.
I could let your fallacy of "appeal to authority" slide, except you seem to
think you are arguing with me about something. I'm not sure what.
The point: Classes should minimize getters and setters, because they should
expose access to behaviors.
I guess I'm confused about what you mean by shared data. Using set and
get methods is not typically considered sharing data. If I have a class
called Arrow which has different properties such as color, length, position, rotation, etc., how am I supposed to manipulate objects of that class in order to change these properties? Am I expected not to be interested in the current value of these objects at runtime? If I am interested in observing these values, then how am I expected to access them without
'get' methods?
Okay, I'm going to make a great effort to agree with you here, but I need
you to know that before I start, because I'm trying to avoid one of /those/
threads...
Consider this graphic:
A -> B
The "behavior" of -> is that it points at B. However, if we move B...
A ->
B
....then -> no longer points at B. Let's call that behavior "extrinsic" .
->'s intrinsic behavior is its tail is there and its head is here, etc. Set
these behaviors with setters.
Limit your application's access to those setters. A class aware of A -> B
could respond to high-level commands that move B by fixing the extrinsic
behavior of the arrow. However, that AB class should not make its awareness
of -> public. The buck stops here.
Encapsulation is hierarchical. The rule "Don't make primitive things
globally public" is more useful than the rule "don't make data members
public".
--
Phlip http://industrialxp.org/community/bi...UserInterfaces
Phlip wrote: Steven T. Hatton wrote: Not all classes exhibit polymorphism. How do the so-called concrete classes fit into your model?
Another aspect of design is how easily it can change. Most methods should not be virtual, and most re-use should be delegated, not inherited.
That really depends on what you are designing. IMO, if you make one member
function virtual, you should have a good reason /not/ to make the remainder
virtual. I'll follow Stroustrup's convention of reserving the term
"method" for pure virtual member functions.
I could let your fallacy of "appeal to authority" slide, except you seem to think you are arguing with me about something. I'm not sure what.
There is no fallacy in appeal to authority when the subject is one of widely
help opinions in a field. The opinions of authorities in the field
constitute the topic.
The point: Classes should minimize getters and setters, because they should expose access to behaviors.
The fundamental concept of object oriented programming is the idea of data
objects combined with associated operators.
Okay, I'm going to make a great effort to agree with you here, but I need you to know that before I start, because I'm trying to avoid one of /those/ threads...
Consider this graphic:
A -> B
The "behavior" of -> is that it points at B. However, if we move B...
A -> B
...then -> no longer points at B. Let's call that behavior "extrinsic" .
->'s intrinsic behavior is its tail is there and its head is here, etc. Set these behaviors with setters.
Limit your application's access to those setters. A class aware of A -> B could respond to high-level commands that move B by fixing the extrinsic behavior of the arrow. However, that AB class should not make its awareness of -> public. The buck stops here.
Encapsulation is hierarchical. The rule "Don't make primitive things globally public" is more useful than the rule "don't make data members public".
This seems like a far weaker statement than the idea that using set and get
methods indicated a probable design flaw. That was, IIRC, the point at
which this thread forked. Stroustrup makes a similar assertion in
TC++PL(SE) regarding set and get methods. I have questioned that in this
newsgroup, and I have never been convinced of the merits of the general
guideline. Perhaps a better statement might be 'Be judicious in what you
expose through accessor methods'. That I can agree with.
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
Someone wrote: Accessor and mutator as I understand it are - for the most part - design flaws. The example in the text shows a GetBuffer member function returing a char* In any event, when data needs to be shared among classes this accessor/mutator beats the alternative (public member data) so I've never quite understood this one. A host of get and sets - I suspect - are signs of poor design. I'd still like to see a concrete example that shows the solution.
You are asking for a concrete solution to an unexpressed problem. Remember
we can't see what you are looking at in a book.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]
Steven T. Hatton wrote: This seems like a far weaker statement than the idea that using set and
get methods indicated a probable design flaw.
Using getters and setters indicates a probable design flaw.
That was, IIRC, the point at which this thread forked. Stroustrup makes a similar assertion in TC++PL(SE) regarding set and get methods. I have questioned that in this newsgroup, and I have never been convinced of the merits of the general guideline. Perhaps a better statement might be 'Be judicious in what you expose through accessor methods'. That I can agree with.
Encapsulation is hierarchical. The root principle of OO is encapsulation of
indirection. Without polymorphism there is no OO. (Regardless of whether a
given program happens to use virtuals.)
"Data objects with the methods that operate on them" is just "object based".
--
Phlip http://industrialxp.org/community/bi...UserInterfaces
Phlip wrote: Steven T. Hatton wrote:
This seems like a far weaker statement than the idea that using set and get methods indicated a probable design flaw.
Using getters and setters indicates a probable design flaw.
In your unsubstantiated opinion. That was, IIRC, the point at which this thread forked. Stroustrup makes a similar assertion in TC++PL(SE) regarding set and get methods. I have questioned that in this newsgroup, and I have never been convinced of the merits of the general guideline. Perhaps a better statement might be 'Be judicious in what you expose through accessor methods'. That I can agree with.
Encapsulation is hierarchical. The root principle of OO is encapsulation of indirection. Without polymorphism there is no OO. (Regardless of whether a given program happens to use virtuals.)
"Data objects with the methods that operate on them" is just "object based".
My reason for saying the fundamental concept of object oriented programming
is the idea of data objects combined with associated operators, is based on
a comment in Ole-Johan Dahl's The *Birth of Object Orientation: the Simula
Languages*:
"... The example shows that the idea of data objects with associated
operators was under way already in 1965."
That seems to be the watershed in his mind as to when OOP first appeared. I
will note that he subsequently adds:
"There is universal use of the term "object orientation", OO. Although no
standard definition exists, some or all of the above ideas enter into the
OO paradigm of system development."
You are free to continue making absolute assertions such as "OO design is
about behavior", but please don't expect such statements to be taken too
seriously by experience computer professionals.
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Isaac Rodriguez |
last post by:
Hi,
I am fairily new to Python, but I am really liking what I am seeing. My team
is going to re-design some automation projects, and we were going to use
Python as our programming language. One of the things we would like to do,
since we are all new to the language, is to define a set of guidelines and
best practices as our coding standards.
Does anyone know where I can get some information about what the community
is doing? Are there...
|
by: Todd |
last post by:
Does anyone know of a book for C# .NET on coding
standards and guidelines? My company is in the process
of defining this stuff as we move to C# .NET.
I could swear I picked up a book like this in a technical
bookstore, but now I can't find one searching Amazon.com
or anywhere else.
By the way, I've seen the documentation Microsoft has in
their best practices section. That stuff is good, but
|
by: dotNetDave |
last post by:
About three weeks ago I released the first .NET coding standards book titled
"VSDN Tips & Tricks .NET Coding Standards". Here is what the famous author/
speaker Deborah Kurata says about it:
"David McCarter once again demonstrates his knack for pulling best practices
into one cohesive unit with his new book "VSDN Tips and Tricks: .NET Coding
Standards". This book includes everything from how to set up your project to
how to declare...
|
by: Natt Serrasalmus |
last post by:
After years of operating without any coding standards whatsoever, the
company that I recently started working for has decided that it might be a
good idea to have some. I'm involved in this initiative.
Typically I find that coding standards are written by some guy in the
company who has a way of coding that he likes and then tries to force
everybody else to write code the way he likes it, not for any rational
reason, but simply for the...
|
by: Ren |
last post by:
Hi All,
I'm still rather new at vb.net and would like to know the proper way to access
private varibables in a class. Do I access the variable directly or do I use
the public property?
public class MyClass
private _variableName as integer
public property VariableName as integer
| |
by: Konrad Palczynski |
last post by:
I am looking for tool to validate conformity to defined coding standard.
I have already found Parasoft's C++ Test, but it is quite expensive. Is
there any Open Source alternative? I do not need GUI, fancy reports nor
predefined sets of rules.
|
by: Robert Seacord |
last post by:
The CERT/CC has just deployed a new web site dedicated to developing
secure coding standards for the C programming language, C++, and
eventually other programming language.
We have already developed significant content for the C programming
language that is available at:
https://www.securecoding.cert.org/
by clicking on the "CERT C Programming Language Secure Coding Standard"
|
by: pat |
last post by:
Abraxas Software
Understanding YOUR GOALS & Using CodeCheck Implementing Corporate
Source Code Guidelines C/C++ Source Code GuideLine Automation
The goals of CodeCheck are:
1 To create a standard which will enable you to provide the customer
with a quality product in a timely manner. 2 To promote standardization
of software development among programmers. 3 To act as a learning tool
for new programmers. 4 To act as a reference tool for...
|
by: auratius |
last post by:
http://www.auratius.co.za/CSharpCodingStandards.html
Complete CSharp Coding Standards
1. Naming Conventions and Styles
2. Coding Practices
3. Project Settings and Project Structure
4. Framework-Specific Guidelines
Naming Conventions and Styles
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| | |