ArrayListLecture - levbrie/self GitHub Wiki

ArrayList Lecture

W1004: Intro to Computer Science in Java, Fall 2014, Professor Cannon

@author Lev Brie
G: http://github.com/levbrie
E: [email protected]

4 Pieces of Advice


  1. If at times you find what you’re learning in CS overwhelming or confusing, don’t let that worry you for even a second. It should be. Computers are by far the most complicated machines human beings have ever built, and the programs that run inside them are by far the largest, most intricate, most complex feats of engineering we as a species have ever managed to put together. There is not a single human being who has ever dedicated their lives to computer science and not felt confused and overwhelmed many many times over. Accept right now that you will be confused and you will be overwhelmed and let yourself focus on what you know now and what you can learn next. If ArrayLists feel confusing because you’re not quite sure you have a handle on Arrays, go back and take a look at arrays. Go slowly, go step by step, try things out on the computer as you go. You will not break your computer - at least not until you take Operating Systems (at which point you probably will break your computer, several times). Being good at computer science is about being good at finding the simplest smallest possible next step in your understanding and taking that one step before you take another.

  2. If you feel frustrated or annoyed by the way something works in Java or in pico or in another editor, if it feels in some way strange and arbitrary to you, good! It should feel arbitrary. There are an estimated 6000 or so spoken languages on earth ([Ethnologue](http://www.linguisticsociety.org/content/how-many-languages-are-there-world http://en.wikipedia.org/wiki/History_of_programming_languages) lists 6909). Every one of these langauges took hundreds and often thousands of years to develop. Already there are over 700 well-known programming languages. The first programming language was created in 1842 (get actual number) programming languages. Every other programming language we know of was created in the last 80 years. Most of them have been created in your lifetime, and nearly all of them have been created because people just like you felt frustrated and annoyed with the programming language they were working with at the time. Programming languages are built on mathematical laws just as computers are built on the laws of physics. But the form they take is by definition arbitrary. They are the inventions of some 1 or 2 or 10 human beings and as good as they may be at solving certain kinds of problems or expressing certain kinds of ideas, they are bound to be bad at solving or expressing others. They are also bound to look strange and feel frustrating at times - especially if your mind is just getting accustomed to computer languages in general. There are things about them that look just like natural language, but they are not like natural language. You can’t make grammatical mistakes in programming languages. If your syntax is wrong, your program will not work correctly. If your logic is even slightly off, your program will not work correctly. If you don’t quite understand how to construct something, or share a piece of data, or where you are in an array when you make a calculation, your program will not work correctly. As I’m sure you’ve already seen, there’s a very good chance it won’t work at all. So if it feels frustrating and arbitrary, don’t think you’re necessarily missing something, and don’t think it’s not worth changing. Perhaps you’ll write a much better programming language than Java yourself some day. But don’t give up on programming because of it, and don’t give up trying to understand Java just because it seems arbitrary. There's a very good chance that some of your frustrations are justified, but there's an even better chance that you're missing something. There are things about every programming language that are clunky and awkward, but there are many more things that are elegant and even quite beautiful. Programming languages are difficult, but they are also extraordinarily powerful, and they are absolutely worth every minute of effort you put into them. You may end up writing a language that's better and even more popular than Java someday, but I can guarantee you that the only way you can ever hope to that is to keep at it until you start to understand Java and why Java works the way it does. What it takes to be a great engineer is the same as what it takes to be a great student is the same as what it takes to be a great entrepreneur: the willingness to delay gratification, to persevere through frustration and confusion and annoyance for the sake of learning or understanding or creating something truly valuable. Accept your confusion, accept your frustration, slow down, take a deep breath, focus on understanding just the one thing you have in front of you, and continue to work at it. Today, tomorrow, for hours and hours and hours. Do each thing until you really understand it, take in each concept one by one and don’t worry about the thousand things you’ve got in your head that you don’t yet understand. If you choose to continue with computer science, there will always be a thousand things in your head that you don’t yet understand. But eventually, there will also be thousands and thousands of extremely powerful, extremely useful things that you do understand.

  3. There are a million things you can be learning at any time. Focus on the ones that matter most. You could spend the next 3 weeks just learning about Eclipse. You could spend 200 hours just starting to get really good at Vim. I have, and I can’t tell you how glad I am that I did. But you definitely should not spend the next 200 hours getting good at Vim, or mastering Eclipse, or learning some other programming language. Focus on Java, focus on trying to understand object-oriented programming as Professor Cannon introduces it to you, and trust that doing this give you the absolute best foundation you can get both in this class and as you move forward with CS. Doing that is what matters the most right now.

  4. Take the absolute smallest step you can take at any given time. When you're coding, it can be very difficult to figure out what you did wrong when a program doesn't work - especially when you're first starting out and the stack trace you get back looks completely incomprehensible. Make things as easy on yourself as possible. Do one tiny thing, recompile and rerun your program and make sure it doesn't crash. Do one tiny thing, recompile, and rerun your program. Make sure it doesn't crash. Check that it's doing what you expected it to do. Do one tiny thing... Repeat, repeat, repeat... I'm going to show you how I go about doing that in my lecture today. I'll take about 10 minutes to introduce you to ArrayLists, another few minutes to compare them to Arrays, and then we'll get write into coding, from scratch, our own ArrayList implementation. I'll do it fast, and there will be a bunch of stuff that you don't quite understand, but focus on what you do understand, and focus on the process. We'll almost never write more than 3 lines before recompiling and rerunning, so we'll always have a very good idea of what's going wrong. Do this for the rest of this semester. In fact, do this, all the time, for everything in your life, and you will go very, very far.