I
Ian Collins
Christopher said:That I'd regard as poor style (although of course that doesn't mean it
may not often occur).
Nonsense, why would you se anything else when there is nothing bu a
public interface?
Christopher said:That I'd regard as poor style (although of course that doesn't mean it
may not often occur).
Ian said:Nonsense, why would you se anything else when there is nothing bu a
public interface?
If you are given a bunch of .c files, is there a way to recognize (by
just looking at them) whether the code in them is written in C or in C+
+?
What would you look for?
Phlip said:Because style guidelines often reserve 'struct' to mean "behaviorless
data bucket", where a pure virtual interface is the exact opposite -
dataless behavior.
Put that guideline together with "all publics should appear at the top
of a class", and our industry is fated to forever write only class Foo{
public:...
"More efficient and sensible" is overstating the case. You're right
about publics coming first more often, but popularity doesn't make it a
good idea. I always put private members first, with fields coming
before the functions that use them. Nothing in my code ever refers to
anything that has not defined yet, except in specific situations on
large projects where there are build-related concerns. I've been doing
this in earnest for about a year, and so far, I'm very happy with it.
I'd have been happy with not introducing "class" in the first place, but
that genie's not going back in the bottle.
Dhilip_kumar said:Depends on the input set.
#include <stdio.h> /* C header
#include <iostream.h>
class xyz {
friend family relatives;
*/
int main()
{
printf("My C++ program \n");
return 0;
}
Now?
I agree with Juha Nieminen. Thats the best.
How will one determain if a given text is English, French or a mix? We
keep looking for key words? No. Make an English read the text.
Jeff Schwab said:In the fourth place, forward declarations smell bad.
Jeff Schwab said:I got it from Bjarne Stroustrup, in The C++ Programming Language.
Jeff said:Developers should not be expected to convolute their code, just to
accommodate a single broken or misconfigured compiler that they aren't
even using.
He recommended it to decrease build times on very large projects.
Nowadays, we have good support for precompiled headers.
Jeff said:"More efficient and sensible" is overstating the case. You're right
about publics coming first more often, but popularity doesn't make it a
good idea. I always put private members first, with fields coming
before the functions that use them. Nothing in my code ever refers to
anything that has not defined yet, except in specific situations on
large projects where there are build-related concerns. I've been doing
this in earnest for about a year, and so far, I'm very happy with it.
Jeff said:I'd have been happy with not introducing "class" in the first place,
but that genie's not going back in the bottle.
Jeff said:That is not the case.
Default said:I'd have been happy to keep struct only for POD use, for C
compatibility. Different strokes and all that.
Noah said:If that's the case then your structs can never contain std::string or
anything else that isn't also a POD. May as well not use them at all
at that point.
Andy said:We tune the contents of our precompiled headers to minimise build time.
Precompiled ones are processed much faster, but you end up with stuff in
the compilation unit that it doesn't need - which slows it down.
There's also the overhead of what happens when a file that is in your
precompiled header set changes - everything that uses the precompiled
header has to be rebuilt.
Andy said:Precompiled ones are processed much faster, but you end up with stuff in
the compilation unit that it doesn't need - which slows it down.
Jeff said:"More efficient and sensible" is overstating the case. You're right
about publics coming first more often, but popularity doesn't make it a
good idea. I always put private members first, with fields coming
before the functions that use them. Nothing in my code ever refers to
anything that has not defined yet, except in specific situations on
large projects where there are build-related concerns. I've been doing
this in earnest for about a year, and so far, I'm very happy with it.
blargg said:But not necessarily C, as many people use compiler extensions or ignore
warnings from their C++ compiler.
Ian said:I've always written my classes that way. I find it much more natural to
look up the screen for declarations than down. We do this everywhere
else in our code, so why should class declarations be any different?
One could argue writing the public interface before the private data it
uses is akin to top posting.....
Writing the public interface first puts the most interesting and
important information about an interface as the first thing you see.
Implementation details, such as private member variables, rarely need to
be accessed or read. One would prefer they not be in the interface at
all, and you can use pimpl's to make that happen, but this is C++ so we
must make do. If you are using a pimpl then it makes even less sense to
have that as the top most item of importance in a class declaration
since it's completely meaningless to the interface.
The most important information should be the first information available
whenever possible. Since we normally read top to bottom, the most
important information should be at top. With regard to class
declarations, the most important information is almost always its public
interface.
One could argue anything one wants but comparing apples to oranges
(English prose to C++) is always going to be a fallacious argument
unless you can show reason for considering them the same.- Hide quoted text -
- Show quoted text -
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.