Making wrong code look wrong!
Why is this bad?char* dest, src;
And Why is this dangerous?
if (i != 0)
foo(i);
What is wrong with this?
s = Request(“name”)
write “Hello!” + s
Keep functions short. If a function cannot be viewed from a single screen and needs scrolling, it is time to refractor your code. Why?
Why this line in c++ doesn’t really say anything about what it does?
i = j * 5;
What’s wrong if dosomething() throws an exception?
dosomething();
cleanup();
One line answer that Joel gives for all above questions is “It doesn’t make wrong code look wrong!”.
Read more here: http://www.joelonsoftware.com/articles/Wrong.html
An interesting read!
:-)
Back to Basics!
What is a null-terminated string? What is a Pascal-string? And finally what is a f#@&ed string?
What is the problem with this code?
char bigString[1000];
char *p = bigString;
bigString[0] = ‘\0’;
p = mystrcat(p,”John, “);
p = mystrcat(p,”Paul, “);
p = mystrcat(p,”George, “);
p = mystrcat(p,”Joel “);
…
…
Does malloc do garbage collection? ;-)
Why is it better always to malloc 2^n bytes?
Why “SELECT author FROM books?” is slow when done on xml?
Do you understand what this code does?
void foo( char* a, char* b )
{
while (*a) b++;
while (*a++ = *b++);
}
I know most of our answers will be “Why should I care about all pointer nonsense when I’m coding in my beautiful language like Java or Perl?” This reminds me of an old discussion we had during lunch. Is it necessary for application programmers to know low level stuffs? Joel says “Yes”. Read the following concluding paragraphs from his article:
For those three gracious members of my audience who are still with me at this point, I hope you’ve learned something or rethought something. I hope that thinking about boring first-year computer-science stuff like how strcat and malloc actually work has given you new tools to think about the latest, top level, strategic and architectural decisions that you make in dealing with technologies like XML. For homework, think about why Transmeta chips will always feel sluggish. Or why the original HTML spec for TABLES was so badly designed that large tables on web pages can’t be shown quickly to people with modems. Or about why COM is so dang fast but not when you’re crossing process boundaries. Or about why the NT guys put the display driver into kernelspace instead of userspace.
These are all things that require you to think about bytes, and they affect the big top-level decisions we make in all kinds of architecture and strategy. This is why my view of teaching is that first year CS students need to start at the basics, using C and building their way up from the CPU. I am actually physically disgusted that so many computer science programs think that Java is a good introductory language, because it’s “easy” and you don’t get confused with all that boring string/malloc stuff but you can learn cool OOP stuff which will make your big programs ever so modular. This is a pedagogical disaster waiting to happen. Generations of graduates are descending on us and creating Shlemiel The Painter algorithms right and left and they don’t even realize it, since they fundamentally have no idea that strings are, at a very deep level, difficult, even if you can’t quite see that in your perl script. If you want to teach somebody something well, you have to start at the very lowest level. It’s like Karate Kid. Wax On, Wax Off. Wax On, Wax Off. Do that for three weeks. Then Knocking The Other Kid’s Head off is easy.
Go here for the original article: http://www.joelonsoftware.com/articles/fog0000000319.html
:-)
Too rigor, mathematicians are!
A meticulous mathematician, a sloppy physicist, and an even sloppier astronomer are on their way to Scotland. They cross the border and observe a black sheep in the middle of a field. ‘Look,’ exclaims the astronomer, ‘all Scottish sheep are black!’ The physicist responds, ‘No, no! Some Scottish sheep are black!’ The mathematician shakes his head, takes a breath and proclaims, ‘Gentlemen, all we can truly say is that in Scotland there exists at least one field, containing at least one sheep, at least one side of which is black.’
:-)
Everyone has someone to envy at !
Quite frequently I used to compare myself with others and think “I am not as good as X”. I used to think “I’ll be happy if I can perform like X”. But it looks like even if I reach the level of X, there will be another ‘X’ with whom I will be doing a similar comparison. And guess what? I’m not alone :-)
I was reading an article on Richard Borcherds, a field medalist. This is what he says:
“I wasn’t getting very far. Most of the time I was struggling to keep my job. I’d see other people my age, such as Simon Donaldson (1986 Fields Medallist), being considerably more successful, and I thought I’m obviously not all that good. There were times when I thought of dropping out.”
This shows one thing. No matter however great you are. You will always have someone you envy!
:-)