Bo Persson wrote:
Jeff Schwab wrote:
SG wrote:
On 7 Mai, 10:47, James Kanze <james.ka...@gmail.com> wrote:
As you say, the code isn't doing the same thing. For very small
programs (up to, say, 500 lines of code), yes. C++ is more
verbose than, say, AWK or Python. And in fact, for such things,
I use AWK, and not C++. For larger projects, however, the
"verbosity" of C++ fulfills an important function---keeping the
interface specification separate from the implementation code.
While I think C++ is probably a little more verbose than Ada 95,
I don't think that the difference is significant. And I don't
know of any other language which provides comparable features,
and which could really be used for the sort of projects C++
would typically be used for.
Regarding separating interface from implementation (.hpp/.cpp): The
Java folks don't seem to have a problem with the lack of header
files. They can write "interface XXX {...}" and/or just let the
javadoc tool generate some nice HTML documentation from the source
code.
I rarely bother with such separation in my own code; in fact, I
usually consider it a mistake. James and I have had this
discussion here before, though, and I have no interest in poking
that particular sleeping dog.
Why not?
Discussing why interface and implementation is so much better than
header and implementation, sounds fun. :-)
Ho ho ho. :)
If you write lots of small classes and functions, then maintaining
separate declarations and definitions causes an absurd amount of source
code bloat (nearly 2x). There is also the maintenance headache of
keeping function signatures up to date. For high-level interfaces,
there's no problem, because the interfaces are meant to be stable;
arguably, changes to the overall interface of an application ought to be
difficult. If the guts of your code include tons of tiny functions,
though, then making changes ought to be easy, not hard. For example, I
vastly prefer this:
template<class Coordinate>
class point
{
Coordinate m_x;
Coordinate m_y;
public:
typedef Coordinate coordinate;
point(coordinate x, coordinate y )
: m_x( x )
, m_y( y ) { }
coordinate x() const {
return m_x;
}
coordinate y() const {
return m_y;
}
};
To that:
template<class Coordinate>
class point
{
Coordinate m_x;
Coordinate m_y;
public:
typedef Coordinate coordinate;
point(coordinate x, coordinate y );
coordinate x() const;
coordinate y() const;
};
template<class Coordinate>
point<Coordinate>::point(coordinate x, coordinate y)
: m_x( x )
, m_y( y ) { }
template<class Coordinate>
typename point<Coordinate>::coordinate
point<Coordinate>::x() const {
return m_x;
}
template<class Coordinate>
typename point<Coordinate>::coordinate
point<Coordinate>::y() const {
return m_y;
}
This is, of course, an extremely simple case. In practice, the mess is
far worse.- Hide quoted text -
I tend to agree with you, but am glad that C++ permits both forms.
written code to a file that had hand-written code. I wonder if
there are some Java developers out there who attempt that.