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.
yawn4life!
Some things dings and other stuff that comes left.
Personal thoughts, tutorials, rants, and blah from Ben
Sunday, May 19, 2013
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
Ben
- 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.
- 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.
- 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.
- 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)
Ben
Friday, April 26, 2013
When days are insanely busy
As the number of things to do each day increases faster than you can hope to get them done, the only hope is that better time organization will help you survive those days. Unfortunatly, there is only a limited amount of time organization possible. At a certain point, if there isn't any time, then there isn't any time.
Here are some things to do if organizing time does not work
Here are some things to do if organizing time does not work
- Push it back. If it does not need to be done immediately (and there are other tasks with greater priority) then there is no point in getting it done early.
- Use google calendar. Place every task you need to do as a calendar event. Set a time for each task and it's approximate length. To avoid a domino effect if one task takes longer than expected, give every task slightly more time than you hope to complete it with. Follow your calendar as closely as possible. Try to multitask. For example, if you have to read, do it on the bus rather than at a desk, when you could be working on something that might require a desk.
- Delegate. There are other people out there. Don't do the work of 5 people on your own.
- Double check. Are you sure you have to do all of this? Make sure that there was no miscommunication before wasting hours of your precious time.
Friday, April 19, 2013
Sunday, March 24, 2013
Java can get annoying
There are times when Java is wonderful, such as its cross platform-ness and its garbage collection. Then there are times when I feel that there could be some ways to improve Java.
Before I go about talking about all of Java's shortcommings, I just want to say that Java is pretty well done. Compared to languages that came before it, Java is a lifesaver. It's also the reason we have C# (for all the people in Microsoftland) and the reason we have all of those strange languages that decided to run in the JVM (for all of the people who put up with Scala and JRuby). Overall, it is the language that people like to ask about, since it is the one that people know about. The syntax is clear, and it doesn't have 3 trillion ways to print out a single line of text. Even so, there are times I wish Java was better.
Before I go about talking about all of Java's shortcommings, I just want to say that Java is pretty well done. Compared to languages that came before it, Java is a lifesaver. It's also the reason we have C# (for all the people in Microsoftland) and the reason we have all of those strange languages that decided to run in the JVM (for all of the people who put up with Scala and JRuby). Overall, it is the language that people like to ask about, since it is the one that people know about. The syntax is clear, and it doesn't have 3 trillion ways to print out a single line of text. Even so, there are times I wish Java was better.
- Consistency. String and array use length when you want to determine their length. On the other hand, the List interface uses Size. Please choose one or the other, I don't like to have the compiler spew errors about such pointless subtleties.
- JRE. If you make a application with Java (and you are mainly developing for windows), its a pain to make sure that the user can run your application. Hopefully, they will have the same version JRE as you did when you compiled it. If not, the application might not start. So you decide to bundle the JRE with your application, but that seems like a strange extra step for a language that you "write once, use anywhere"
- Parsing JSON. Regardless of the parser that you choose to use, you will either get a zillion warnings or cast everything until the apocalypse. The compiler has no faith in the programmer that they got the type right, and is determined to save humanity by refusing to compile until every last 'error' is addressed. What a nightmare.
- Generics. I understand Java's reasoning with generics, but I still wish it was done better (like in Scala) Due to the way java separates primitives and objects, some classes contain one method for all objects as a parameter, and then a zillion different methods for int, float, double, long etc. Wrapper classes are also necessary if you want to place an int into a List. While they have made substantial improvements regarding how they wrap and unwrap the primitive, it's still rather inconsistent to type List
rather than just List . Sure, it tells the coder that the List is actually storing Integer wrapper objects rather than ints, but I don't think that will cause anyone to reconsider how they write their code. It would be a nice note to make in the docs, but not something that anyone really cares for. - Security. You've read the articles. I don't need to say anymore.
Friday, March 8, 2013
The new way to think of code
Let's face it, coding isn't hard. The only part that confuses people is the syntax. But that's the least important part about coding. Coding is about creation. It's about making things that can have everlasting influences in your life as well as the lives of other people. Like spoken language, we don't learn it simply to be able to speak proper grammar and make cool sounds with our mouths. It's about communication. Coding is a form of communication with the computer. You have to interact with it, understand it, and hopefully utilize it's ability in useful and novel ways. In fact, the snippet below might as well be a programming language. (Please please please do not make a programming language based off of this)
Eat (1) mangoThat's it! You see, the syntax is not the part of concern! Learning basic code is a fairly trivial task if you put it into the right mindset. It's a shame that more people don't think this way.
Eat (1) mango
Eat (3) mango
Take (6) hour nap
Wake up (eventually)
Power
In the physics world, power is simply the energy divided by the change in time. Sadly the rest of the world isn't really interested in this idea.
There's something alluring about power to people. Maybe its the shiny bars of gold that sit around in some of the world's largest gold reserves. Maybe they just like seeing other people miserable. The odd thing about power is that we all think it would make our lives better but we have neither empirical nor scientific evidence of that ever happening.
It's strange.
Subscribe to:
Posts (Atom)