Subscribe. Follow. Stalk.

Wednesday, May 29, 2013

Why Recursion is Bad (shorter version)

Recursion is where you try to attempt a problem, give up, and let it try again...

Sunday, May 19, 2013

Recursion is bad

Before crazy people start sending me threatening emails, I agree there is a time and place where recursion is probably ideal (Quicksort?) That being said, its better to use other options where possible. (Please do not do binary tree problems iteratively. Ok Carry on)

Repeat after me. I will never use recursion unless there is no better alternative. There are times when recursion is a necessary evil but it's an evil that should be avoided wherever possible.

Recursion eats up memory on the call stack. Every time a function is called there is going to be an overhead associated with saving register values into memory. This adds up fairly quickly when doing recursion. Since the compiler cannot really optimize recursion since it can't predict how many times it will recurse that also will contribute to the performance hit. Once recursion goes too far it causes Stack Overflow, and life just sucks.

There are people out there who call recursion 'beautiful'. I personally think loops make more sense since they don't seem as weird. Making recursive code requires a leap of faith assuming that your code is doing the correct thing its supposed to do even though your not done writing it yet. (What did I just say??)

Basically recursion is bad. But if you have to use it wash your hands afterwards. You can do recursive questions with your own stack, but I don't see the point.

Wednesday, May 1, 2013

How to type faster

Once of the most common questions i have ever gotten is: Ben how do you type so fast. I generally make a joke that most of what I write is full of typos (which is true) but there are a few ways that you can type faster

  1. Keep in mind that you are trying to type faster. Often I type at only 30 wpm due to the fact that I am not really in a rush or trying to type faster. If you try to type faster, generally you will be able to type faster.
  2. Type hard to reach keys properly. It wasn't until a few years ago before I realized how much faster I could type if I simply hit the period and comma keys with my fingers in the home position rather than have my hand move down to the lower part of the keyboard and hit the key that I wanted. Other keys that are commonly cheated are the z and the x at the bottom left of the keyboard. Do those in the same manner. It will take some time to get used to, but it really is worth it.
  3. Practice. For the people who are reading this blog, this shouldn't be an issue for you. You should have a lot of opportunities to practice your typing. Type in search queries as fast as you can. Write anything - emails, essays whatever using proper typing techniques.
  4. Play some games! My personal favorite is typingtest.com They have games and typing tests alike. I usually do some typing tests from time to time to make sure that my typing speeds have not gone down and then I play a few games (my favorite is the ones with the bubbles)
Over and out

Ben