I was proposing a style from this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
namespace vp {
template<class T>
class list {
private:
struct node {
node();
node(T Value, node *pnode);
node(T Value, node *Prev, node *Next);
~node();
// ...
template<class T>
vp::list<T>::node::node() : value(T()), prev(NULL), next(NULL) {}
template<class T>
vp::list<T>::node::node(T Value, node *pnode) :
value(Value), prev(pnode->prev), next(pnode) {
pnode->prev = this;
if (prev)
prev->next = this;
}
template<class T>
vp::list<T>::node::node(T Value, node *Prev, node *Next) :
value(Value), prev(Prev), next(Next) {
if (prev)
prev->next = this;
if (next)
next->prev = this;
}
|
To this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
namespace vp {
template<class T>
class list {
private:
struct node {
node() :
value(T()), prev(NULL), next(NULL);
node(T Value, node *pnode) :
value(Value), prev(pnode->prev), next(pnode);
node(T Value, node *Prev, node *Next) :
value(Value), prev(Prev), next(Next);
~node();
// ...
template<class T>
vp::list<T>::node::node() {}
template<class T>
vp::list<T>::node::node(T Value, node *pnode) {
pnode->prev = this;
if (prev)
prev->next = this;
}
template<class T>
vp::list<T>::node::node(T Value, node *Prev, node *Next) {
if (prev)
prev->next = this;
if (next)
next->prev = this;
}
|
Everything still get's defined separately from the declaration of the class members, so you can have all definitions in a source file (except with templates) and all declarations and initializations in the header file. I haven't tested it yet, but I'm sure this compiles (I believe it's the way I had it before). The only thing I don't like about this method is that if you change the way a ctor behaves and need to modify the way a member is initialized, you need to edit the header file.
chrisname wrote: |
---|
Also, what do you mean by "block notation"? Do you indent your code in "LISP style"? Like this: |
No, I meant like how variable data types line up in a column and the variable names in another column. This is typical in the documentation on MSDN, all MS source code I've ever seen, and popular amongst senior coders (referring to age, not experience). I'm not sure if it originated from languages that didn't allow multiple declarations on a single line, or what, but I don't exactly like it. It also tends to promote declaring ALL variables at the beginning of the function, another thing I had, and isn't ideal for a lot of functions (optimization wise).
I prefer to declare my variables when and where I need them, no where else. I like to keep all ints, doubles, strings, on one line so I can easily see the data type and all variables associated with them.
xerzi wrote: |
---|
everything else I use the same thing as you. |
Yes, the only major differences I notice is the indentation is larger, again limited screen space so 3 space indentation is my preference, and that you pad your parenthesis. I like my variables and arguments, and whatever else, slammed up tight. I like how you keep a space between the if/for statements (
if (...)
). Some people still think that those are function calls, hidden deep within some implementation of C.
xerzi wrote: |
---|
Screens are becoming more and more high res now though even 1920x1080 is looking small in comparison. |
Yes, I agree with you, my monitor I have supports over 2000x1600 (I don't know the numbers exactly) but due to the distance I sit away from it, the text becomes too hard to read. When my desktop is working properly, I'm in heaven when I open up C::B. I love the massive amounts of space I have to type, and from time to time, I'll plug my laptop into the monitor via the VGA...yeah, the laptop was made last year (March 2011 if I'm not mistaken) and still has only a VGA display port...
iseeplusplus wrote: |
---|
I can't decide which of these ways I like to do it. |
If it were up to me, I wouldn't pick any (duh!), but I'd lean more towards the first one if I was worried about width limitations (which I am), or the second one if not. The second one looks cleaner, but you run into the issue that if you have a multiple parameter ctor, your initializer list could be pretty far out there.
Obviously, we can debate about what looks best, but I've seen some really clean code that wasn't very effecient. I've also seen some hideous looking code that was, once you could understand it, a gem amongst codes. I believe it really comes down to readability. It'd be nice if there was a standard way to format code, but then I believe a lot of very good programmers would get upset since it's non conformant (and more than likely my style wouldn't be selected so I'd be upset as well).
I've also narrowed it down to trying to be as concise as possible, don't over do for loops, like I have in this very program, keep a constant pattern throughout your entire code, and always remember to use things like AStyle to help ;)