Ask HN: What did the really successful programmers do differently?
http://news.ycombinator.com/item?id=4611337 http://news.ycombinator.com/item?id=4620276 http://news.ycombinator.com/item?id=4616635
As someone who is definitely on the path to be developing software for the rest of his life, I'm somewhat concerned. There are many anecdotes of programmers in their 50s having a pretty bad time, and yet there are real examples out there of programmers who have done phenomenally well: they've made a difference, they're well known and respected AND they've been financially successful as well.
I'm thinking of (contemporary) programmers of the caliber of John Carmack, Rich Hickey, Peter Norvig, Jeff Dean.. I'm trying to understand what it is that they did differently from everybody else that set them apart. I understand that many have been successful through their ventures (see Bill Joy or Eric Schmidt), is that perhaps the only route?
I think this is an interesting and valuable discussion for every developer out there.
177 comments
[ 3.9 ms ] story [ 129 ms ] threadIt's about knowing where you want to go, what you want to achieve, and be able to focus enough to go there. Vision + Execution.
For me focus is at the same time "fast and slow".
You have the focus on the long term vision of your career, products etc. That means, yeah, probably choose between your 10 projects. But again, it depends the goal you set yourself concerning those 10 projects. If you're a pragmatic OSS commiter ("I commit the changes to this lib' I really need for my main product"), then 10 projects is okay.
Then You have to focus, during your day to day work. Where do I head with this feature? What do I want to achieve? What problem am I trying to solve here? Did I think about all the edgy cases? Did I test everything? Is the code better now than before? etc.
It's hard work.
Be Driven, Be focus.
There is nothing you can do that will make you remain interested and excited and passionate about something for decades.
Because I'm one of the success stories, I'm in a position to answer. A successful programmer is not just a programmer, he is also a personal representative, a salesman and a contract negotiator.
I originally wrote what became Apple Writer (http://en.wikipedia.org/wiki/Apple_Writer) because I was writing a technical magazine article that was difficult to organize. I finally realized I could use my newly acquired Apple II to organize my disorganized notes and help in editing. So I divided my time between writing the article (about Special Relativity) and programming my Apple II to help with the writing task. This meant I was the first user of my program, and I was a demanding customer, a factor that helped the project along.
Eventually Apple heard about my program (originally called LexiCalc, a name meant to remind people of VisiCalc) and, having far too few programs for their computer, asked to see my program. After a lengthy negotiation in which I demanded and secured a 25% royalty rate, we had a deal.
The bottom line -- Apple Writer didn't become a success only because of my programming skills. It became a success and a household name because I was able to negotiate a royalty marketing deal with Apple that served both our needs. The fact that a 25% royalty rate was excessive, was unknown to either me or Apple at the time of the original negotiation, and by the time we both realized it, I was unwilling to change the terms.
To reiterate, programmers that become successful do it by having skills beyond programming -- they know how to present themselves, they know how to negotiate, and they earn a reputation for reliability.
Yes, and business people and managers who have technical skill and knowledge possess the advantage that they can detect when programmers are lying to them or exaggerating, and they can schedule realistic programming project times. Nothing is worse than a manager in charge of programming projects who doesn't understand programming.
Programming + Biology. Programming + Economics. Business + Comic book writing. Programming + Business. Cooking + fluency in Japanese & English. You get the idea.
Exactly. I was fortunate enough to realize this early on in college. Since that realization I've always made the effort to straddle the tech and business side. Programmers, even average ones, have the ability to multiply business effort by orders of magnitude. Look around in any business and even today it's easy to find places were software can help.
Apart from those, being able to build the right app at the right time helps too.
I think one could make several distinctions about "being successful" though:
* You're good at it, and you're still employed at 50.
* You strike it rich, so you can do whatever you want at 50.
From what you write here, you're in the second category. Given the odds of striking it rich though, I hope people post about type #1 programmers too.
http://arachnoid.com/MySQL
http://arachnoid.com/python/DBClient
And in the summertime I travel around by boat in Alaska:
http://arachnoid.com/alaska2012
So being a good programmer is not synonymous to having your bank accounts with decent zeroes following some non zero number.
Incidentally, yesterday I was talking to a programmer who had been coding for 17 years, he codes bots for games in C++ when not coding other stuff. He did not take his degree seriously, and today is looking for an MNC to hire him, so that he gets married, for the chic wants a secure life.
What did the good programmers do differently? Its a difficult question to answer. Having said that, couple of things are:
1. starting early
2. getting lucky
3. focus and hardwork
4. marketed themselves properly
5. surrounded themselves with better programmers, to get better at it.
6. capitalized on the opportunity of solving a tough and challenging problem.
ending on a pragmatic quote: passion burns out, what sustains is greed. (taken from "Do you want to be doing this at 50")
There are a lot of guys making $250k or more working on some obscure B2B product or enterprise team somewhere. Just because we don't hear about them doesn't mean they aren't just as happy or find as much meaning in their work, and it's certainly a lot easier to optimize for if that's what you want.
That said, I think programming is a bit like a professional athlete in that you can't have a great lifelong career by sticking purely to the technical aspects. You need to be learning how your skills apply to real businesses and building your network. Fortunately I think these things happen naturally to some extent, but it can't hurt to think about them.
I'm going far than this and say are two OPPOSITE things. Being good a 1 thing is hard. Good at 2 things? 3 things? Rare. That is way is easy to have Teslas, but not Bells...
I know a lot of developers in the latin america community, and mi city (www.clubdelphi.com). Here, is VERY rare to find the super-rich, mega-startup anomaly (yes, it is). We can do the hard work, have competent skills and still survive. I don't see highly tech people being good at the art of make money (the lack of social skills hurt a lot!), and the time necessary to code + doing business is a big drag.
I have a partner that help in the sales side. Without him, I can't see how I can code and get client in a steady way (the economic realities here are differente to USA: Have FACE TO FACE is DAMM IMPORTANT!, internet-only business? close to impossible), and I'm lucky for that. A lot of my peers are code monkeys, even the good ones...
I'm not sure if you've heard about the concepts of Structure and Agency [0] in sociology? Consider the importance of: (1) being able to go off the beaten path to chase a new way of thinking/working or an idea which can improve many other people's lives, and (2) being in a company or position which gives an increase in high-value opportunities.
In any case, forget about just being a standard developer if you want to reach this level of impact. You own neither the platform on which you can reach a large group of people; nor the intellectual skill, anti-authoritarian outlook or vision required to create at a standard that sets you apart from your peers. There is something qualitatively different here from the careers of normal developers.
By the way, the ease of defining these qualities actually means it's not so hard to go about reaching them. If you can engineer software, you can engineer your career.
[0] http://en.wikipedia.org/wiki/Structure_and_agency
Great folks I've met are high on productivity, they are quick in discovering things and generally maintain an aura of self confidence around them. Many of them start off because they a 'lucky break' somewhere but they build on it, they work hard and make their own space.
When we are talking of successful guys out there. We are ideally talking of guys who are >40 now. I know a relative of mine highly successful 40+ guy. Some of the things that I've noticed is, he is insanely hardworking, nearing 50 he can give any 20 year old run for his money. He is productive, doesn't blog much, not very active on social media. Doesn't go gaga on small wins, he has great focus on picking and solving tough problems. I mean problems that can add real great value.
A few things that I've noticed is he is agnostic to tool religion. He goes by what helps him, rather than our usual religious tool affiliations. He is also very well organized.
So to add it up:
1. Work really hard, I mean I literally. No excuses on this point.
2. Focus on solving tough problems, adding value and things that matter. Learn and master things that can help you solve problems. But there is no such a thing called 'permanent' technology. You have to learn to move on, because tools help you solve the problems. They are not your problems you would want to solve. Unless selling tools is your business.
3. Technology matters, but that is only a enabler.
4. Be a little disciplined and organized.
5. Celebrate big wins, write and talk about them. Network with people just like you and surround yourself with smart people.
6. Work hard on opportunities and always keep a tab on your next move. The more opportunities you convert to finished work the more you get next.
I like your post and this isn't meant as criticism, but ... could we not say "guy" so much? Women are often terrific programmers, and there should be more of them. But that goal is thwarted by a certain common assumption about who programmers are.
> A successful programmer is not just a programmer, he is also a personal representative, a salesman and a contract negotiator.
Yes! Just do things with the right tools.
1. I think my best quality is that I'm lazy. Extremely lazy. Yet still very productive. I achieve this by thinking more about problems before I do anything, which usually greatly reduces the amount of work I actually have to do, because I come up with a better way of doing it. I'm extremely serious here; on a normal working day I'll likely spend more than 50% slacking. My clients don't care, they get charged only for the effective hours. And I love it, because the effective hours become so much more productive that I can charge a lot for them.
4. This matters a lot, especially in communicating to other stakeholders. Nothing is more annoying than someone who promises to do something by date X, only to not hear anything by then.
6. Extremely true. I talk to a lot of people to find work, and generally have a ratio of 10:1 for possible opportunities to things that actually lead to real work. I don't think I can improve this ratio much, because really interesting work is not that readily available.
I'm also not very active in the blogosphere and social media, mostly because that's simply not where my work comes from. My work comes mostly from business people and they care much more about recommendations, being able to talk to them in language they understand, etc.
http://news.ycombinator.com/item?id=4626349
I'm sure it's far from being that bad for programming, particularly if your main goal is to not end up miserable. Still, for every one John Carmack, I'm sure there are a 100 or a 1000 people as skilled and as hardworking, but who don't have the same amount of recognition.
They might have rather cushy jobs at some obscure R&D lab though. Which suggests a third question: What kind of people without widespread name recognition should we also be asking the "what did they do right" question about? It's easier to start thinking about John Carmack instead of Joe Q. Senior Systems Development Fellow, but that primes you for the somewhat wrong goal of trying to get massive name recognition in addition to the not ending up a miserable programmer one.
Einstein said something like "I owe many of my achievements to my persistence, not letting go of my goal until I achieve it" (Nash proved later that keeping to a strategy [= persistence] increases chances of winning a game), and Feynman has been known as a big advocate of the scientific method per se. Again, hard to say whether they owe their Nobel prizes to these methods, but I like to think that they helped.
Methods are actions gone habits. If you force yourself to think "Is this really right?" before coming to a conclusion, you will soon do it automatically. As a programmer, you could build up the habit of understanding the system you are currently operating in, before fixing or enhancing a part of it. Or you could write a pseudo-code script using your API (or testcases ;)) before implementing it, to get a grasp of what your users will actually use it for. You can make it a habit to blank out program areas in your mind which you don't currently need, to reduce cognitive load and turn a greater focus on the problem at hand (which will also enforce modularization automatically).
There are many such methods (also including getting more focus out of your worktime etc.), and they can become habits if you execute them for long enough. Habits are everywhere, and the (IMO) most crucial ones are hidden in how we think, and our thoughts eventually ensue our actions.
Working with software is like poker. If you aren't playing with real money, it gets boring quickly. Programming is fun if you have "skin in the game"-- a decision where you want to see if it was the right one, a problem you want to solve-- and it's mind-numbingly boring if not.
You need, somehow, to ensure a reliable stream of high-quality work. You need to become that guy who moves from machine learning to self-driving cars to new language development while the unlucky saps are trying to swing from an HR app led by a Manager II to an HR app led by Manager III.
I don't want to trivialize this, because getting high-quality work is really fucking hard. There just isn't much of a budget for it, and usually getting the best work involves manipulating the politics, especially when you're young and not "obviously" qualified for it yet. Good work tends to be R&D stuff where up-or-out business people who will be promoted or gone in 4 years can't see the payoff. You often have to take a mercenary attitude toward transfers and job changes and, if your boss isn't personally interested in your career growth, balance out the universe by stealing an education. Most people learned how to program by doing something other than what they were supposed to do. This doesn't change when you become a professional programmer. Good programmers tend to put their own development over business goals-- "optimizing for learning"-- because otherwise, they wouldn't have become any good.
People talk about "5:01 developers", but I've started to think of myself as a "1/21 developer". I expect to grow the value of my programming skill set (and indirectly, my earning potential) by 1% every 21 days. It doesn't have to be coding only. Improving social skills or business knowledge can easily account for such an improvement. I make that rate of growth (more as metaphor and guideline than hard lower bound, because it's impossible to measure such a quantity precisely) an almost inflexible primary constraint, as important as (a) getting done what I'm told to do, (b) showing up on time, and (c) not being offensive at work. None of these get slack except in extreme circumstances, so why should my learning rate?
1 percent every 21 days might not seem like much-- it's incremental change as opposed to get-rich-quick bullshit-- but that's a doubling every 4 years, or a factor of 32 in two decades.
What I think is getting much harder is consistently putting yourself forward as a person who deserves the best projects. As the number of frameworks and languages increases, we're getting curse-of-dimensionality problems. Being seen as a good programmer (which is increasingly different from being one) is an artifact of terrain knowledge, these days, more than general competence. This makes political battles around tooling a lot nastier, because the stakes are so high.
I think the way out is, for now, to establish a credibility in something other than engineering-- statistics, business, design. Hence the X-Who-Programs vs. Just-A-Programmer phenomenon: http://michaelochurch.wordpress.com/2012/08/26/xwp-vs-jap/ . If you're a software engineer and nothing else, your place in the pecking order is unsafe because of tool-sensitivity, so you need to diversify into other areas of knowledge.
An addition to your proposition that you needs make your decisions in order to improve: You also need to actively learn from your failures. Many people just go like "That sucks, it did not work out" without ever asking the Why. That's not enough to learn, and one could even learn the wrong lesson from a failure.
Agreed. 21 days is a good audit point. If you can make the case to yourself that you've improved the total value of your skill set by 1 percent, then proceed normally.
This is equivalent to 19% per year. That's measurable if you pay attention to market trends. Keep in mind that if you stick with one job, you're likely to bank only half of that increment. You probably won't get 20% pay increases unless you work for yourself (in which case your expectancy might go up by 20%, but you have a lot of volatility). You'll get 6 to 10 percent per year. It might still be worth it to stay in the same job, if you feel like you're learning a lot. Part of the reason why the pay improvement is slower is that the best engineers tend to prefer more interesting work (and stability, as they get older) over aggressive salary growth.
Here's a scale for software engineering: http://michaelochurch.wordpress.com/2012/01/26/the-trajector... . Each 0.1 increment seems to be about a 26% increase in abstract business value (or a 10-fold increase per 1.0) and about an 8-15% increase in salary. You should be aiming for 0.1 every 18 months, which is hard but doable, although it usually requires pushing back at work sometimes.
An addition to your proposition that you needs make your decisions in order to improve: You also need to actively learn from your failures. Many people just go like "That sucks, it did not work out" without ever asking the Why. That's not enough to learn, and one could even learn the wrong lesson from a failure.
Absolutely. No disagreement there.
Unless you want to define "really successful" as really good (which is subjective) or popular and then the answer is obviously to be really good and make something popular. Oh and try to make sure to get the timing right. ;)
For example, my cursory read of your list of programming success stories plus "they've made a difference, they're well known and respected" suggests that you might care about your status among geeks in particular. There's nothing wrong with that, but it would counsel very different career moves than if you cared about your status among "the typical person who reads the New York Times." You might, for example, aim your moves towards a high-status industry that skews geeky (like, say, videogames, which is across almost any other axis a terrible place to work), startups, advertising firms which employ anomalously high number of PhDs and get disproportionate love from geeks, etc etc, and away from where many extraordinarily talented programmers are likely to work (in a dark hole writing important code that the world will never know or care about even though it keeps their planes in the sky, moves their food to their table, makes sure that when they call 911 a phone actually rings, etc).
In terms of being financially successful? There are many, many approaches to it. Most of them boil down to figuring out how programming solves a problem for a business, quantifying that value, and then shaking the money tree.
I think HNers sometimes have an unnecessarily narrow view of the solution set: for values of financially successful which include "I don't need to be a billionaire but I'd sort of like to earn, I dunno, doctor money rather than marketing manager money" it includes things like "Run a small boutique consulting firm", "Become an individual specialist in a few very valuable things and just charge market rates for them", "Use your programming expertise to found a non-tech business and ROFLstomp on one core area of operations due to your unfair advantage", etc etc etc.
Possible answer: Learning a skill that most programmers shy away from, are afraid of, or down-right scorn, thus giving me (him) an almost unfair advantage over virtually every other programmer out there.
If you read the comment you're replying to again, you might notice it to be written by somebody who lies towards the other end of the spectrum. As such, you might as well be asking him how much he bench presses, as it is equally relevant (as in, not at all so) to the utility of the advice he's giving.
Clues:
1. It's called A/Bingo
2. It's hosted on his bingo card creator site, not on github or kalzumeus.com (his personal site)
3. People tend to link to interesting open source projects
4. The text they use in the link is usually the title of the project
5. Google uses the number of links and the link text to rank sites on keywords
This is what he means by using his coding skill against his competition in ways orthogonal to programming.
And a little more greyhat than I've come to expect from patio11
Nah.
Naming it "A/Bingo" and hosting it on his own site for the intent of garnering linkjuice while at the same time presenting the name choice as simply a guileless, clever pun (as he does in his announcement of the project [1]) and within the context of his normal policy of broad disclosure?
A little bit. Perhaps "grey hat" is too strong a word. Swap in "a little discomfiting".
[1] http://www.kalzumeus.com/2009/08/15/introducing-abingo-rails...
(To clarify, my discomfort is due to the tying together of two orthogonal axes, ie, the quality of Bingo Card Creator as a result for the keyword "Bingo" and the quality of Bingo Card Creator as a source for an A/B testing framework.)
Please name a salesperson more open and honest than Patrick. Tell us who he should emulate. If people don't emulate Patrick's style, maybe they should follow Marc Pincus or Coffeefool instead?
http://www.jcdrepair.com/blog/your-business-has-more-to-offe...
Another example, and the one that inspired me, was one of the bloggers mentioned earlier. Patrick McKenzie runs a small, online business selling bingo cards to teachers (he sold over $45,000 worth of bingo cards in 2011). One thing Patrick does really well is search engine optimization (SEO). One of his techniques for getting people to link to his site (a big part of a high Google ranking), involves open source software. “What!?” That might be your reaction right now. What does open source software have to do with bingo cards for 1st graders?
The answer is nothing. However, Patrick is a software developer that wrote the code for his bingo card website. He recognized that some of the code he wrote was valuable all on its own. So he turned part of it into an open source Ruby on Rails project, put the code up on his site along with instructions on using it, and then told the world about it. What happened? All sorts of software developers, with no interest in bingo cards but a huge interest in his software, started linking to the portion of Patrick’s website that hosted this open source project. More links to his website meant a better ranking on Google which meant more sales of his bingo card creator. So while he didn’t directly sell his offering the way Amazon sold their’s, he did use it in a way that created more business for him.
When you grok what Patrick is doing, the programming angle on it makes more sense. On HN, he's best known for Bingo Card Creator (that's the work he has the easiest time talking about). Here is the right way to think about Bingo Card Creator: it is an experiment in how much engineering effort you can apply to marketing as opposed to product features and what the payoff on that is. The engineering in BCC is invisible to users; the product itself is "hello world", hooked up to a random number generator. The result of the experiment: he matched his salary with it, and then left his full-time development job, because 5-10 hours a week of effort was paying him better than the 60 he spent as a salaryman.
Also: get past the idea that you can gauge people's skills from their Github profiles. Nerds are in love with that idea because it sure would be nice if it were true. I've been a professional developer, mostly in C, since I was ~17 years old. Only a tiny fraction of the lines of code I've written --- and virtually none of my favorite lines --- are publishable on a site like Github.
This thread was about programming, and the given comment was mere a self-assertion. So, it is OK to assert oneself if one wants to. But, show us, then, what you have done.
I you have lots to say, for instance about modeling natural language as s-expressions, you too can write lots of long comments and blog posts, and we will enjoy reading them. Unlike the short, nasty one you wrote above.
Rest assured these guys here: http://news.ycombinator.com/leaders wouldn’t be there if they could not code. Most of them have detailed profiles for you to check out first, instead of asking them ‘show me the code’ on their every comment on HN.
A corporate lawyer may produce a whole bunch of excellent work that the outside world never sees. Yet he keeps the company complaint with regulations.
If we were to do "show me the github" for stonemasons, we would want to see the pretty works of art that someone has made and select for that. But what about the guy who worked for 20 years laying the stone to keep the buildings up? He can't show off his work. But if I work in his building every day, I'm going to care a lot more that he was selected based on his ability to choose the stone that keeps buildings up than on his art.
The majority of code never sees the light of day. We are much more like miners than mathematicians in that the public cannot see our immediate work product, only the results after it has worked as a team. If you've never been hired you obviously can have all of your stuff public, but that's just selecting against people who have worked.
Analogies are hard.
Take a look at Smalltalk at Xerox PARC, AI lab and Scheme language at MIT, Plan9 at Bell Labs, Erlang at Ericsson, Go at Google, FreeBSD and OpenBSD projects, etc.
For an individual achievements - Linux 0.9, viaweb, arc, clisp, nginx, redis, sqlite, git, vi, emacs, etc.
Each particular story could be enough for learning almost everything about software engineering.
Erlang is a story of applied principles, methodology and design decisions - real-world functional programming success.
Plan9 is an example of what system programming really are, that less is really more and good is really enough.) Take a lot at src/lib
Arc is a prove of concept that lies in foundation of the "On Lisp" book - that you could evolve a language together with your software in a bottom-up process. And he did.
The story of Scheme language you could read in MIT AI memos, where, actually you could find all you need to know about programming.
Go is an example of how ideas form Plan9 and language design comes together in a unique language with unique features.
The evolution of the Lisp is another example. Systems should evolve.
And the two aspects are certainly not mutually exclusive, and by that I mean: being a good programmer does not necessarily translate into being a successful programmer. The reverse is true too.
IMHO, to nurture a lasting career as a "programmer", you have to balance the two aspects. Be good and successful.
Or, so I think.
That's also one of the reasons why I don't like the title 'programmer' as opposed to something like 'software engineer'.
(Excellent==Successful. Money & fame are more difficult to control.)
1. Choose a small subset of available technology, learn it intimately, and embrace it. Then evolve that subset.
2. Understand the pros and cons of various data structures, both in memory and on disk.
3. Understand the pros and cons of various algorithms.
4. Understand your domain. Get away from your computer and do what your users do.
5. Be ready, willing, & able to deep dive multiple levels at any time. You must know what's going on under the hood. There is a strong correlation between "number of levels of deepness understood" and "programming prowess".
6. Use your imagination. Always be asking, "Is there a better way?" Think outside the quadralateral. The best solution may be one that's never been taken.
7. Good programmer: I optimize code. Better programmer: I structure data. Best programmer: What's the difference?
8. Structure your data properly. Any shortcomings there will cause endless techincal debt in your code.
9. Name things properly. Use "Verb-Adjective-Noun" for routines and functions. Variables should be long enough, short enough, and meaningful. If another programmer cannot understand your code, you haven't made it clear enough. In most cases, coding for the next programmer is more important than coding for the environment.
10. Decouple analysis from programming. They are not the same thing, require different personal resources, and should be done at different times and places. If you do both at the same time, you do neither well. (I like to conduct analysis without technology at the end of the day and start the next morning programming.)
11. Never use early exits. Never deploy the same code twice. Never name a variable a subset of another variable. You may not understand these rules and you may even want to debate them. But once you start doing them, it will force you to properly structure your code. These things are all crutches whose use causes junior programmers to remain junior.
12. Learn how to benchmark. Amazing what else you'll learn.
13. Learn the difference between a detail (doesn't really make that much difference) and an issue (can end the world). Focus only on issues.
14. Engage your user/customer/managers. Help them identify their "what". Their "how" is not nearly as important.
15. Write a framework, whether you ever plan to use it or not. You'll learn things you'll never learn any other way.
16. Teach others what you know, either in person or in writing. You'll accidently end up teaching yourself, too.
17. Always tell your customer/user "yes", even if you're not sure. 90% of the time, you'll find a way to do it. 10% of the time, you'll go back and apologize. Small price to pay for major personal growth.
18. Find someone else's code that does amazing things but is unintelligible. Refactor it. Then throw it away and promise yourself to never make the same mistakes they made. (You'll find plenty.)
19. Data always > theory or opinions. Learn the data by building stuff.
20. At some point, run your own business (service or product). You will learn things about programming that you'll never learn as an employee.
21. If you don't love your job, find another one.
I have found that you get higher marks for saying NO in the right occasions than being known as the one that always says YES.
So possibly: If you always say NO, you never learn anything. If you always say YES, you never deliver anything.
"Never use early exits". Could you please elaborate what you mean by that?
PS. I'm not trying to unintentionally start a flame war. Just trying to understand.
A little background: I have gotten many calls when legacy code has a bug or needs a critical enhancement and no one in-house is willing or able to figure it out. I'm no smarter than anyone else, but because I'm stupid and fearless, I often do something that few others attempt: I rewrite or refactor the code first, then work on the bug/enhancement. And the first thing I always do is look for early exits. This has always given me the most bang for my buck in making unintelligible code understandable. The only entry to any function or subroutine should be on the first line and the only exit should be on the last line.
This is never about what runs fastest or produces less lines of code. It's strictly about making life easier for the next programmer.
Early exits can make things really easy (I'll just get out now.) 20 lines of clean code. No problem. Until years later, when that function is 300 lines long, and the next programmer can't figure out what you're doing. Much of the maintenance had been done in emergency mode, each programmer just trying to get in and out as fast as they could.
Early exits make it much easier for bad things to evolve:
Removing early exits forces you to understand what really should be happening and enables you to structure code into smaller, more intelligible pieces.Short, hand-wavy response, but I hope that helps clarify some. Stay tuned for a better answer...
It often goes like this:
IME, the jobs most programmers are doing don't need to try to accomplish maximum speed or need to wring a few bytes out of RAM. Certainly we don't want to be wasteful, but long-term maintainability is more important, again IME, than absolute speed or minimising memory footprint by a few (k) bytes.
Back in the bad old days when I was writing programs to run on mainframes, yeah, we did need to fight for every byte. A $5 million machine back then had less RAM and less raw CPU power than a tablet does today. We don't live in that world now.
This style has nothing to do with running fast, it has to do with lowering the cognitive load of the rest of the function. A branch means you have two states to keep in mind (the state where the branch is taken, and the state where the branch is not taken). Without early exit, you have to keep both states in mind until the end of the function just in case.
With guard clauses, you can discard on of the states (the one which matched the clause) entirely.
In the end, I'm not disagreeing with early exits per se, just that over time they can make it more difficult to understand function because assumptions about state have to adjust as a maintainer goes through the code. Those assumptions may have been crystal-clear to the writer originally but how many times is the original writer the only maintainer?
This is what I would focus on avoiding instead.
Function calls and return are like goto that obeys structure, and therefore don't have the same problems.
Knowing where you are jumping doesn't help you to make assumptions about the control flow.
Goto's are bad because they allows you to jump. The jump in itself is the problem because it breaks the instruction flow arbitrarily - without explicitly expressing the boolean condition for it. Early exits are of the same kind: they don't express explicitly the boolean condition of the jump. We know where we are jumping. Not why. With time, the boolean equation of the code which determines the instruction flow is unmaintainable. And then you end up not understand where your flow is going through, not because you don't know where a jump is going, but because you have lost why.
Most gotos, early returns, breaks and continues (C speaking) are considered to be bad habits for this reason.
return only goal is to return values to the function caller. Not to jump.
Function calls jump back to whatever call them so it's like there has been no jump at all in terms of instruction flow - you basically can continue to read the code assuming some code has been executed behind the function name.
Ouch. It will be kind of amusing if we ever work on the same code - I frequently start a bug fix by refactoring to introduce as many early exits as possible. I find guard clauses so much easier to understand than nested conditionals that sometimes refactoring it like this is the only way I can understand the code at all. I would love to see a blog post where you compare different styles.
OTOH, If you're talking about things other than guard clauses then I think we might have a much more similar viewpoint.
I'm still learning so I'd be grateful for a heads up if you make that blog post. I've put my email in my hn profile.
http://www.osdata.com/programming/loops/earlyexit.html
http://programmers.stackexchange.com/questions/118703/where-...
As a general piece of advice, this is flat out wrong. Or, to put it more correctly, this is only valid advice when using certain languages and only under certain conditions. Just because it is sound advice in languages with C/C++ derived syntax doesn't mean it should be presented as good advice in general.
Even less bad in C++ where destructors can automatically handle any cleanup (exactly that is also common practice in C++; making the cleanup implicit). Similarly in many other more high level languages with GC and/or automatic refcounting or so.
In rare cases, it might be more complicated, though.
But you seem to have some languages in mind where it really doesn't matter? What languages?
I believe that the majority of programmers agrees that using early returns for guard clauses is an okay exception.
Also, for example, when you have lots of "if" clauses, those languages force us to use mutable state (and a variable initialized as null) just to avoid early exits. But we can avoid both by treating the "if" as an expression, as in Ruby, Lisp, etc, or with the ternary conditional operator...
Plus, IMO, there are some situations where early exits are a good idea even in languages derived from C, such as with guard clauses/preconditions.
There's a nice discussion about that here with some points I made: http://c2.com/cgi/wiki?SingleFunctionExitPoint
(EDIT: I edited a lot but still couldn't make it clear that I agree with you, but I still ended up making points about completely different things, sorry about that, my english skills are lacking sometimes)
Throw away the unintelligible code, or throw away the refactor?
Good advice. So why do you give the same amount of attention to variable naming and early exits as to much higher level issues? I don't think the difference between Carmack and a random developer has much to do with adherence to coding standards.
About #17, one of my clients once told me he hired and kept me because I never outright, or in the beginning said no, and instead said 'let me think about it', or 'anything is possible relative to time and money'.
As guides to implementing technology, I think this is a fundamental skill.
This is not true.
It depends on how much data you can get and how representative it is.
A big mistake is to assume that an unrepresentative sample of data is representative, and to draw conclusions based on that assumption.
If you do not have a representative set of data (and you can't always get one) then data can be less-than "theory or opinions".
Acting in data IMHO is only if have LOT of data. If not, acting in expertise of others look best to me..
that's mischaracterising my point. I didn't say anything about having no data. I talked about when the data you're able to get is unrepresentative.
from what place did these putatively superior data or opinions come from? Because they clearly aren't coming from data.
i think that's just playing word games with "data". We're talking about data concerning the problem at hand. Theories may come from data, but they don't come from data you obtain about the problem at hand. And knowledge can come from experience, which again is a form of data, but clearly not the sort the person was talking about. You can reason based on knowledge and principles.
Sure, it'd be better if you had good data, but when you can't have that sometimes the best you can do is to reason based on knowledge/experience/theoretical ideas.
As we speak, I'm maintaining some old code with the following variables names:
along with the fact that some of these are reused for different purposes and all are global.I'm having a hell of a time finding all instances to rename them properly.
I understand that some programmer interfaces are better than others hanlding this, but that belies my main point:
"Just name shit what it really is."
Cmnd
Cmd
Command
RecCommand
Command
(Couldn't resist that last one)
Data are on my side here: a quick perusal of the Quake 3, the Linux kernel, the Clojure runtime, and LevelDB show that Carmack, Torvalds, Hickey, and Dean all use them where appropriate.
I know people will say "but I will only write this little return statement here" before you know it you will "add this little assignment before it returns" ...
Never might be strong but it make a very good point.
The alternative to early exits is nesting, and nesting is the readability killer. My experience has apparently been just the opposite of yours: that avoiding early exits is a sign of a junior programmer, and returning early whenever possible is a sign of an experienced programmer who knows that understands code maintenance.
http://www.starling-software.com/employment/programmer-compe...
Focus on hard problems and you will end up using and developing the right tools to solve them. By focusing on hard problems, you will naturally stay up-to-date with companies looking for your expertise.
But what do I know--I'm not as successful as those guys, nor is anyone posting here, so we're all just pontificating because we like to hear ourselves talk. Don't lean too much on advice from anyone less successful (or as successful) than you.
I returned, and saw under the sun, that the race is not to the swift, nor the battle to the strong, neither yet bread to the wise, nor yet riches to men of understanding, nor yet favour to men of skill; but time and chance happeneth to them all. -- Ecclesiastes 9:11