Formatting in C++ (fwd)

Tim Writer tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Tue Dec 30 16:17:17 UTC 2003


John Wildberger <wildberger-iRg7kjdsKiH3fQ9qLvQP4Q at public.gmane.org> writes:

> On December 29, 2003 01:37 pm, Tim Writer wrote:
> 
> > By now, you should be convinced that porting the original program from C to
> > C++ yielded no benefits whatsoever at the cost of additional complexity,
> > portability problems, and clumsiness.  Note, I'm not saying that's true for
> > every program but this particular program was not a good candidate.
> 
> I think you are missing a point here. I t was never my intention to port the 
> program from c to c++ for the purpose of improving the program. It was solely 
> a learning experience and as such it served its purpose very well. I learned 
> how to apply C99 standards and after some struggling I even managed to use 
> the proper formatting tools in C++.

And hopefully you learned that this type of program isn't a good candidate
for translation to C++. :-)

> The program itself is rather useless and can now be discarded.

Yep.

> C++ is not the preferred programming language for most Linux aficionados.

Agreed, although it's an important one for Linux as KDE is written in C++.

> They prefere standard C instead. The kernel does not have a single part
> written in C++.  However, there is a lot of potential in C++, and anyone
> interested to write programs for his/hers use will find it very useful and
> powerful. To reap the full benefit it is necessary to get familiar with its
> syntax and structure.

Yes, but it's important to choose examples that benefit from C++; otherwise,
you'll just get frustrated.  Afterall, the syntax is mostly compatible with C
and you only break new ground when you get into features like classes and
templates.  You won't learn a lot from a more or less mechanical translation
of a procedural C program to C++. Of course, as a new C++ user, you might not
yet be aware of the kinds of programs which benefit from C++.

> Extra complexity is introduced for portability reason.

Unfortunately, C++ has not lived up to its promise of portability.  The
language is so complex that few environments implement the same subset and
its often difficult to move a C++ program from one compiler to another on the
same platform, let alone from one platform to another.

> If you should not care for portability you can make things a lot
> simpler. e.g use the simple types like int, char, float etc instead of the
> C99 types.

The C99 types exist to assist with portability.  Clearly, programmers should
avoid dealing with exact size types but some programs, such as your example,
require them.  Using "int16_t" when you need a 16 bit quantity is much more
portable than using "short" and assuming its 16 bits.  If you're worried a
given platform won't have the C99 headers, you can always include a copy with
your source code (with appropriate #ifdefs etc. to handle different
platforms).

> But as always, it is good to know the later forms, so that you can at least
> read programs written by other people.

Agreed.  Unfortunately, C++ is so large and has changed so much since its
inception many people use more or less disjoint subsets.

If you're learning C++ for fun, consider another language instead, unless
perhaps you're planning to do some KDE development.  C++ can be incredibly
frustrating; I know from bitter experience.  If you don't already know them,
learning a language like Perl, Python, Ruby, Lisp, or Scheme will be a lot
more fun.

-- 
tim writer <tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org>                                  starnix inc.
905.771.0017 ext. 225                           thornhill, ontario, canada
http://www.starnix.com              professional linux services & products
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list