STL design "good" wrt producing code bloat?

N

Noah Roberts

Tony said:
Not an asset, IMO. Pretty much a language on it's own. It reminds me
of the column in a programming magazine: "Obfuscated C" where the
goal was (I think) to write the most undecipheral code snippet. Doing
unusual things with templates may be interesting or fun but probably
doesn't belong in general coding practices. How much undecipherable
code can one have before it becomes overwhelmingly unmaintainable?
I want to see code that I can understand what it is doing without having
to go investigate the tiniest of idiosyncracy of template machinery.

You and I have different views of the STL. I see the STL as a black
box into which I send things and get things back. I don't particularly
care how it does those things. What I find interesting about the STL
is the public interface. From a generic programming viewpoint the STL
is an amazing piece of work that has an interface that is fairly easy
to use for most purposes and can be implemented on numerous
architectures.

When I do have to look inside the STL because something I have done
wrong traces into an STL container I don't find the code there
particularly difficult or even that interesting or groundbreaking. If
you want interesting things to do with templates look at MPL, Spirit,
and boost::bind/boost::function. Yes, those thing definately do have a
place in general coding practices...they allow you to create very
powerful tools that are easy to USE (if not easy to understand or
implement).

Spirit is one great example of such work. Spirit is easy to use and
makes developing parsers a breeze...but no way would I step into it
trying to figure out how it works...I don't need to know how it does
what it does to use it.
 
T

Tony

Noah Roberts said:
You and I have different views of the STL.
Yep.
I see the STL as a black
box into which I send things and get things back.

And I OTOH don't like black boxes.
I don't particularly
care how it does those things.

And I have "NIH syndrome".
What I find interesting about the STL
is the public interface. From a generic programming viewpoint the STL
is an amazing piece of work that has an interface that is fairly easy
to use for most purposes and can be implemented on numerous
architectures.

When I do have to look inside the STL because something I have done
wrong traces into an STL container I don't find the code there
particularly difficult or even that interesting or groundbreaking. If
you want interesting things to do with templates look at MPL, Spirit,
and boost::bind/boost::function. Yes, those thing definately do have a
place in general coding practices...they allow you to create very
powerful tools that are easy to USE (if not easy to understand or
implement).

Those are specialized applications. I consider templates a specialized
subsystem of C++. I don't want code littered with templates unless the
templates are containers/iterators/algorithms. Just personal preference.
Spirit is one great example of such work. Spirit is easy to use and
makes developing parsers a breeze...but no way would I step into it
trying to figure out how it works...I don't need to know how it does
what it does to use it.

And the "off the beaten path" applications of code are not what I'm
generalizing about.

Tony
 
N

Noah Roberts

Tony said:
Those are specialized applications. I consider templates a specialized
subsystem of C++. I don't want code littered with templates unless the
templates are containers/iterators/algorithms. Just personal preference.

Well, that is certainly your poragative but you've just tossed out
pretty powerful tools based on "personal preference".
 
I

Ian Collins

Tony said:
Those are specialized applications. I consider templates a specialized
subsystem of C++.

Then you haven't invested the time and effort to master a core part of
the language.
I don't want code littered with templates unless the
templates are containers/iterators/algorithms. Just personal preference.
A rather shortsighted preference. Try them, learn where they make life
easier. The more I dig into templates and meta programming, the more I
find myself asking "is that it?" when solving complex problems with very
few lines of code.
 
P

peter koch

Tony skrev:
And I OTOH don't like black boxes.

Right. What operating systems do you write code for? Apart from that,
the standard containers are pretty well documented so the boxes are not
that black again.
And I have "NIH syndrome".


Those are specialized applications. I consider templates a specialized
subsystem of C++. I don't want code littered with templates unless the
templates are containers/iterators/algorithms. Just personal preference.

I don't like liver; it's a personal preference. But it is not an
argument against others who eat liver with great joy. If you don't like
it then stay away from it, but don't expect sympathy from others.

Peter
[snip]
 
G

Gavin Deane

Tony said:
And I OTOH don't like black boxes.


And I have "NIH syndrome".

Which is, of course, your personal choice. However, if you reject the
concept of reading the documentation and treating the implementation as
a black box in favour of reinventing all the wheels yourself, you are
throwing away an enormous amount of your own productivity. It's
entirely up to you whether you care about that, and it sounds like you
don't. But if you ever aspire to find yourself programming
professionally, I imagine an employer would have a problem with that
approach.

Gavin Deane
 
N

Noah Roberts

Gavin said:
Which is, of course, your personal choice. However, if you reject the
concept of reading the documentation and treating the implementation as
a black box in favour of reinventing all the wheels yourself, you are
throwing away an enormous amount of your own productivity. It's
entirely up to you whether you care about that, and it sounds like you
don't. But if you ever aspire to find yourself programming
professionally, I imagine an employer would have a problem with that
approach.

I had an employer that had NIH syndrom. I don't know...it might be
worse working for one than having one work for you. At least when one
working for you you can smack them around and make them use tools
available to them....you can't do that when it's your boss :p
 
I

IR

Noah said:
I had an employer that had NIH syndrom. I don't know...it might
be worse working for one than having one work for you. At least
when one working for you you can smack them around and make them
use tools available to them....you can't do that when it's your
boss :p

Well, I *have* an employer that *had* that syndrom too. Fortunately, I
managed to convince him that buying a fully fledged ACID RDBMS library
was indeed way more profitable than having to code it ourselves.

I have to admit, he only saw my point after I spent waaaay too much
time coding a disk-based B-Tree (which didn't even support
transactions or multi-threading), whereas in about an hour I installed
the DB library, made some example code and got it running.

:D


Cheers,
 
M

Mathias Gaunard

Tony said:
Sounds like obfuscation.

Did you read all the implementations of the libraries you used?
The implementation can vary also, while APIs are usually stable.

Been there. Done that. I wanted architecture/design documentation on the
memory management.

There is no need to be a guru to understand how containers handle memory.
std::vector, for example, asks for a contiguous segment of memory of T's
through the standard allocator (or another one if you provide it), then
uses placement new to construct the objects.
Of course, to provide the complexity the standard requires, it needs to
allocate more than it needs. The "more" is implementation dependent and
is at least sqrt(n) where n is the number of elements.

What may be bothering you is that they often do not give the memory back
to the system when shrinking, and may not even do so when freeing. The
standard doesn't really put constraints on how vector manages its
capacity to amortize operations.

There is no such problem with node based containers though, that can
allocate memory as needed without performance issues.

Performance is overrated, these days.

Well, if you store pointers instead of objects, you're basically stuck
with "everything is a pointer".
That's a huge performance hit. You might as well use Java, which
actually will be more efficient since it has GC, which are basically
needed to make "everything is a pointer" efficient.

Readability improves, usage improves
safety need not be compromised.

What you don't seem to understand is that with void* you lose
readability, easy usage and safety.

std::vector<void*> v;
v.push_back(new int(5));
v.push_back(new double(6.));

std::cout << *((int*)v[1]) << std::endl;

1) You need to cast to get back to the original type, which is verbose.
This is still needed if want heterogenous containers though.
2) While casting you may do things wrong and produce undefined behaviour
3) How should memory be handled here?

But I don't want to get into the details:
just go find another well-implemented library and look at it.

Again, who cares about how a library is implemented?
What's important is that it does what it does in the most efficient way.

The code of your compiler is not supposed to be easy to read so that
beginners can understand how a compiler works. It's supposed to analyse
correctly your code and produce the most efficient assembler.

To understand how it works, read the documentation.


No, it's a fact.
And it doesn't even allow specialization.

Hehe. OK, if you say so then surely it must be so. :p

You have made numerous posts criticizing C++ while you obviously don't
have much knowledge about it, and even less usage.

Again, performance is overrated in many many cases. In many many cases,
it doesn't even matter what container you use. You'd have to be doing things
with thousands of objects before performance concerns became important.

Sure, O(1) and O(n) are the same things.
What kind of algorithmic course did you follow? The one for dummies?

Or maybe you just never worked with applications that had to scale.
 
M

Mathias Gaunard

Tony said:
And I OTOH don't like black boxes.

There is no way to know how the implementation works, since there are
various implementations of C++ and standard libraries, some
closed-source, and that your code should run on all of them.

And I have "NIH syndrome".

I, too, don't like stuff made by others when it could have really be
made better written in another way.
This is not the case for the STL though.

Those are specialized applications. I consider templates a specialized
subsystem of C++. I don't want code littered with templates unless the
templates are containers/iterators/algorithms. Just personal preference.

The STL is just containers/iterators/algorithms.
What are you talking about then?

It you mean "the C++ standard library parts that are not STL" just say
so explicitly.
So is your criticism about usage of templates in iostreams?
 
I

IR

Mathias said:
Or use one that you don't need to buy and that doesn't have a
restricting license.
Such as SQLite.

I hardly see how your boss could refuse public domain.
You actually have the right to copy and paste the code and claim
it as yours.

Sure. I used other free libs (eg. Anti Grain Geometry 2.4, before it
went to GPL in 2.5).
Concerning the DB thing, SQLite was an option. Nevertheless I
preferred another lib which was more conforming to our needs.

However I do use SQLite in a personal project ;-)


Cheers,
 
I

IR

Mathias said:
I hardly see how your boss could refuse public domain.
You actually have the right to copy and paste the code and claim
it as yours.

BTW, the only way to keep public domain code alive IMHO is to *never*
claim it as yours. As far as I'm concerned, I always credit the
authors.

Years ago, a manager tried to make me omit credits in the
documentation. Although he was legally right, we included the credits.
I made him choose between two lines of "we are using..." and me. :D

Cheers,
 
N

Noah Roberts

Mathias said:
Or use one that you don't need to buy and that doesn't have a
restricting license.
Such as SQLite.

I hardly see how your boss could refuse public domain.
You actually have the right to copy and paste the code and claim it as
yours.

Well, I had a pretty hard time selling boost. The policy actually was,
"No third party libraries." We use it now, but that manager quit so...

They can come up with all sorts of reasons. "Has no support," "might
change in incompatible ways," "doesn't fit our needs (even though no
effort was made to see if it did)," etc...

You know...someone has a bad experience with some library vendor and so
to defend against that they decide to never use anyone else's libraries.
 
M

Mathias Gaunard

IR said:
Well, I *have* an employer that *had* that syndrom too. Fortunately, I
managed to convince him that buying a fully fledged ACID RDBMS library
was indeed way more profitable than having to code it ourselves.

Or use one that you don't need to buy and that doesn't have a
restricting license.
Such as SQLite.

I hardly see how your boss could refuse public domain.
You actually have the right to copy and paste the code and claim it as
yours.
 
I

IR

Noah said:
Well, I had a pretty hard time selling boost. The policy actually
was, "No third party libraries." We use it now, but that manager
quit so...

They can come up with all sorts of reasons. "Has no support,"
"might change in incompatible ways," "doesn't fit our needs (even
though no effort was made to see if it did)," etc...

You know...someone has a bad experience with some library vendor
and so to defend against that they decide to never use anyone
else's libraries.

In which case I always reply: we have the code available since it's
public domain, at least didn't have to write it, even if we have to
support it ourselves later... (this doesn't apply to the "doesn't fit
our needs" argument, but this one is pretty weak if the devs believe
they need that lib)

Even in the worst case it's still a win using it IMHO. :)


Cheers,
 
T

Tony

Mathias Gaunard said:
Did you read all the implementations of the libraries you used?

Not when I was team developer of corporate apps (10+ years ago).
But now that I'd like to deliver my own software, I'm considering
building everything I need.
The implementation can vary also, while APIs are usually stable.



There is no need to be a guru to understand how containers handle memory.
std::vector, for example, asks for a contiguous segment of memory of T's
through the standard allocator (or another one if you provide it), then
uses placement new to construct the objects.

Oh. I thought perhaps it had something other than the compiler-supplied
mem mgmt underlying it. Good info.
Of course, to provide the complexity the standard requires, it needs to
allocate more than it needs. The "more" is implementation dependent and is
at least sqrt(n) where n is the number of elements.

How did they come up with sqrt(n) as the reserve mem amount?
What may be bothering you is that they often do not give the memory back
to the system when shrinking,

That seems reasonable, but an option may have been better.
and may not even do so when freeing.

You mean even when the container is deleted??
The standard doesn't really put constraints on how vector manages its
capacity to amortize operations.
OK.

There is no such problem with node based containers though, that can
allocate memory as needed without performance issues.

And node-based containers give it all back when deleted?

Well, if you store pointers instead of objects, you're basically stuck
with "everything is a pointer".
That's a huge performance hit.

But all that matters is staying within the performance requirement of the
application program. Side-by-side comparison of the performance of
various container implementations may not be relevant then.
You might as well use Java,

That's a silly thing to say.
What you don't seem to understand is that with void* you lose readability,
easy usage and safety.

I understand it very well. I weigh the tradeoffs and make a choice. Well
without disclosing my own container implementations, I have to say that
readability and ease-of-use is greatly improved over something like STL.
While not being the purist's idea of "type safe", it's hardly an abominable
aberration. (Remember too, it doesn't have to be templates or no templates,
things in between are possible).
Again, who cares about how a library is implemented?

I do.
What's important is that it does what it does in the most efficient way.

That's not enough for me.
The code of your compiler is not supposed to be easy to read so that
beginners can understand how a compiler works. It's supposed to analyse
correctly your code and produce the most efficient assembler.

It's the "all things for all users all the time" stuff. One can do much
better
many times for a specific program.
To understand how it works, read the documentation.

Usually there is none at the design/architecture level.
No, it's a fact.

If you're an extremist/purist.
And it doesn't even allow specialization.

Not a concern.
You have made numerous posts criticizing C++ while you obviously don't
have much knowledge about it, and even less usage.

LOL. Don't take it personally. (Though I made no criticizing remarks. You
are
taking it that way and you should do some introspection to determine why you
are so sensitive to anyone doing anything differently than your own way or
the
"std" way).
Sure, O(1) and O(n) are the same things.
What kind of algorithmic course did you follow? The one for dummies?

Read my statement above noting that if you're within the range that the
program
requires, it's a moot point. It simply does not matter. The user won't
notice anything
different.
Or maybe you just never worked with applications that had to scale.

Or maybe you're getting a bit long in the tooth with your attacks. (Grow up
already).

Tony
 
T

Tony

Noah Roberts said:
Well, that is certainly your poragative but you've just tossed out
pretty powerful tools based on "personal preference".

Again, it doesn't have to be either/or. There's usually a range of
possibilities
in between.

Tony
 
T

Tony

Ian Collins said:
Then you haven't invested the time and effort to master a core part of
the language.

LOL. Because I choose not to use it all over, all of the sudden I can't even
tie my own shoes huh? Some of you guys are silly, silly, silly.
A rather shortsighted preference.

Just the opposite actually.
Try them, learn where they make life
easier.

Been there, done that. Judicious use and even minimal use is the mantra
here.
The more I dig into templates and meta programming, the more I
find myself asking "is that it?" when solving complex problems with very
few lines of code.

That's not the goal here. I'll leave that kind of research to the language
lawyers
and scientists. All those clever tricks done with templates or whatever are
not
only not necessary but also undesireable. Give me a good architecture/design
with the FEWEST advanced/obscure/clever mechanisms any day. (Something
I'm sure a lot of people enamored with technology itself rather than
building
software will never quite grasp. Keep It Simple Stupid.)

Tony
 
T

Tony

peter koch said:
Tony skrev:

Right. What operating systems do you write code for?

Well I'm writing my own of course! (hehe, ;) )
Apart from that,
the standard containers are pretty well documented so the boxes are not
that black again.

They're only one option amongst many.
I don't like liver; it's a personal preference. But it is not an
argument against others who eat liver with great joy. If you don't like
it then stay away from it, but don't expect sympathy from others.

My my, another one getting sensitive about nothing. Interesting. I wasn't
aware the choice of whether or not to use the STL was a religious topic!

Tony
 
T

Tony

Gavin Deane said:
Which is, of course, your personal choice. However, if you reject the
concept of reading the documentation

There isn't any design/architecture documentation really. But from what
I've gotten here, there's really nothing that novel happening at the mem
mgmt level.

Any way you slice or dice it though, the STL is hideous to look at (at least
the implementations I've seen, though I don't see how any could be much
better because it's the template syntax that is a big part of the ugliness).
and treating the implementation as
a black box in favour of reinventing all the wheels yourself, you are
throwing away an enormous amount of your own productivity.

It is very educational though. (Maybe everyone should do it, even if they
use STL).
It's
entirely up to you whether you care about that, and it sounds like you
don't. But if you ever aspire to find yourself programming
professionally, I imagine an employer would have a problem with that
approach.

I haven't done that in 10+ years. Been there. Done that. (Never again!). :)

Tony
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top