D
Dave Sexton
Hi Mark,
No need to throw us a bone -- we're doing just fine
No need to throw us a bone -- we're doing just fine
Ben said:Not commenting code is a very good way of keeping "ownership" of code.
I once worked for a company who thought they had bought the source
code to a large project. Well, they had, I suppose. Unfortunately, one
of the programmers for the selling company thought that the code was
"his", so he removed all the comments, thus rendering it pretty much
useless. I found, as the new maintainer of the code, that it was very
hard to keep the project going, even though about 40% of the code had
actually been written by me several years previously. Good, relevant
comments are invaluable.
Mark said:I work on a team where comments are forbidden (except for exceptional
conditions). And yet we deliver quality software on time.
How could this be?
1) We write good code (that's what I've been saying throughout this thread).
2) We all work on all the code. When it comes time to divide up tasks,
preference is given to working on code you haven't worked on before. We
don't have the concept of "taking over his code." We often work on code
together. We do most design in common.
Works for us!
///ark
When I feel the need arise to document the source itself, my first
reaction is to see if the code itself can't be made more self
explanatory. In most cases, it can.
Ben Newsam said:// Up the left side and across the top,
// two pixels away from the window.
hPen = CreatePen ( PS_SOLID, 0, bRaised ? WHITE : BLACK );
hOldPen = SelectObject ( hDC, hPen );
ptPoints[0].x = rcRect.left - 1;
ptPoints[0].y = rcRect.bottom;
ptPoints[1].x = rcRect.left - 1;
ptPoints[1].y = rcRect.top - 1;
ptPoints[2].x = rcRect.right;
ptPoints[2].y = rcRect.top - 1;
Polyline ( hDC, ptPoints, 3 );
SelectObject( hDC, hOldPen );
DeleteObject( hPen );
I am certainly not going to make any of the variables more meaningful than
they already are.
Ben Newsam said:Not commenting code is a very good way of keeping "ownership" of code.
Unfortunately, one
of the programmers for the selling company thought that the code was
"his", so he removed all the comments, thus rendering it pretty much
useless.
Yes, it most certainly does. But "taking into consideration" doesn't mean
that it's ok to support the development of code without documentation.
It is a skill just like coding is a skill.
They specify what's assumed to be correct at the time they pass.
The code is never guaranteed to be right, however.
Do you trust the people on your team to write good code?
You're really fixated on the idea that you can't trust documentation.
But then again, agile guys don't write buggy code I guess
I'm not sure we're ever going to agree on this.
Man, I wish we could agree on something! Don't you just feel like we're
both just spinning our wheels?
Mark Wilden said:Ben Newsam said:// Up the left side and across the top,
// two pixels away from the window.
hPen = CreatePen ( PS_SOLID, 0, bRaised ? WHITE : BLACK );
hOldPen = SelectObject ( hDC, hPen );
ptPoints[0].x = rcRect.left - 1;
ptPoints[0].y = rcRect.bottom;
ptPoints[1].x = rcRect.left - 1;
ptPoints[1].y = rcRect.top - 1;
ptPoints[2].x = rcRect.right;
ptPoints[2].y = rcRect.top - 1;
Polyline ( hDC, ptPoints, 3 );
SelectObject( hDC, hOldPen );
DeleteObject( hPen );
I think I would refactor that code. Note that you're using rcRect.left - 1
twice and rcRect.top - 1 twice. If you chose to make it three pixels away,
you'd have to change the code in a number of places. I'm not sure
exactly -how- I'd refactor it without knowing the greater context, but
duplication is always a "smell," the removal of which can often make code
more readable.
I am certainly not going to make any of the variables more meaningful
than they already are.
One thing I find detracts from its readability is the hungarian notation.
There's extra characters there with no extra meaning.
If this were C++, I would use the RAII idiom to compress the four lines
dealing with pens.
However, I do grant you that graphical manipulation (which I'm not an
expert on by any means) does lead to more complicated code. And
complicated code should indeed be commented.
///ark
I like to have the time to document my code. I find that it helps me to
improve it. It's the same train of thoughts that leads me to blog about my
code when I find it interesting enough, I just happen to like re-analyzing
what I did, and understanding it better.
1 and 3 also smell like magic numbers that should be named constant. Also,
where are the two pixels referenced in the comment ? :')
Ben Newsam said:// Up the left side and across the top,
// two pixels away from the window.
hPen = CreatePen ( PS_SOLID, 0, bRaised ? WHITE : BLACK );
hOldPen = SelectObject ( hDC, hPen );
ptPoints[0].x = rcRect.left - 1;
ptPoints[0].y = rcRect.bottom;
ptPoints[1].x = rcRect.left - 1;
ptPoints[1].y = rcRect.top - 1;
ptPoints[2].x = rcRect.right;
ptPoints[2].y = rcRect.top - 1;
Polyline ( hDC, ptPoints, 3 );
SelectObject( hDC, hOldPen );
DeleteObject( hPen );
Ben said:Ben Newsam said:// Up the left side and across the top,
// two pixels away from the window.
hPen = CreatePen ( PS_SOLID, 0, bRaised ? WHITE : BLACK );
hOldPen = SelectObject ( hDC, hPen );
ptPoints[0].x = rcRect.left - 1;
ptPoints[0].y = rcRect.bottom;
ptPoints[1].x = rcRect.left - 1;
ptPoints[1].y = rcRect.top - 1;
ptPoints[2].x = rcRect.right;
ptPoints[2].y = rcRect.top - 1;
Polyline ( hDC, ptPoints, 3 );
SelectObject( hDC, hOldPen );
DeleteObject( hPen );
I think I would refactor that code.
So would I. Er... probably. Possibly. I wasn't illustrating my point
with a piece of perfect code, but with some *real* code that will
definitely *not* be altered without a really good reason (such as it
not working any more).The point is that the comments make it a whole
lot easier to understand. The code itself simply is what it is, it
does its job (whatever that happens to be) and therefore does not need
to be fiddled with in any way. Whatever circumstances that code was
written in, and whatever language it is written in, are irrelevant.
Yes, it can be improved, but it won't be, and when I found that
snippet I was grateful for the comments included.
Note that you're using rcRect.left - 1twice and rcRect.top - 1 twice. If you chose to make it three pixels away,
you'd have to change the code in a number of places. I'm not sure
exactly -how- I'd refactor it without knowing the greater context, but
duplication is always a "smell," the removal of which can often make code
more readable.
One thing I find detracts from its readability is the hungarian notation.
There's extra characters there with no extra meaning.
If this were C++, I would use the RAII idiom to compress the four lines
dealing with pens.
However, I do grant you that graphical manipulation (which I'm not an expert
on by any means) does lead to more complicated code. And complicated code
should indeed be commented.
///ark
Ben,
Your posts are appearing as one day into the future, which means that
topics to which you respond are staying at the top of the heap in my
newsreader.
Please fix your system clock....
So would I. Er... probably. Possibly. I wasn't illustrating my point
with a piece of perfect code, but with some *real* code that will
definitely *not* be altered without a really good reason (such as it
not working any more).
The code itself simply is what it is, it
does its job (whatever that happens to be) and therefore does not need
to be fiddled with in any way.
See my other comment about how, at my shop, we forbid both commenting and
ownership. Turns out the practices work well together.
How could it be useless, when the code itself can be read? Was it really
written that badly?
What we're saying is that if you "fiddle" with the code a bit, you don't
need to comment it. And you end up with better code, to boot. That's sounds
like a win to me.
Ben Newsam said:I have learnt, over many, many years experience, not to "fiddle" with
code at all unless it is necessary. What seems like an improvement can
have all sort of repercussions elsewhere.
Ben Newsam said:// Up the left side and across the top,
// two pixels away from the window.
hPen = CreatePen ( PS_SOLID, 0, bRaised ? WHITE : BLACK );
hOldPen = SelectObject ( hDC, hPen );
ptPoints[0].x = rcRect.left - 1;
ptPoints[0].y = rcRect.bottom;
ptPoints[1].x = rcRect.left - 1;
ptPoints[1].y = rcRect.top - 1;
ptPoints[2].x = rcRect.right;
ptPoints[2].y = rcRect.top - 1;
Polyline ( hDC, ptPoints, 3 );
SelectObject( hDC, hOldPen );
DeleteObject( hPen );
I think I would refactor that code.
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.