I am looking forward to your stories.
I would like to share a quote from a post I read today, as an outside confirmation for what I always emphasized in my class: only worry about efficiency when you need to.
You can find it here : http://www.ibm.com/developerworks/linux/library/l-clear-code/?ca=dgr-FClnxw01linuxcodetips
Enjoy!
Tip 5: "Premature optimization is the root of all evil." - Donald Knuth
I didn't make up the above sentence. But you can find it on Wikipedia, so it must be really smart.
Unless you are trying to make people suffer, your first goal, when writing code, should be clarity. Simple code is faster to write, faster to understand when you return to it later, and faster to debug.
Optimization is the enemy of clarity. Sometimes, though, you have to optimize. This is especially true in games. However, and this is the vital point, you almost never know what you need to optimize until you actually take your functioning code and test it with a profiler. (A profiler is a program that watches your program and figures out how much time it spends using different calls. These are awesome programs. Find one.)
Every time I've optimized one of my games, I've invariably been blown away. The code I was most worried about was always fine. The code I'd never thought about was slow. Because I had no idea what was fast and what was slow, all optimization time I had spent before getting actual data was wasted. Worse than wasted, in fact, because it tangled up the code.
This is a hard rule to follow. Heck, if it were easy, it wouldn't have to be a rule. Good programmers tend to be offended by clumsy code that could be faster.
But rejoice! After preaching about how you should spend more time doing this and more time doing that, this is one rare, precious moment when I'm saying that it's okay to be lazy!
Write something that is clean and works. You have all the time in the world to ugly it up with optimization later. But don't do it until you're sure that you're doing the right thing.
1 comment:
It's very quiet here. I found a interesting question the other day.The question is:
Partition X={1,2,...,16} into two sets of equal sums, equal sums of squares,
and equal sums of cubes. Here's a formal statement of the problem:
find a subset A of {1,2,...,16} that satisfies the following three
properties:
o Sum_{a in A} a^1 = Sum_{a in X \ A} a^1.
o Sum_{a in A} a^2 = Sum_{a in X \ A} a^2
o Sum_{a in A} a^3 = Sum_{a in X \ A} a^3.
Somebody said that this problem can be solved by using recursive. Any suggestions?
Post a Comment