The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
There's a lot to be said for the idea of self-documenting code... not all of it pleasant. The thing is that, while the code may well document itself perfectly in the mind of its creator, that creator might fail to take into account that many people are not exactly what one might describe as "autodidactic" and thus that self-documentation may well be lost on them.
Of course, in a perfect world, people who are unable to understand your code shouldn't be playing with it in the first place... but it's not a perfect world, and ultimately, one has to live with the knowledge that from the moment one's code hits a live environment, the catharsis of creating such brilliance is over, and at that point it becomes prostitution, with the nature of a free-for-all built in.
Code is self-documenting only if people of at least as high an intelligence as the original programmer are looking at it... but since every programmer (in his own mind, at least) is more intelligent than every other programmer, that's almost guaranteed not to happen.
My personal style is to comment at the start of procedures: "This procedure does [this], and (sometimes) here's the algorithm, rendered down into English for all you lesser mortals to understand." I might occasionally document a flag or something which is being used in a particularly abstruse way (consider, for example, the "reverse" or "multiply" - or whatever you want to call it - flag in some implementations of the Luhn algorithm for calculating checksums in credit card numbers -- that's not obvious at all).
Sometimes, the way an algorithm works isn't obvious even though the code itself is amazingly simple: for example, to describe why Euclid's algorithm (for the greatest common divisor of two positive integers) works takes pages and pages of text, involving graphs and discussions of where points converge and so on - even though a function for it looks like this:
int GCD(int x, int y)
if ((x==0) || (y==0)) return 0;
if (x>y) x-=y; else y-=x;
So in summary, then, I don't think code can always be said to be self-documenting: if the algorithm itself is abstruse (as is Euclid's algorithm) then no matter how simple the code is, the thing's still going to need to be explained. In cases like Euclid's algorithm, the best documentation may well be a link to a Wikipedia article, or something like that.
"Naturally, I'm not programming anything that requires more thought than a payroll program, and I have a perfect memory and everyone I work with does too, and all of them plan to live forever and never leave my company."
"Seize the day" - Horace
"It's not what he doesn't know that scares me; it's what he knows for sure that just ain't so!" - Will Rogers, said by him about Herbert Hoover
Yeah, exactly. I'm starting to think that this whole "I don't need to use comments" thing is coming from people misunderstanding what self-documenting code is. Self-documenting code is largely about readability (which is good); it doesn't mean that you never need to use comments.
Self-documenting code can reduce the need for comments, but that's not the same as eliminating the need for comments. Whenever I hear programmers making these kinds of over-generalized dogmatic statements, I assume it to be a sign of lack of experience in real-world programming, because I can't imagine how someone can program for years and not run into counterexamples.
Scalar functions used in large sets can be the work of the devil, the overhead for processing a function is proportional to the number of rows and the run under a single thread. If you can't or don't want to use the CLR and want better performance, write table valued functions and use a subquery. Sounds stupid and kind of counter intuitive, but it works...
"If you ever start taking things too seriously, just remember that we are talking monkeys on an organic spaceship flying through the Universe"
Sorry, I meant table valued parameters, which is what I assumed Rhys was talking about (that is, pass a bunch of results to a function through a table valued parameter, then return the manipulated results as a table from the function).
I once did a mistake of writing a query with a function that takes a string, manipulates it and returns the value. The query took forever to run. Moving the logic to the query itself made it insanely faster.
On Tuesday when I went home from work there were a 30" and a 20" monitor connected to my PC. I had a day off Wednesday and came in this morning to find the 20" monitor has been swapped for another 30". It's pretty cool, I feel like I'm working in mission control now!
It's always nice having more than one monitor and having two quite large ones is nice. I don't have monitors as large as 30" but I have three 21.5" displays that I love using. I love the added screen space.