How to avoid using arrays for strings???

B

Bob Masta

On Fri, 16 Nov 2007 19:00:19 +0000, Richard Heathfield
Please bear in mind that this thread is cross-posted, and I'm reading it in
comp.os.ms-windows.programmer.win32, where arrays are very much a part of
ordinary programming practice, not some kind of anathema to be shunned at
all costs.

I'm also reading from the Win32 group, and am not a C or C++
programmer. So can somebody explain the supposed evils of string
arrays? I know that languages traditionally have "issues" with
strings with indefinite sizes, since a lot of memory manipulation is
needed when they shrink or grow. But that doesn't seem to be the
"evil" being discussed here.

Best regards,


Bob Masta

DAQARTA v3.50
Data AcQuisition And Real-Time Analysis
www.daqarta.com
Scope, Spectrum, Spectrogram, FREE Signal Generator
Science with your sound card!
 
J

James Kanze

@see.sig.invalid> wrote:

Not in C++. Not with professional Windows programmers, anyway.
I'm also reading from the Win32 group, and am not a C or C++
programmer. So can somebody explain the supposed evils of string
arrays?

There's no problem with string arrays. The problem is with a
particular type in C++, known as the C style array, because it
is inherited from C. Objects of this type don't obey any of the
rules of normal objects, and using objects of this type requires
significantly more work, for no gain. The result is the
professional software engineers avoid them.
I know that languages traditionally have "issues" with strings
with indefinite sizes, since a lot of memory manipulation is
needed when they shrink or grow. But that doesn't seem to be
the "evil" being discussed here.

Nothing to do with performance. That's another issue. Although
the semantics of C style arrays are killers for compiler
optimization, the replacements currently offered aren't
necessarily any faster. It's not an accident that when Java
fans want to show their language faster than C++, they write
benchmarks making extensive use of arrays of built-in types.
 
R

Richard Heathfield

James Kanze said:

The problem is with a
particular type in C++, known as the C style array, because it
is inherited from C. Objects of this type don't obey any of the
rules of normal objects,

Er, yes, they do obey the rules of normal objects. They have a size, a
type, and a value.
and using objects of this type requires
significantly more work, for no gain.

I'm sorry, but I can't agree that using arrays is more work than using,
say, a std::vector. I can agree that it *can* be more work, but not that
it necessarily is more work.
The result is the professional software engineers avoid them.

Is this an example of the "true Scotsman" argument? That is, if you find
someone - such as myself - who does not avoid arrays, do you refuse to
consider them to be a professional software engineer?

<snip>
 

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,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top