Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The newbie struggles with C++

85 views
Skip to first unread message

bitrex

unread,
Mar 22, 2017, 11:47:32 PM3/22/17
to
My main struggle with learning C++1x coming from languages like straight
C and Python is that I might have what I think is a good idea for a
particular software design, but then while attempting to implement it I
find myself bogged down for an afternoon in Stack Overflow posts about
the particulars of performance issues in the "copy and swap" idiom and
blog debates about whether the constructor of a superclass should be
inherited this way or that and I look at my code and ask myself "Um,
will any of this stuff I just did perform well in practice or even
idiomatic or 'correct' in any way at all?

Alf P. Steinbach

unread,
Mar 23, 2017, 12:27:14 AM3/23/17
to
How about just ask about one particular concrete problem, with code
(that is complete enough that) that readers can try?

Stack Overflow can be a good place to ask about some definite-answer
question, but for the more vague stuff, where you'd like some back and
forth discussion, try this group or e.g. a Reddit or Facebook group.

Keep in mind that C++ started as nothing more than /language support/
for certain idiomatic ways to use C. As I recall Bjarne was implementing
simulations with queues, so he needed classes. Oh, yes there's Simula,
that silly verbose Norwegian programming language, it fits this problem
domain, I'll just implement the Simula stuff in C. Oh gosh (whatever,
some exclamation) even with my crafty macros that's a heck of a lot of
boilerplate code, not to mention the casts, repeated all over the place!
I'd better make my own C extension to deal with all of that, grumble...,
let's call it, say, “C with classes”, yes... to work!


Cheers!,

- Alf

Bo Persson

unread,
Mar 23, 2017, 5:37:08 AM3/23/17
to
Start with the 'correct' part. If the program doesn't do what it is
supposed to, it doesn't matter how fast it is.

And most parts of a program (97%?) are not important performance-wise.
Like if you create an object once in a program, how fast does the
constructor need to be?

Just wait until you see that some parts are not fast enough, and then
look for possible optimizations there. And only there.

Remember:

"Premature optimization is the root of all evil" (Donald Knuth)

https://en.wikiquote.org/wiki/Donald_Knuth#Quotes_about_Donald_Knuth



Bo Persson

woodb...@gmail.com

unread,
Mar 23, 2017, 1:15:20 PM3/23/17
to
On Wednesday, March 22, 2017 at 11:27:14 PM UTC-5, Alf P. Steinbach wrote:
> On 23-Mar-17 4:47 AM, bitrex wrote:
> > My main struggle with learning C++1x coming from languages like straight
> > C and Python is that I might have what I think is a good idea for a
> > particular software design, but then while attempting to implement it I
> > find myself bogged down for an afternoon in Stack Overflow posts about
> > the particulars of performance issues in the "copy and swap" idiom and
> > blog debates about whether the constructor of a superclass should be
> > inherited this way or that and I look at my code and ask myself "Um,
> > will any of this stuff I just did perform well in practice or even
> > idiomatic or 'correct' in any way at all?

Welcome to the jungle. Welcome to the desert jungle.
And then pray for rain. Cause if it doesn't rain, your
work will go down the drain.


> >
>
> How about just ask about one particular concrete problem, with code
> (that is complete enough that) that readers can try?
>
> Stack Overflow can be a good place to ask about some definite-answer
> question, but for the more vague stuff, where you'd like some back and
> forth discussion, try this group or e.g. a Reddit or Facebook group.
>
> Keep in mind that C++ started as nothing more than /language support/
> for certain idiomatic ways to use C. As I recall Bjarne was implementing
> simulations with queues, so he needed classes. Oh, yes there's Simula,
> that silly verbose Norwegian programming language, it fits this problem
> domain, I'll just implement the Simula stuff in C. Oh gosh (whatever,
> some exclamation) even with my crafty macros that's a heck of a lot of
> boilerplate code, not to mention the casts, repeated all over the place!
> I'd better make my own C extension to deal with all of that, grumble...,
> let's call it, say, “C with classes”, yes... to work!
>

I think I've taken a similar approach.



Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net

bitrex

unread,
Mar 23, 2017, 1:38:54 PM3/23/17
to
Got it. I've been using Code::Blocks on Linux, the current version comes
with Valgrind already plugged-in, are there any recommended profiling
tools for that setup?

Jorgen Grahn

unread,
Apr 4, 2017, 2:14:08 PM4/4/17
to
On Thu, 2017-03-23, bitrex wrote:
> On 03/23/2017 05:36 AM, Bo Persson wrote:
>> On 2017-03-23 04:47, bitrex wrote:
>>> My main struggle with learning C++1x coming from languages like straight
>>> C and Python is that I might have what I think is a good idea for a
>>> particular software design, but then while attempting to implement it I
>>> find myself bogged down for an afternoon in Stack Overflow posts about
>>> the particulars of performance issues in the "copy and swap" idiom and
>>> blog debates about whether the constructor of a superclass should be
>>> inherited this way or that and I look at my code and ask myself "Um,
>>> will any of this stuff I just did perform well in practice or even
>>> idiomatic or 'correct' in any way at all?
>>>
>>
>> Start with the 'correct' part. If the program doesn't do what it is
>> supposed to, it doesn't matter how fast it is.
>>
>> And most parts of a program (97%?) are not important performance-wise.
>> Like if you create an object once in a program, how fast does the
>> constructor need to be?
>>
>> Just wait until you see that some parts are not fast enough, and then
>> look for possible optimizations there. And only there.
>>
>> Remember:
>>
>> "Premature optimization is the root of all evil" (Donald Knuth)
>>
>> https://en.wikiquote.org/wiki/Donald_Knuth#Quotes_about_Donald_Knuth
>
> Got it. I've been using Code::Blocks on Linux, the current version comes
> with Valgrind already plugged-in, are there any recommended profiling
> tools for that setup?

If you need tools to detect that your code isn't fast enough, chances are
that it /is/ fast enough, after all ;-)

I got the impression from your first posting that performance wasn't
your focus. And IMHO, it shouldn't be.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Robert Wessel

unread,
Apr 4, 2017, 5:43:27 PM4/4/17
to
On 4 Apr 2017 18:14:00 GMT, Jorgen Grahn <grahn...@snipabacken.se>
wrote:
That's not really fair. Using a profiler, or some other tool, to
measure where the bottlenecks in your program are is an excellent way
to proceed once you've determined that the code is, in fact, too
slow. While it would normally be silly to use a profiler to *detect*
bad performance, using one to *locate* it is a much better idea that
the near-random guessing technique preferred by most programmers.

Jorgen Grahn

unread,
Apr 5, 2017, 1:37:08 AM4/5/17
to
I'm pretty sure good old gprof(1) will work. time(1), strace(1) and
Valgrind may also be of use for this. Linux perf(1), too.

And you need a way to run your program with realistic inputs so it
runs into situations where it /might/ be too slow or resource-hungry.

>>If you need tools to detect that your code isn't fast enough, chances are
>>that it /is/ fast enough, after all ;-)
>
> That's not really fair. Using a profiler, or some other tool, to
> measure where the bottlenecks in your program are is an excellent way
> to proceed once you've determined that the code is, in fact, too
> slow. While it would normally be silly to use a profiler to *detect*
> bad performance, using one to *locate* it is a much better idea that
> the near-random guessing technique preferred by most programmers.

You're right, of course. But bitrex didn't seem to have any actual
problems with his code being too slow.

I obsess too much about micro-performance myself, and he was (it
seemed to me) about to make the same mistake.

(It's fair to let him know, though, that when he /does/ need profiling
tools, they /are/ available. I should have done that in my first
posting.)
0 new messages