Do C++ Programmers Overuse Templates?

T

tonytech08

In what way?  Early C++ libraries (NIHCL) tried it, and found
that it didn't work.  Java tried it, and found that it didn't
work.


Whoa! I was not talking about library-level!
 
T

tonytech08

I suggest to you that software pattents disallow me to enlighten you.
That's bureaucratic

Yes, apparently oppression IS the issue :p

FUD (who is/was a sheeple?)
Judicious, in the way he seems to be using it, means "I'm too
stupid or too lazy to try to understand how it works".

Oh yeah, you propandist of big corporate committee surely have it
right. :p
Certainly, some people do overuse templates, but it's far from
universal.  

I was less than rhetorical: I WAS suggesting overuse is rampant.
There's also the question: what is overuse?

Ask your wife?
Of course, with the usual meaning of the word "judicious" in
English, his statement is trivially true.  Everything should be
used "judiciously" (i.e. with good judgement).

So state your excesses. :p
 
R

Rune Allnor

Good luck on that one.  Colleges don't get into the advanced, or in many
cases even the intermediate stuff.  People just don't seem interested in
instructing themselves on these things either.  I pushed pretty hard to
get reading and instruction material at my workplace.  

I never did that - arranged for books to be baught. I bought the
books myself, for my own money. That way I have *my* library,
which follows me around and I can get my job done.
I'm the only one who reads the stuff.

Since I already have the books available, there is no need for me
to fight for somebody else to spend $20000 on books no one else
than I will ever read anyway.
The only exception is when someone needs to know
something and I just refer them to the book that would help them.

Ah, that's where my plan backfires: I'd love to do that too, but
since I already have the books, the question comes up if I can
lend them out...

The world is a sinister place.

Rune
 
R

Rüdiger Ranft

Ian said:
Those "assembly language people" are telling your porkies. Such a
subset would be very small. "jmp" springs to mind.
NOP is the only instruction you have ALMOST everywhere.

SCNR
Rudi
 
V

Vidar Hasfjord

Arrays? If you view an "array" as a container of objects, then a
template makes obvious sense.

Yes, and that's how the typed languages C and C++ see an array. In
that sense, a C array and a C++ tr1::array template models the same
concept. Only the syntax and rules governing conversions, ability to
assign/copy, etc. are different. And here the tr1::array template is
much more regular, thus simpler.
If though, you view an "array" as a contiguous block of memory
(C++ remains close to the hardware"), then array as a template
is unappropriate.

No, while it sounds like you are talking assembly language here, even
in assembly language types are involved (e.g. byte, word, double). So
the programmer has to consider the elements contained even in raw
memory for proper size calculation, element addressing and alignment.
The array concept encapsulates that very well, and a template is
perfect for modelling it. Without templates C had to use special
syntax and peculiar semantics for arrays (that are now commonly
described as "broken").
(Did I grok your implied thought correctly?)
Almost.

Pointers: ok.

And a pointer is closely assosiated with the array concept. Using the
concepts of the STL you can view it as an iterator; a reference to an
element of an array. This is a nice generalisation at the heart of the
STL design; a high-level abstraction of the low-level features of the
language (and machine architecture) with no abstraction costs
involved.

As I've come to understand it this was a real break-through in generic
programming resulting from years of work in the field by Alexander
Stepanov. The traditional OOP and FL approaches to generic programming
removed you from the hardware and had substantial abstraction costs.
Structs implemented as templates? How?

In principle:

typedef tuple <string, int> Person;
enum {name, age};
Person joe = make_tuple ("Joe", 33);
cout << get <age> (joe);

See Boost.Fusion and Assosiated Tuples for a thorough implementation
of this idea that has advantages such as introspection.

Regards,
Vidar Hasfjord
 
L

LR

Pete said:
How? Patents are public disclosures of techniques. They in no way
prevent discussion of those techniques (indeed, their purpose is to
promote discussion and knowledge). What they prevent is use of those
techniques without permission.

I think I don't understand how IP law works in this regard. Does this
work the same way for code that it does for, say, an apple peeler?

If someone invents a new apple peeler can I, at least in the US, in aid
of showing how the invention works, publish blue prints, and maybe even
make a virtual model in some simulation software that emulates the apple
peeling process to show how truly good this type of apple peeler is?

If I can do that with a patented apple peeler, can I do that with
patented software? Can I write code that shows how it is used?
Distribute it on paper? Distribute it on computer readable media?
Write a computer emulator that simulates the patented software, like I
could with the apple peeler?

And if I can do this, could there be a violation of, something that I
don't think exists for the peeler, a software copyright?

LR
 
J

James Kanze

I think I don't understand how IP law works in this regard.
Does this work the same way for code that it does for, say, an
apple peeler?

You can't patent "code". What you patent is an invention: a
process or a machine which is new and non-evident. And the
patent doesn't cover the "expression" of the invention, only the
invention itself. Also, you can't patent laws of nature or
algorithms (but you can patent particular applications of them).

At least traditionally, and in international law. I get the
feeling that the US is extending what patents were designed for.
There is no mention of the requirement to publish at
http://www.uspto.gov/web/offices/pac/doc/general/index.html#patent,
for example.
If someone invents a new apple peeler can I, at least in the
US, in aid of showing how the invention works, publish blue
prints, and maybe even make a virtual model in some simulation
software that emulates the apple peeling process to show how
truly good this type of apple peeler is?

In order to patent an apple peeler, you *must* make the plans,
showing how it works, public. Otherwise, no patent.
If I can do that with a patented apple peeler, can I do that
with patented software?

Software is the expression of an algorithm. As such, it isn't
patentable, at least under international law. The literal
expression can be copyrighted, of course, and the software may
be an integral part of a machine or process, which can be
patented. In that case, you do have to publish detailed
specifications of the machine or process, including detailed
specifications of what the code does, and (generally, I would
assume) the algorithms it uses to do it. I don't think you'd be
required to publis a particular "expression" of those
algorithms, i.e. you need an English language expression of
them, but no C++ code.

Different jurisdictions interpret this differently; in the
United States, there is a patent for a "Cryptographic
communications system and method" which uses the RSA algorithm;
in the rest of the world, the absence of any physical machine in
the patent meant that it wasn't patentable, and the patent is
only valid in the US. But even under the US law, the authors of
the patent were required to publish the algorithm, in enough
detail that any moderately competent programmer could understand
it.
Can I write code that shows how it is used? Distribute it on
paper? Distribute it on computer readable media? Write a
computer emulator that simulates the patented software, like I
could with the apple peeler?
And if I can do this, could there be a violation of, something
that I don't think exists for the peeler, a software
copyright?

Copyright covers a different aspect: expression. The blueprints
of the apple peeler could be copyrighted. The patent office
requires, however, that a copy (or several) of them be filed
with the patent, and anyone can consult them. And you can
legally draw up your own blueprints, based on what you learned
by consulting them (but not copying), and publish them. If your
publication was just of the blueprints, I suspect that you'd
have a hard time introducing enough originality in them that
they wouldn't be considered a derived work. But if you were
writing a book on the history of apple peelers, you could
certainly include the blueprints, or parts of them, under the
fair use doctrine.
 
J

James Kanze

Whoa! I was not talking about library-level!

So what were you talking about? Just about every place I've
seen forbids the definition of templates except at the library
level. The rules are usually stricter than necessary (but of
course, the first rule is always that any of the rules may be
broken, if there is a good reason for doing so).

In practice, in numerous different companies, I've yet to see
templates used for anything but library code. Which is, IMHO,
more than "judicious". And no use can hardly be considered
over-use.
 
L

LR

James said:
You can't patent "code". What you patent is an invention: a
process or a machine which is new and non-evident. And the
patent doesn't cover the "expression" of the invention, only the
invention itself. Also, you can't patent laws of nature or
algorithms (but you can patent particular applications of them).

I think I see what you mean. Like this invention?

http://patft.uspto.gov/netacgi/nph-...PTXT&p=1&p=1&S1=6058376&OS=6058376&RS=6058376

6,058,376
Process for evaluating the financial consequences of converting a
standard form I.R.A. to the Roth form I.R.A.
At least traditionally, and in international law. I get the
feeling that the US is extending what patents were designed for.

Maybe a little bit. Maybe a little bit too much. Maybe the same way
some C++ programmers misuse templates?
There is no mention of the requirement to publish at
http://www.uspto.gov/web/offices/pac/doc/general/index.html#patent,
for example.

So much for our desire "To promote the progress of science and useful arts".

In order to patent an apple peeler, you *must* make the plans,
showing how it works, public. Otherwise, no patent.


Software is the expression of an algorithm. As such, it isn't
patentable, at least under international law.

For which I am grateful.
The literal
expression can be copyrighted, of course, and the software may
be an integral part of a machine or process, which can be
patented. In that case, you do have to publish detailed
specifications of the machine or process, including detailed
specifications of what the code does,

If you want a patent. If, it's just a trade secret that you might be
using to convict someone of a crime with, then I don't think under the
law of Florida, at least, that you have to reveal your code. Well,
maybe, we'll see how that goes.
http://www.heraldtribune.com/article/20080309/COMMUNITY/803090560

and (generally, I would
assume) the algorithms it uses to do it. I don't think you'd be
required to publis a particular "expression" of those
algorithms, i.e. you need an English language expression of
them, but no C++ code.

No, of course, not, but suppose I wanted to explain how the patent about
converting your IRA worked. Can I publish code to explain it? On paper?
On computer readable media? Just the way I could for an apple peeler? I
mean, that patent says that it uses a computer. Maybe I could implement
a hardwired solution and that would be ok? Could I hook the hardwired
version up to a computer? Or what about an "english" rendition of the
algorithm?

Different jurisdictions interpret this differently; in the
United States, there is a patent for a "Cryptographic
communications system and method" which uses the RSA algorithm;
in the rest of the world, the absence of any physical machine in
the patent meant that it wasn't patentable, and the patent is
only valid in the US. But even under the US law, the authors of
the patent were required to publish the algorithm, in enough
detail that any moderately competent programmer could understand
it.

I believe in the past that patents of this kind were required to publish
a circuit. http://www.softpanorama.org/History/index.shtml
http://patft.uspto.gov/netacgi/nph-...0&d=PTXT&s1=4135240&p=2&OS=4135240&RS=4135240
United States Patent 4,135,240
Ritchie January 16, 1979
Protection of data file contents
"The circuitry shown in the Figure controls file access in the following
manner..."

But it's not just math, I understand that this
http://patft.uspto.gov/netacgi/nph-...NM.&OS=in/Schlafly-Roger&RS=IN/Schlafly-Roger
patents not just properties of particular numbers, but an actual number
5,373,560 Partial modular reduction method
http://www.simson.net/clips/95.ScientificAmerican.PrimePat.txt


Copyright covers a different aspect: expression. The blueprints
of the apple peeler could be copyrighted. The patent office
requires, however, that a copy (or several) of them be filed
with the patent, and anyone can consult them. And you can
legally draw up your own blueprints, based on what you learned
by consulting them (but not copying), and publish them. If your
publication was just of the blueprints, I suspect that you'd
have a hard time introducing enough originality in them that
they wouldn't be considered a derived work. But if you were
writing a book on the history of apple peelers, you could
certainly include the blueprints, or parts of them, under the
fair use doctrine.

Expression is important too. http://www.mit.edu/~ocschwar/C_English.html

Or this about Universal v. Reimerdes

Source Code’s Challenge to U.S. Law
Introducing a Translator from C to English and Back
By Jonathan M. Baccash

Sadly, I can't gain access to the original at
http://www.cs.cmu.edu/People/dst/DeCSS/Baccash/thesis.pdf but Google(tm)
has thoughtfully provided a link to what I suspect is an HTML archive of
the original PDF here:
http://64.233.169.132/search?q=cach...c2eng+ACM+transcript&hl=en&ct=clnk&cd=1&gl=us


"During the trial, Professor Touretzky of Carnegie Mellon University
convincingly demonstrated that computer source and object code convey
the same ideas as various other modes of expression, including spoken
language descriptions of the algorithm embodied in the code. He drew
from this the conclusion that the preliminary injunction irrationally
distinguished between the code, which was enjoined, and other modes of
expression that convey the same idea, which were not, although of course
he had no reason to be aware that the injunction drew that line only
because that was the limit of the relief plaintiffs sought. With
commendable candor, he readily admitted that the implication of his view
that the spoken language and computer code versions were substantially
similar was not necessarily that the preliminary injunction was too
broad; rather, the logic of his position was that it was either too
broad or too narrow. Once again, the question of a substantially broader
injunction need not be addressed here, as plaintiffs have not sought
broader relief."


LR
 
J

James Kanze

I think I see what you mean. Like this invention?

6,058,376
Process for evaluating the financial consequences of converting a
standard form I.R.A. to the Roth form I.R.A.

I'd have to read the entire patent to be sure, and even then,
I'm not a patent lawyer. Still, the first sentence of the
abstract says it concerns a "process". The real question then
becomes: what is a process, and what is an algorithm. The fact
that the patent seems to talk about input and output formats
suggests that it is more than an algorithm. (On the other hand,
one might seriously question the novelty or originality. Off
hand, it looks to me that what is being patented is the use of a
program to convert between two formats. Which isn't what I'd
consider a particularly novel or original idea. But from what
I've read, the patent office in the US doesn't really have the
means of verifying such claims, and counts on the applicant
being honest and providing full and detailed "existing
practice".)
Maybe a little bit. Maybe a little bit too much. Maybe the
same way some C++ programmers misuse templates?

With the major difference that it's easy to verify what has been
patented and what hasn't. And that you're back to using loaded
phrases which don't mean anything. It's certain that some C++
programmers misuse templates, just as it's certain that some
misuse inheritance, and some misuse pointers, and some even
misuse addition. Such programmers are in a very small minority
(with those misusing inheritance probably outnumbering those who
misuse templates).
So much for our desire "To promote the progress of science and
useful arts".
:).
For which I am grateful.

But a process which depends on some specific software is, and
it's sometimes hard to make the distinction.
If you want a patent. If, it's just a trade secret that you
might be using to convict someone of a crime with, then I
don't think under the law of Florida, at least, that you have
to reveal your code. Well, maybe, we'll see how that
goes.http://www.heraldtribune.com/article/20080309/COMMUNITY/803090560

Trade secrets are almost the opposite of patents: reveal your
code, or not take proper and adequate steps to prevent it from
being known, and you forfeit the right of trade secret. You
cannot have a patent and a trade secret for the same thing (and
I'm pretty sure that still holds in the US as well).

And of course, you can register almost anything as a trademark.
I've often wondered why trademark protection wasn't used for
"look and feel"---copyright doesn't seem to be right here. (To
me---and again, I'm not an IP lawyer, so there are likely issues
that I don't understand.)
No, of course, not, but suppose I wanted to explain how the
patent about converting your IRA worked. Can I publish code
to explain it? On paper? On computer readable media? Just
the way I could for an apple peeler?

Of course. You can *publish* anything you want about a patent.
(You might be required to mention that the code is covered by
patent. I'm not sure there. And anyone who uses the code to
compete with the patent holder, without the authorization of the
patent holder, is infringing.)
I mean, that patent says that it uses a computer. Maybe I
could implement a hardwired solution and that would be ok?

Probably. You'd have to read the patent to be sure. And of
course, the courts might have to rule whether the hardware was
"a computer", or "programmed".
Could I hook the hardwired version up to a computer? Or what
about an "english" rendition of the algorithm?

An English rendition is clearly legal; it must appear in the
patent. Beyond that, you'd have to talk to a patent lawyer, to
read the entire patent, and measure exactly what is covered.
And you'd have to ask to what degree the patent is enforceable;
if it is a solution that is evident to any competent
practitionner, you can fight it.
I believe in the past that patents of this kind were required to publish
a circuit.http://www.softpanorama.org/History...etacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=%...
United States Patent 4,135,240
Ritchie January 16, 1979
Protection of data file contents
"The circuitry shown in the Figure controls file access in the following
manner..."

There's been a definite evolution. At least partially
justified: what we consider a "machine" has evolved.
But it's not just math, I understand that thishttp://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=%...
patents not just properties of particular numbers, but an actual number
5,373,560 Partial modular reduction methodhttp://www.simson.net/clips/95.ScientificAmerican.PrimePat.txt

I've heard a number of wild stories. Enough to convince me that
there is some underlying truth. The crux of the problem is that
a program cannot be patented, but a machine can, and that today,
many machines aren't anything more than a program.

Note that RSA is patented in the US, but the patent is not
recognized elsewhere. (I think it might be recognized today,
however. As long as the patent covers using the algorithm for
a specific cryptographic purpose, and not the algorithm itself.
It's a "machine" which is realized entirely in software.)
 
T

tonytech08

So what were you talking about?  

Language/compiler supported dynamic typing just like in a wholly
dynamically typed language but applied only to implement generics. The
rest of the language would be statically typed (or at least at the
programmer's discretion). I was just wondering if that is easier to
implement than templates. Though now that I think about it again
today, what can be simpler than simply substituting text like is what
template implementations do basically (read, a more sophisticated and
built-into-the compiler preprocessor).
 
T

tonytech08

NOP is the only instruction you have ALMOST everywhere.

I don't believe it. Indeed, isn't, say, the Java VM basically an
abstraction of common machine instructions (or similar that works on
bytecode)?
 
T

tonytech08

Yes, and that's how the typed languages C and C++ see an array. In
that sense, a C array and a C++ tr1::array template models the same
concept. Only the syntax and rules governing conversions, ability to
assign/copy, etc. are different. And here the tr1::array template is
much more regular, thus simpler.


No, while it sounds like you are talking assembly language here, even
in assembly language types are involved (e.g. byte, word, double). So
the programmer has to consider the elements contained even in raw
memory for proper size calculation, element addressing and alignment.
The array concept encapsulates that very well, and a template is
perfect for modelling it. Without templates C had to use special
syntax and peculiar semantics for arrays (that are now commonly
described as "broken").

I'm not convinced. I think we're just talking past each other
(different programming perspectives). The key to me is that "built-in
arrays" are contiguous and for an "array container", that is not
necessarilly so.
In principle:

  typedef tuple <string, int> Person;
  enum {name, age};
  Person joe = make_tuple ("Joe", 33);
  cout << get <age> (joe);

See Boost.Fusion and Assosiated Tuples for a thorough implementation
of this idea that has advantages such as introspection.

That is too far away from the machine to be at a traditional C/C++
level if you ask me. It puts too much of a black box between me and
the hardware (not the least of which a concern is being boiled in oil
by those megacorps that who have the resources to build complexity on
top of complexity until the little guy .. well get's slowly boiled in
oil). I think what you showed above is one of those things that
prompts me to "ask": "Are templates overused?".
 
T

tonytech08

An array can be a container of unsigned char objects. This is easily
achievable by a template as well, but irrelevant (see below).





Both boost::array and boost::shared_ptr are templates.

Something being a template does not mean that it prohibits being close to
hardware. More to the point, templates do not exist in the generated
code, only the template instantiations do, and they are technically the
same as non-templated functions or objects. As only the generated code is
exposed to hardware it is running on, the templates do not come into play
at all. Templates only live at the time of coding and compiling (with
"export", also linking stage). At run-time there are no templates, so
discussing their interaction with hardware is meaningless.

That's all "fine and dandy" to say when talking about simple use of
templates, but not for doing things with templates that exploits in
snakey/sneaky ways. Then, code becomes obfuscated in the worse way:
you can't even see the obfuscation because it is there unapparently
(that is, only behaviorly).
 
E

Erik Wikström

I'm not an expert but I'd say that while different architectures will
differ on the details you can almost always find instructions that
performs a few common operations such as logical operations (and, or,
xor, etc.), integer plus and minus, comparison and jump (combined or
separate), and instructions to store and load from memory.
I don't believe it. Indeed, isn't, say, the Java VM basically an
abstraction of common machine instructions (or similar that works on
bytecode)?

No, Java bytecode is an instruction set for an abstract architecture
which the Java VM will emulate and while there will be a lot of
similarities with other modern ISAs there is surely a number of
differences too. I believe that one of the greatest differences is the
level of abstraction, I think that Java bytecode, just like .Net CIL,
has a higher abstraction level than most "real" ISAs.
 
L

Laurent Deniau

Language/compiler supported dynamic typing just like in a wholly
dynamically typed language but applied only to implement generics. The
rest of the language would be statically typed (or at least at the
programmer's discretion). I was just wondering if that is easier to
implement than templates. Though now that I think about it again
today, what can be simpler than simply substituting text like is what
template implementations do basically (read, a more sophisticated and
built-into-the compiler preprocessor).

Seems that you look after something like the "C Object System" which
provides dynamic-types (duck typing) only when sending message and
static typing everywhere else (on top of C, it's a library). The only
thing which is not compile-time checked is if an instance responds to
a message (generic method). This is the cornerstone software design
simplification (very low coupling). It also provides numerous other
useful concepts briefly described in the slides:

http://cos.cvs.sourceforge.net/viewvc/cos/CosBase/share/doc/cos/slides-cos.pdf.gz

Coming back to C++, templates alone are useless. People claiming that
it would be useful to have templates in C (or any other language) just
don't see that they will also need to add overloading (at least),
traits (and hence namespaces) and specialization, even without aiming
at template meta-programming, and you just get another C++ (add the
special treatment of int/enum type and you get it). C++ has a very
nice and consistent set of tools to deal with static typing (still
being improved by concepts, auto and variadic template soon) which
results from practical experience over decades. On the other and it is
rather poor on the dynamic side since dynamic features are often
though as library related solution. This is not completely true
because it must interact properly with the static side which always
prepends to the dynamic side.

The pending of template+overloading on the dynamic side are the multi-
methods and with the actual C++ object model, it's rather not trivial
to add to the language (see proposal from BS which doesn't cover all
of the problem). Another very powerful dynamic concept is the generic
delegation (smalltalk, ObjC, COS) which is the pending of the special
operator-> (and the mix with operator()), but this concept is far
beyond what static type systems can handle. So C++ support very (the
most?) powerful static concepts here around. But it's just lacking
their dynamic equivalent.

a+, ld.
 
V

Vidar Hasfjord

[...]
The array concept encapsulates that very well, and a template is
perfect for modelling it. Without templates C had to use special
syntax and peculiar semantics for arrays (that are now commonly
described as "broken").

I'm not convinced. I think we're just talking past each other
(different programming perspectives). The key to me is that "built-in
arrays" are contiguous and for an "array container", that is not
necessarilly so.

It is. Being contiguous is part of the array concept.

Both the C array and the tr1::array models this concept; and equally
efficient in the sense of being "close to the hardware". The
tr1::array is just a cleaner model without the special syntax and
pecularities of the C array (non-copiable, decay, etc.).
Structs implemented as templates? How?
In principle:
typedef tuple <string, int> Person;
[...]
That is too far away from the machine to be at a traditional C/C++
level if you ask me. It puts too much of a black box between me and
the hardware [...]

It is not really any further from the machine; you can view a tuple as
a structured layout of memory. Vice verca, a 'struct' is just an
associative tuple indexed by names (fields). What I showed is that
templates has the power to model structs as well; just to answer your
question.
I think what you showed above is one of those things that
prompts me to "ask": "Are templates overused?".

In this case I think you confuse "overused" with "used for complex
stuff". I don't think you'll find widespread use of associative
tuples. That said, I fully agree with you that keeping things simple
is a good rule of thumb. Again, judicious is good.

Regards,
Vidar Hasfjord
 
T

thomas.mertes

I'm not convinced. I think we're just talking past each other
(different programming perspectives). The key to me is that "built-in
arrays" are contiguous and for an "array container", that is not
necessarilly so.





That is too far away from the machine to be at a traditional C/C++
level if you ask me. It puts too much of a black box between me and
the hardware (not the least of which a concern is being boiled in oil
by those megacorps that who have the resources to build complexity on
top of complexity until the little guy .. well get's slowly boiled in
oil). I think what you showed above is one of those things that
prompts me to "ask": "Are templates overused?".

The story of C/C++ is about building something on top of something
else: C -> C++ -> STL -> boost
Others also added some big and complicated librarys (partly on top
and partly in parallel): Win32, TurboC librarys, .NET and others.
In the end complexity is built on top of complexity.

Not everything is suited to be used as base to build something on
top. Some good concepts degenerate when too much is builded on them.

C has good basic concepts but as it can be seen at the complexities
of its descendants not all this concepts are ideal to build a
tower on them.

Greetings Thomas Mertes

Seed7 Homepage: http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.
 
T

tonytech08

[...]
The array concept encapsulates that very well, and a template is
perfect for modelling it. Without templates C had to use special
syntax and peculiar semantics for arrays (that are now commonly
described as "broken").
I'm not convinced. I think we're just talking past each other
(different programming perspectives). The key to me is that "built-in
arrays" are contiguous and for an "array container", that is not
necessarilly so.

It is. Being contiguous is part of the array concept.

Both the C array and the tr1::array models this concept;

"modeling" and actually being are different. Can I memmove tr1 arrays
around in memory?
and equally
efficient in the sense of being "close to the hardware". The
tr1::array is just a cleaner model without the special syntax and
pecularities of the C array (non-copiable, decay, etc.).

So do tr1 arrays put objects (say, for example, structs) in
continguous memory?
Structs implemented as templates? How?
In principle:
typedef tuple <string, int> Person;
[...]
That is too far away from the machine to be at a traditional C/C++
level if you ask me. It puts too much of a black box between me and
the hardware [...]

It is not really any further from the machine; you can view a tuple as
a structured layout of memory.

How it gets to be that is at issue. Begs the question: what's the
point of doing that?
Vice verca, a 'struct' is just an
associative tuple indexed by names (fields). What I showed is that
templates has the power to model structs as well; just to answer your
question.

I want structs. I don't want to just MODEL them. (That may be an
archaic viewpoint, but I don't see any better way of doing that close
to the hardware type of programming. When you get away from structs
and primitives (built-ins), that to me makes it NOT a close-to-the-
hardware language. Whether that level of programming is required
outside of things like device drivers and OSes may be relevant. It is
my programming model though even at the application level.)

I've forgotten some significant portion of C++ "techniques" I used to
know, but because I've replaced them and found them unnecessary.
In this case I think you confuse "overused" with "used for complex
stuff". I don't think you'll find widespread use of associative
tuples. That said, I fully agree with you that keeping things simple
is a good rule of thumb. Again, judicious is good.

Good point, but the caveat is more important: don't use that stuff
just because you know it. Use it only when you have to. Otherwise,
avoid it. Usage of C++ techniques is "underspecified". Of course I
will avoid stuff way more often then the typical C++ user, but then I
hope to move my codebase to my own (read in-house) language someday.
 

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,771
Messages
2,569,587
Members
45,097
Latest member
RayE496148
Top