473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Relative prevalence of "good" C++

In your experience, what is the prevalence of "good" C++ (i.e., the
code makes full use of solid language features and the STL) versus C++
written in ignorance (or defiance) of one or more key features of the
language?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jan 18 '06 #1
9 2251
Christopher Benson-Manica wrote:
In your experience, what is the prevalence of "good" C++ (i.e., the
code makes full use of solid language features and the STL) versus C++
written in ignorance (or defiance) of one or more key features of the
language?


5%.

And worshiping STL ain't the point. You can go overboard too. Just writing
clean flexible code that doesn't crash and is easy to upgrade is very hard,
yet possibly worthwhile.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Jan 18 '06 #2
Some point that come to my mind:

- consistent naming rules (variables, methods, classes) for your code
- using references instead of pointers (if possible) makes your code
saver
- use const for variables, method parameters and, method return values
if this is the nature of the function
- find an elegant class model for your problem (clean encapsulation).

but there are surely more points...

In general:

For my part, I try to write CONSISTENT code. That means: If I have the
same/similar problem I try to use the same/similar solution. That
really helps to make your code more robust (It works there, so it will
work here. Found a logic error there, so I have to fix it here too),
maybe you can even share code (base class), and it's easier to
understand the code for another person.

--

Henryk

Jan 18 '06 #3

"Christopher Benson-Manica" <at***@ukato.freeshell.org> wrote in message
news:dq**********@chessie.cirr.com...
In your experience, what is the prevalence of "good" C++ (i.e., the
code makes full use of solid language features and the STL) versus C++
written in ignorance (or defiance) of one or more key features of the
language?

--


Rule: All programmers write perfect code. All other programmers write
crap.
(-From an unknown source. Not me, though, so it must be crap.)
Jan 18 '06 #4

Christopher Benson-Manica wrote:
In your experience, what is the prevalence of "good" C++ (i.e., the
code makes full use of solid language features and the STL) versus C++
written in ignorance (or defiance) of one or more key features of the
language?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.


It's shocking. People are writing this in their code:

class Foo
{
private:
typedef std::vector< Bar > BarVect;
BarVect bars;

public:
void func1( const Bar & bar );

void func2();
};

void Foo::func2()
{
BarVect::const_iterator iter = bars.begin(), itEnd=bars.end();

for ( ; iter != itEnd; ++iter )
{
func1( *iter );
}
}

I mean, look! they use a for-loop instead of some convoluted binder!
(or writing a functor class to solve it)

Jan 18 '06 #5
I can answer this question as soon as you define what it means to be
"good", and as soon as you define what it means to be a "key feature".

E.g., the following is perfectly good C++ in my book, although you'd
probably call it "ignorant" or "defiant":

=====
#include <cstdio>

int main()
{
printf("Hello, World!\n");
return 0;
}

=====

C++ is a huge language with tons of different ways to skin cats. There
are usually many perfectly reasonable ways to flay any given feline.
The ultimate measure of reasonableness is the reliability of the code,
how well the code addresses the problem it's supposed to solve, and how
easy it is for successors to maintain.

Jan 18 '06 #6
Robert J. Hansen wrote:
I can answer this question as soon as you define what it means to be
"good", and as soon as you define what it means to be a "key feature".

E.g., the following is perfectly good C++ in my book, although you'd
probably call it "ignorant" or "defiant":

=====
#include <cstdio>

int main()
{
printf("Hello, World!\n");
return 0;
}

Not in mine, it won't compile - should be std::printf.

--
Ian Collins.
Jan 18 '06 #7
Robert J. Hansen <ci********@gmail.com> wrote:
E.g., the following is perfectly good C++ in my book, although you'd
probably call it "ignorant" or "defiant":
There's nothing wrong with that, but I would suggest that C++ code
that takes great pains to duplicate functionality provided by the STL
certainly qualifies as "ignorant" or "defiant", possibly both. Surely
there is something left to be desired in code that cries out for, say,
std::map but is prevented from making use of it by the use of
nonstandard language extensions.
The ultimate measure of reasonableness is the reliability of the code,
how well the code addresses the problem it's supposed to solve, and how
easy it is for successors to maintain.


I also suggest that C++ that uses a static array of, say, 600 structs
and then complains when one wants space for 601 does a poor job of
solving a problem that a std::vector would in all probability be far
better suited for.

I really thought this would be an easy question, but apparently
gratuitously bad C++ would seem to be the exception.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jan 19 '06 #8
>I also suggest that C++ that uses a static array of, say, 600 structs
and then complains when one wants space for 601 does a poor job of
solving a problem that a std::vector would in all probability be far
better suited for.
That would be indeed perverse. But what about the (I assume) ironical
comment earlier?
I mean, look! they use a for-loop instead of some convoluted binder!
(or writing a functor class to solve it)


C++ is not a true functional language with proper anonymous closures,
so something simple like calling a method for all objects in a
collection can get nasty if one insisted on for_each. So a lot of
people prefer to use explicit loops where they are clearer, and generic
algorithms when they make sense (e.g. std::copy). Now would we call
such people old-fashioned people best left behind by the march of
progress? I think not.

steve d.

Jan 19 '06 #9
st*************@gmail.com wrote:
That would be indeed perverse. But what about the (I assume) ironical
comment earlier?


Which one? (They weren't intended to be rhetorical.)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jan 21 '06 #10

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

Similar topics

6
by: Hostile17 | last post by:
What's considered to be the definitive version of a "good font settings" style sheet? That is, one which allows nearly all modern browsers, and Netscape 4, to get readable text. The basis of...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
2
by: lagunasun | last post by:
I am going from learning c++ console apps to windows, and need a good book. I prefer the non techical approach with some humor (if possible). I would like the book to assume the reader has NO...
4
by: Petterson Mikael | last post by:
Hi, We are today into RoseRT. We are not very satisfied with the environment ( speed, control and complexity). Today RoseRt generates about 40-60% of the code. Q1: Is it possible to move to...
0
by: André | last post by:
I'm trying to change an app so that it uses gettext for translations rather than the idiosyncratic way I am using. I've tried the example on the wxPython wiki...
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
48
by: Tony | last post by:
How much bloat does the STL produce? Is it a good design wrt code bloat? Do implementations vary much? Tony
8
by: Zytan | last post by:
In VB, you use ControlChars.CrLf (or better, ControlChars.NewLine). In C/C++, we are used to using merely "\n" (or at least I am). It appears "\n" is good enough for RichTextBoxes. Does it...
1
by: Tyno Gendo | last post by:
Hi everyone I need to move on a step in my PHP... I know what classes are, both in PHP4 and 5 and I'm aware of "patterns" existing, but what I'm looking for are some real world projects eg....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.