That's a good rule. I usually declare variables as close to their intended scope of use as I can get them, so for instance, right inside the block where the variable is going to be used.
The temptation then becomes to re-use the name but I avoid that to make it easier to see which declaration belongs to which variable.
Declaring all the variables at the top of a function was a pretty hard to break habit.
I tend to do the same thing. Except, since JavaScript doesn't have block scope, it all ends up at the top of the function.
Which is much more preferable than scattered around the function. Especially due to hoisting[1].
My functions typically go in the order of:
declare variables;
declare any local functions if necessary (most of the time these eventually get refactored out to somewhere else, because they tend to be one-off utility functions that can be abstracted);
do stuff;
return value.
It reminds me of Rob Pike's "Notes on Programming in C", where Pike takes frequency into account as guideline, i.e. "A global variable rarely used may deserve a long name, maxphysaddr say" [http://doc.cat-v.org/bell_labs/pikestyle - Variable names paragraph - a nice and suggested read].
Here is a quote from that essay that says it much clearer than my pithy 'guideline':
"I prefer minimum-length but maximum-information names, and then let the context fill in the rest. Globals, for instance, typically have little context when they are used, so their names need to be relatively evocative. Thus I say maxphysaddr (not MaximumPhysicalAddress) for a global variable, but np not NodePointer for a pointer locally defined and used. This is largely a matter of taste, but taste is relevant to clarity."
for what concerns capital letters, from the essay I cited before [http://doc.cat-v.org/bell_labs/pikestyle]: "I eschew embedded capital letters in names; to my prose-oriented eyes, they are too awkward to read comfortably. They jangle like bad typography". As Pike acknowledges this is just a matter of taste.
The progression in your list of 'safety net' investments is 1) Cash 2) Savings accounts 3) Certificates of deposit
4) Bonds. That last step is a doozy. Considered this coursely, BND is perhaps appropriate. But it is hardly 'safe'. I think Taleb's idea of safe is more oriented toward catastrophic events. Think LTCM, Asian crisis, S&L, unregulated derivatives.
Well, T-Bills, of course. Short term, so that you don't get stuck when interest rates rise. TIPS are another thought.
You're dismissing lots of conservative/safe alternatives because they don't yield much. But that's today. Next year, 5 years, 20 years, who knows? Today, maybe the best thing is to sit back and wait for better conditions, versus take on risk.
Overall, I thought your discussion of "why invest" was too brief. You don't actually need to invest/gamble your money. Just save it (T-Bills, etc) and work to make enough.
If you've got a pile, why invest? What's the possible use of doubling the size of your pile? Can't buy any more stuff. But if you lose half your pile, it might seriously hurt.
As the next guy mentioned, I'm also not sure about BND - or bonds in particular - as a good safety net right now.
With the U.S. as heavilty-leveraged as it is now, if the past is any indicator, we're headed for inflation. For the same reasons that we got into this situation in the first place (people buying more home than they could actually afford). Look at the debt-to-income ratio of the country (deficit-to-GDP), and it's a parallel story to the housing boom.
That being said, at current valuations, are even precious metals safe? Who's to say?
I'd be interested in looking for an ETF that trades in TIPS - while the return is almost certainly less, the security offered by it is almost certainly more.
Otherwise, you and I see pretty much eye-to-eye, except I'm more heavily invested in stocks right now (mostly because lots of people over the past few years have been running the opposite way - another Buffett-ism). Nice post!
This is a noteworthy objection, and applies to much of Harvey's course at Berkeley as well. I think the rationale for his approach is so that student's don't get tripped up by using only math examples.
Several people have brought up HTDP, which is very much in the same SICP-inspired vein as these other books in the list. I personally find it to be different enough from SICP as to not be considered a precursor to SICP. YMMV.
If you "did" this book at the age of 14 and came away with the idea that it was about "hard" math, your learning/time ratio might not have been as high as you imagined.
I know the book is not about math (in fact I'm a math major now so I think I know what math is about ;), it was just that the mathy things were the hardest for me. For example understanding the O(log n) algorithm for fibonacci, the square root algorithm, series, exponentiation algorithm, newton's method, etc (especially since I had no idea what a derivative or exponentiation was). I suspect programmers with little math training will have similar difficulties.
I think one of the wonderful qualities of SICP is that a determined 14 year old and an experienced programmer can both get a lot out of it. I also think the difficulty of the text is generally overstated.
The downvotes to my response to his self-proclaimed precociousness indicate that others find my implication to be 'irritating' as well. However, anyone who is bogged down in the math would most certainly benefit from the sources in this list, many of which are explicitly prepared to avoid the math difficulties. SICP is not the place to learn basic mathematics, and it seems to me that it would be distracting from their message.
The 'us too' quality of that blog post is disturbing. They don't need to defend their architecture choices against people who naively assume that OO is an appropriate paradigm for all domains. The list of how 'design patterns' are really in there somewhere is particularly off-putting. I didn't like developing for Drupal, but I certainly support their right to do the things in the way they think is best for the problems they are trying to solve.
Ditto that. My first programs were in assembly on the 6502, and I'm thrilled to see it getting this attention. I'm just sorry that I don't still have the KIM-1.
I was planning on buying a KIM-1 when my dad surprised me by buying an Apple II. I didn't end up writing anything in assembly on the Apple II, though. My first assembly language was IBM-370 in college. I wish now I had started with the KIM-1, though.
The premise of RWDWS is flawed by assuming that the secondary market in stocks is 'free'. This book was published in 1973, and after the 'analytic' schemes of the 1960s (and continuing in the 70s), it had obvious appeal. What it did not account for was government manipulation of financial markets through (de)regulation. For example, the Monetary Control Act of 1980 and the expansion of IRA coverage under ERTA in 1981 opened the flood gates to the securities markets and intensified the Ponzi-scheme nature of securities 'investing'. Prior to the publishing of RWDWS, it is reasonable to claim that the stock market was a arena for transferring risk, not pretending to be a savings institution. Something else to bear in mind is that there are little or no real alternatives to 'funds', and this exaggerates the influx of capital into them. The idealized view of stock and bond trading fails to fully account for the transaction costs, which are largely hidden, and this 'vigorish' makes it a losing game eventually. The costs associated with funds ('index' or otherwise) are also carefully and skillfully masked, but it is easier to market the diversification arguments. There's a reason that the 'financial industry' is so profitable: http://chartingtheeconomy.com/?p=665 It's an increasingly elaborate wealth transfer mechanism.
You need a bootstrap. Ideas for libraries come from writing applications. If you can't get some sort of app started, you aren't going to have any ideas that should be distilled into a library.