Hi all,
I've made a little console app dealing with 3d graphics. So I figured could post it here. It is using windows api, though there are only few lines of that, so I think you could easily change it to run on other systems. Any comments and suggestions appreciated.
Edit: and besides that, you can read the source and clearly see that it's clean. It's also very neatly written and easy to read; some open source programs aren't. GNU fdisk comes to mind...
Edit 2: one problem with this: literally the only comment in that code was a line of source code that was commented out (maths.h). Why aren't there any comments?
Edit 3: Only these lines are windows-specific:
graphics.cpp line 102, 104, 107, 108, 109, 110
main.cpp line 4, 7, 77
I disagree. Sure, his code is neat enough not to _need_ inline comments but he could at least put a description of what each function does at the top of it's declaration:
1 2 3 4 5 6 7 8 9 10 11 12 13
/**
* swap: swap the values of the two pointers, a and b
* @a: a pointer
* @b: another pointer
*/
void* swap(void* a, void* b)
{
char* pA = (char*)a,
* pB = (char*)b,
tmp = *pA;
*pA = *pB;
*pB = *pA;
}
Comments are habitually out of date or just plain lying.
Where did you get that idea from?
Are you saying i++; /* Add one to i */ is a lie? In what possible scenario is ++ going to do something other than increment i by 1 (except where i is a pointer, in which case it will resolve to something like i += (unsignedlongint)(i * (sizeof(typeof(i));, and except where ++ is overloaded)?
Having said that; you're right. If code is written well enough, it should explain on it's own what it does and why. But that doesn't mean you shouldn't comment your code at all, does it?
I haven't had a chance to run it yet, because I haven't been on windows lately, but when I do (probably later on today) I'll make sure to test it out and see what's so cool :)
I'm okay with comments explaining what interface functions do. Inside the functions, unless it's for didactical purposes, not so much.
Where did you get that idea from?
Simple. Programmers know that compilers ignore comments, so they're likely not to read them. As code changes, the comments have to be manually corrected, and being the lazy effs that we are, we won't do it. A heavily commented project that's gone through enough revisions contains two programs: the code itself and its comments.
That, and the suits in code review are often confused on how comments should be done, so the poor programmers have to use specific comment templates, increasing cruft.
Commentary describes what is happening, not how, as the code itself does that. Clear code only needs commentary that describes its purpose, and only when that purpose is not evident.
That's nice work, shame that website sux balls. It opened 3 lame javascript windows about IQ testing, Casino games, and Penis enlargement...(I think those 3 go hand in hand). which wouldn't allow me to close, every time I would close a new popup would open, and when I force quit firefox from task manager and restarted firefox the same lame windows opened up. Only way to get around it was to open up some more firefox windows with a couple tabs of bookmarks and then close the first window to flush all those tabs, and then restart the computer delete cookies and start again. fun fun fun....
I don't usually work with my code long enough to forget what it does and I always write it alone, so there isn't much point it writing comments for me.
I don't usually work with my code long enough to forget what it does and I always write it alone, so there isn't much point it writing comments for me.
That's fair enough. The code is still very nice. I can't emphasize this enough, but your code really is excellent. It's very easy to read and understand. But at the same time... it's still nice to see some natural language every so often :)