Minor quibble. Your 401k plan almost always has more fees than index funds at someplace like Vanguard.
1. Contribute to your 401k to get your entire company match.
2. Then max out an IRA, a Roth IRA, or a combination of the two based on your income level.
3. Only then continue to max out your 401k.
Your income, your 401k match, and your ESPP are all tied to your employer, so as long as things are good, ESPPs can be a great way to make easy money, but if things take a stark downturn, you can find yourself with ESPP you lost money on, a slouching 401k, and no job. The chances of that happening are fairly low, but still something that makes me a little uncomfortable about ESPPs.
Obviously your advice to max our 401k/IRA contributions first should mitigate a lot of this, but I think it's important to mention the risk too since there's a certain temptation for younger engineers who think it sounds like easy money and don't realize the full implications of it.
This is certainly not true for all companies. I lost over $100K due to our Employee Stock being driven into the ground over the course of a decade by a CEO and board who had loose ethics and no business running a company.
My advice is, before investing in you're ESPP (or Employee Stock Ownership Plan - ESOP), even if you're surrounded by exceptional talent, take a close look at your corporate leadership before purchasing. If they seem sleezy and disingenuous, they probably are and it may be 10 years before you realize you've been totally screwed.
I told the accountant, who I always found watching CNBC in the break room and I suspect still dreamed of being a day-trader, that the best investment I ever made was our company's ESPP (Employee Stock Purchase Plan).
He said, "You know what? Same here."
(Standard disclaimer: max out your 401(k)/IRA contributions, first.)