Coming back to C++...

J

Joe Van Dyk

I've been using Ruby for the past couple years. But fate has decided that
I return to C++ for the time being.

Unfortunately, I've forgotten a lot of C++. So, here's my training
regime. I need to get up to speed on C++, networking, threads, XML (and
hopefully unit testing -- never done automated tests with C++).

- Accelerated C++
- Programming with POSIX Threads
- C++ Coding Standards
- Effective C++ (3rd ed)
- Exceptional C++ Style
- Exceptional C++
- More Exceptional C++

Probably in that order. That look ok?

Any pointers or tips? I've been spoiled by Ruby for some time now, so C++
(initially) is sort of making me cry. I've been enjoying dynamic / duck
typing!

Thanks,
Joe
 
P

Phlip

Joe said:
I've been using Ruby for the past couple years. But fate has decided that
I return to C++ for the time being.

Unfortunately, I've forgotten a lot of C++. So, here's my training
regime. I need to get up to speed on C++, networking, threads, XML (and
hopefully unit testing -- never done automated tests with C++).

- Accelerated C++
- Programming with POSIX Threads
- C++ Coding Standards
- Effective C++ (3rd ed)
- Exceptional C++ Style
- Exceptional C++
- More Exceptional C++

Probably in that order. That look ok?

Essential C++ by Lipmann?
Modern C++ Design by Alexanzdrieuoeusceieou.. that guy?
C++ Template Metaprogramming by that boost guy?
C++ Common Knowledge by Dewhurst?
Standard C++ IOStreams and Locales by Langer & Kreft?

something about the STL?

Start with Accelerated C++ and C++ Coding Standards, then pull the others in
one by one. Don't just whip out the plastic and hit Amazon for all of them.
Any pointers or tips? I've been spoiled by Ruby for some time now, so C++
(initially) is sort of making me cry. I've been enjoying dynamic / duck
typing!

Learn CppUnit, and then use CppUnitLite. The former painstakingly matches
all the JUnit features (themselves ported from SUnit), and the latter
starts with the minimum needed to efficiently do TDD under C++ using C++
idioms.

Then add:

Large Scale C++ Software Design
Design Patterns
Test Driven Development
Refactoring
Refactoring to Patterns

And leave out threads; a clean architecture is better.
 
A

Aleksander Beluga

Hello Joe,
I've been using Ruby for the past couple years. But fate has decided
that I return to C++ for the time being.

Unfortunately, I've forgotten a lot of C++. So, here's my training
regime. I need to get up to speed on C++, networking, threads, XML
(and hopefully unit testing -- never done automated tests with C++).
- The C++ Language
- Programming with POSIX Threads
- C++ Coding Standards
- Effective C++ (3rd ed) - Effective STL
- Exceptional C++ Style
- Exceptional C++
- More Exceptional C++ - Modern C++
Probably in that order. That look ok?

I revised your list with my recommendations.
Digitally yours, Aleksander Beluga
 
J

Joe Van Dyk

Essential C++ by Lipmann?
Modern C++ Design by Alexanzdrieuoeusceieou.. that guy?
C++ Template Metaprogramming by that boost guy?
C++ Common Knowledge by Dewhurst?
Standard C++ IOStreams and Locales by Langer & Kreft?

something about the STL?

Start with Accelerated C++ and C++ Coding Standards, then pull the others in
one by one. Don't just whip out the plastic and hit Amazon for all of them.

Luckily, work pays for these. And since there's a fairly significant
delay from when I place my order to when I get the books, I've found it's
a good idea to place a large order up front.
Learn CppUnit, and then use CppUnitLite. The former painstakingly
matches all the JUnit features (themselves ported from SUnit), and the
latter starts with the minimum needed to efficiently do TDD under C++
using C++ idioms.

Thanks! Not Boost::Test? One of the tricky things I've found is
evaluating the multitude of libraries that exist for C++.
Then add:

Large Scale C++ Software Design
Design Patterns
Test Driven Development
Refactoring
Refactoring to Patterns

And leave out threads; a clean architecture is better.

I'm doing a significant amount of GUI work that do a lot of processing
an updating behind the scenes, so using threads is sort of necessary
(AFAIK, but then again, I'm not terribly smart).

Thank you, everyone!
Joe
 
J

John Carson

Joe Van Dyk said:
I've been using Ruby for the past couple years. But fate has decided
that I return to C++ for the time being.

Unfortunately, I've forgotten a lot of C++. So, here's my training
regime. I need to get up to speed on C++, networking, threads, XML
(and hopefully unit testing -- never done automated tests with C++).

- Accelerated C++
- Programming with POSIX Threads
- C++ Coding Standards
- Effective C++ (3rd ed)
- Exceptional C++ Style
- Exceptional C++
- More Exceptional C++

Probably in that order. That look ok?

Any pointers or tips? I've been spoiled by Ruby for some time now,
so C++ (initially) is sort of making me cry. I've been enjoying
dynamic / duck typing!

Thanks,
Joe

I second Gavin Deane's suggestion. You *have* to get The C++ Standard
Library by
Nicolai Josuttis.

If you want to take the next step with templates, then David Vandevoorde &
Nicolai Josuttis, C++ Templates: The Complete Guide is highly recommended.
 
P

Phlip

Joe said:
I'm doing a significant amount of GUI work

I'm writing up something about GUIs for TDD these days. I mean TDD for GUIs.

http://www.zeroplayer.com/cgi-bin/wiki?TestFirstUserInterfaces
that do a lot of processing
an updating behind the scenes, so using threads is sort of necessary
(AFAIK, but then again, I'm not terribly smart).

The best architectures are fully event driven, so threading is less
critical.

Don't thread because "this function takes too long and I want to do
something else at the same time". GUIs can easily pump event-driven routines
from a window timer.
 
J

Joe Hotchkiss

Joe Van Dyk said:
I've been using Ruby for the past couple years. But fate has decided that
I return to C++ for the time being.

Unfortunately, I've forgotten a lot of C++. So, here's my training
regime. I need to get up to speed on C++, networking, threads, XML (and
hopefully unit testing -- never done automated tests with C++).

- Accelerated C++
- Programming with POSIX Threads
- C++ Coding Standards
- Effective C++ (3rd ed)
- Exceptional C++ Style
- Exceptional C++
- More Exceptional C++

Probably in that order. That look ok?

Don't forget a copy of the language standards.

INCITS/ISO/IEC 14882-2003, "Programming languages - C++"
http://webstore.ansi.org/ansidocstore/product.asp?sku=INCITS/ISO/IEC+148
82-2003

This references the C libraries, so you may also want
INCITS/ISO/IEC 9899-1999, "Programming Languages - C"
http://webstore.ansi.org/ansidocstore/product.asp?sku=INCITS/ISO/IEC+989
9-1999

$30 each.
Unreadable for learning C++, but an essential reference afterwards.

I'll add my recommendation for "The C++ Standard Library" by Josuttis to
the others.

My feeling on "Modern C++ Design" by Alexandrescu was that it should
have been subtitled "How to abuse templates". Maybe if I'd had a
compiler that could cope with it when I read it (VC++6 doesn't) I would
have felt differently, but the whole template meta-programming thing
seems to me a step too far. Maybe I ought to re-read it now, but I have
too big a stack to work through as it is.


Also look at the reviews on both Amazon and the "Book Reviews" section
of http://www.accu.org.

--
Regards,

Joe Hotchkiss,
http://joe.hotchkiss.com
http://harrowsubaqua.org.uk

XXXXXXXXXXXXXXXXXXXXXXXXX
X joe.hotchkiss X
X at selex-sas.com X
XXXXXXXXXXXXXXXXXXXXXXXXX
 
J

Joe Van Dyk

I'm writing up something about GUIs for TDD these days. I mean TDD for GUIs.

http://www.zeroplayer.com/cgi-bin/wiki?TestFirstUserInterfaces

Holy crap, that's a gold mine. I thought I read something about you
writing a book like this using Ruby/Tk for most of the examples.

When that book is ready, I'll definitely buy it.
The best architectures are fully event driven, so threading is less
critical.

Don't thread because "this function takes too long and I want to do
something else at the same time". GUIs can easily pump event-driven
routines from a window timer.

I guess this gets OT now, but can you explain more here? (or, if it's
covered in your book, just say so) Is
http://ruby-gnome2.sourceforge.jp/hiki.cgi?cmd=view&p=Gtk#Gtk.timeout_add
an example of a "window timer"?
 
P

Phlip

Joe said:
Holy crap, that's a gold mine.

I'l inform my editor(s) that someone, somewhere, thinks that... ;-)
I guess this gets OT now, but can you explain more here? (or, if it's
covered in your book, just say so) Is
http://ruby-gnome2.sourceforge.jp/hiki.cgi?cmd=view&p=Gtk#Gtk.timeout_add
an example of a "window timer"?

Healthy threads may drift in and out of topicality. The difference is we
know the difference. Here's the verbiage around progress bars. They are
symbolic of all asynchronous GUI issues:

During a long process, users need more than assurance the program did not
hang. They need to know how long a process will take, so they can schedule a
break, lunch, or a vacation. And they need the option to cancel progress
without deleting your program from their task list.

Progress bars' lowly status, as event-driven supplements to procedural
features (often added late, after those features work), exposes them to some
common AntiPatterns. Don't:

* raise a separate dialog box just to display the progress bar
* put the logical procedure into a separate thread
* write a loop statement in the GUI thread to
spin until the procedure advances
* guess or fudge the number of ticks to progress-count them
* convert the mouse pointer to an hourglass if clicking still works
* block the event queue, disabling clicking and the Paint() event
* display a cancel button that does nothing.

Most of those admonitions have common exceptions. Some procedures by nature
are not interruptible. Some, such as Web browsers, communicate with distant
unreliable servers, and cannot predict the number of ticks a progress bar
will consume.

Here's a naïve WTL implementation of a progress bar:

LRESULT
ProjectDlg::OnSlowOperation(WORD, WORD, HWND, BOOL &)
{
CListBox aList = GetDlgItem(IDC_LIST_CUSTOMERS);
int count(aList.GetCount());

CProgressBarCtrl aBar = GetDlgItem(IDC_PROGRESS);
aBar.SetRange(0, count);
aBar.SetPos(0);

for (int x(0); x < count; ++x)
{
Sleep(25);
aBar.SetPos(x);
}

return 0;
}

The function Sleep(25) simulates some Logic Layer function that slowly
processes one record.

That design is not good enough yet, but it could be worse. The design could
call aBar.SetPos(x) from somewhere deep inside the function that Sleep(25)
represents. That would couple the Logic Layer to a GUI Layer identifier,
aBar. This design decouples a little, but tests will soon force it to
decouple more.

This test forces the IDC_SLOW_OPERATION button to start a timer:

TEST_(TestDialog, SetTimer)
{
CButton slowButton = m_aDlg.GetDlgItem(IDC_SLOW_OPERATION);
slowButton.SendMessage(BM_CLICK);
BOOL thereWasaTimerToKill = m_aDlg.KillTimer(0);
CPPUNIT_ASSERT(thereWasaTimerToKill);
}

The test detects the timer by successfully killing it. (Future refactors
should replace the "Magic Number" 0 with a named constant.)

This code sets the timer, and moves the loop index into ProjectDlg's member
list. A third data member, for a dialog with so many features, is a small
price to pay for event queue freedom:

class
ProjectDlg:
public CDialogImpl<ProjectDlg>
{
.....
BEGIN_MSG_MAP(ProjectDlg)
.....
COMMAND_ID_HANDLER(IDC_SLOW_OPERATION, OnSlowOperation)
MESSAGE_HANDLER(WM_TIMER, OnTimer)
END_MSG_MAP()

LRESULT OnTimer(UINT, WPARAM, LPARAM, BOOL &);

ProjectDlg(char const *xml):
m_aCA(xml),
m_index(0)
{}
.....
private:
CustomerAddress m_aCA;
CString m_fileName;
int m_index;
};

OnSlowOperation() will now work by checking if m_index is at the beginning
or end of its progress. When no slow operation is under way the method
starts it, otherwise it stops it.
 
J

Joe Van Dyk

I'l inform my editor(s) that someone, somewhere, thinks that... ;-)

Any ideas on a publication date? Need reviewers?
Healthy threads may drift in and out of topicality. The difference is we
know the difference. Here's the verbiage around progress bars. They are
symbolic of all asynchronous GUI issues:

During a long process, users need more than assurance the program did not
hang. They need to know how long a process will take, so they can schedule a
break, lunch, or a vacation. And they need the option to cancel progress
without deleting your program from their task list.

Progress bars' lowly status, as event-driven supplements to procedural
features (often added late, after those features work), exposes them to some
common AntiPatterns. Don't:

* raise a separate dialog box just to display the progress bar
* put the logical procedure into a separate thread
* write a loop statement in the GUI thread to
spin until the procedure advances
* guess or fudge the number of ticks to progress-count them
* convert the mouse pointer to an hourglass if clicking still works
* block the event queue, disabling clicking and the Paint() event
* display a cancel button that does nothing.

Most of those admonitions have common exceptions. Some procedures by nature
are not interruptible. Some, such as Web browsers, communicate with distant
unreliable servers, and cannot predict the number of ticks a progress bar
will consume.

Here's a naïve WTL implementation of a progress bar:

LRESULT
ProjectDlg::OnSlowOperation(WORD, WORD, HWND, BOOL &)
{
CListBox aList = GetDlgItem(IDC_LIST_CUSTOMERS);
int count(aList.GetCount());

CProgressBarCtrl aBar = GetDlgItem(IDC_PROGRESS);
aBar.SetRange(0, count);
aBar.SetPos(0);

for (int x(0); x < count; ++x)
{
Sleep(25);
aBar.SetPos(x);
}

return 0;
}

The function Sleep(25) simulates some Logic Layer function that slowly
processes one record.

That design is not good enough yet, but it could be worse. The design could
call aBar.SetPos(x) from somewhere deep inside the function that Sleep(25)
represents. That would couple the Logic Layer to a GUI Layer identifier,
aBar. This design decouples a little, but tests will soon force it to
decouple more.

This test forces the IDC_SLOW_OPERATION button to start a timer:

TEST_(TestDialog, SetTimer)
{
CButton slowButton = m_aDlg.GetDlgItem(IDC_SLOW_OPERATION);
slowButton.SendMessage(BM_CLICK);
BOOL thereWasaTimerToKill = m_aDlg.KillTimer(0);
CPPUNIT_ASSERT(thereWasaTimerToKill);
}

The test detects the timer by successfully killing it. (Future refactors
should replace the "Magic Number" 0 with a named constant.)

This code sets the timer, and moves the loop index into ProjectDlg's member
list. A third data member, for a dialog with so many features, is a small
price to pay for event queue freedom:

class
ProjectDlg:
public CDialogImpl<ProjectDlg>
{
....
BEGIN_MSG_MAP(ProjectDlg)
....
COMMAND_ID_HANDLER(IDC_SLOW_OPERATION, OnSlowOperation)
MESSAGE_HANDLER(WM_TIMER, OnTimer)
END_MSG_MAP()

LRESULT OnTimer(UINT, WPARAM, LPARAM, BOOL &);

ProjectDlg(char const *xml):
m_aCA(xml),
m_index(0)
{}
....
private:
CustomerAddress m_aCA;
CString m_fileName;
int m_index;
};

OnSlowOperation() will now work by checking if m_index is at the beginning
or end of its progress. When no slow operation is under way the method
starts it, otherwise it stops it.

Thanks for the info. My question was not so much about how to do a long
process that the user starts, but rather, how to constantly get and
process data from an external source and update the GUI, while leaving the
GUI responsive.

In my case, I've got hundred of entities that need to have their
attributes updated a few times a second, and preferably as fast as
possible without sucking up too much CPU. These entities are represented
in the GUI and need to move, change shape, color, etc whenever the
entity's information is updated. I kind of figured a thread would be best
for that. The GUI doesn't directly change any entities, so I figured it's
fairly easy to do threading.

I've got some more questions on TDD a GUI. Where's a good place to ask
those questions?

Joe
 
M

marcwentink

That looks ok?

No! To me at looks a bit too much. Although knowledge of a language is
good, and all the named books are excellent, I doubt if you really have
know them all by heart to get the future job done? Especially if you
already got C++ experience.
 
T

tragomaskhalos

For processing XML using C++ you can try "C++ XML" by Arciniegas. There
are a few glitches in the text but it comes with a CD chock full of
goodies.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top