elfs: (Default)
[personal profile] elfs
How To Use C++
  • Real Men use class heirarchies.
  • Real Programmers use templates and generics.
  • Loonies write the entire program as a cpp macro expansion
  • Munchkins use Microsoft wizards and Visual Basic

Date: 2010-11-12 07:01 pm (UTC)
From: [identity profile] urox.livejournal.com
What's your preferred debugger for C++?

Date: 2010-11-12 07:03 pm (UTC)
From: [identity profile] elfs.livejournal.com
GDB. If I have X, DDD as a front-end to GDB.

Date: 2010-11-14 10:33 pm (UTC)
From: [identity profile] http://users.livejournal.com/_candide_/
Hah! My frontend for GDB is Emacs. ^_^

Date: 2010-11-12 08:04 pm (UTC)
From: [identity profile] caprine.livejournal.com
...I spray tea on my monitor and fall out of my chair. And I don't even know enough about programming to get this on a deep level; I just know the Four Types of Gamers.

Date: 2010-11-12 08:19 pm (UTC)
From: [identity profile] elfs.livejournal.com
My work here is done!

Date: 2010-11-13 04:53 pm (UTC)
From: [identity profile] srmalloy.livejournal.com
I am reminded of the submission to the Obfuscated C contest some years ago which was a fairly short program that would compile and run as a C program, as a FORTRAN program, as a Perl script, and in csh. That's more what I expect from Loonies.

Date: 2010-11-14 10:49 pm (UTC)
From: [identity profile] http://users.livejournal.com/_candide_/
(C++) Template Metaprogramming, when used appropriately, is absolutely vital. Trying to achieve the same result without them (even if you have Java/C# Generics) requires copious amounts of copy+paste+edit.

[Oh … turns out that there's an easy solution to the "template code-bloat problem". Say you normally have "TClass.h" and "TClass.tcc", the header and definition of a class called [duh] TClass. Here's what you do:

(A) Move "TClass.tcc" into a "details" subdirectory.

(B) Create a "TClass.cc" file, containing a forward declaration for every template-instantiation you intend to support. It should [obviously] '#include "details/TClass.tcc"'.

(C) Optionally create a "TClass_fwd.h" header that creates typedefs for your supported template-instantiations of TClass.

(D) Link any binary or library that uses one of those supported template-instantiations with "TClass.o".

I use this technique all of the time. Works like a charm.]

Date: 2010-11-15 12:31 am (UTC)
From: [identity profile] elfs.livejournal.com
That reads like a case of Design Patterns Are Missing Language Features (http://www.c2.com/cgi/wiki?AreDesignPatternsMissingLanguageFeatures).

Date: 2010-11-15 04:57 pm (UTC)
From: [identity profile] http://users.livejournal.com/_candide_/
Yep, I've heard that one before. I agree with it, too. But what I've described regarding C++ Templates isn't so much a missing language feature as a hidden one, paired with stylistics.

Current C++ language style recommends putting the implementation of template (member) functions in a file named *.tcc. Another style recommendation is putting headers and *.tcc files that Have No User-Servicable Parts in a subdirectory named "details" (and, often, in a sub-namespace called "details", as well).

As for the hidden feature: Once you instantiate a C++ template class, it has external linkage. Template functions have external linkage if they're namespace members. Therefore, you only need to instantiate the template once, in one translation unit, then link to that translation unit to your heart's content. Just like for a non-template C++ class.

Date: 2010-11-15 03:04 pm (UTC)
From: [identity profile] shockwave77598.livejournal.com
Real men use straight C and their products run on the user interface WTHIAOS.

What the heck is an operating system?

:)

Profile

elfs: (Default)
Elf Sternberg

December 2025

S M T W T F S
 12345 6
78910111213
14151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 9th, 2026 08:02 am
Powered by Dreamwidth Studios