Ask HN: What habits make a programmer great?
Meta-habit: learn to adopt different habits for different situations.  With that in mind, some techniques I&#x27;ve found useful for various situations:<p>&quot;Researchey&quot; green-field development for data-science-like problems:<p>1. If it can be done manually first, do it manually.  You&#x27;ll gain an intuition for how you might approach it.<p>2. Collect examples.  Start with a spreadsheet of data that highlights the data you have available.<p>3. Make it work for one case before you make it work for all cases.<p>4. Build debugging output into your algorithm itself.  You should be able to dump the intermediate results of each step and inspect them manually with a text editor or web browser.<p>5. Don&#x27;t bother with unit tests - they&#x27;re useless until you can define what correct behavior is, and when you&#x27;re doing this sort of programming, by definition you can&#x27;t.<p>Maintenance programming for a large, unfamiliar codebase:<p>1. Take a look at filesizes.  The biggest files usually contain the meat of the program, or at least a dispatcher that points to the meat of the program.  main.cc is usually tiny and useless for finding your way around.<p>2. Single-step through the program with a debugger, starting at the main dispatch loop.  You&#x27;ll learn a lot about control flow.<p>3. Look for data structures, particularly ones that are passed into many functions as parameters.  Most programs have a small set of key data structures; find them and orienting yourself to the rest becomes much easier.<p>4. Write unit tests.  They&#x27;re the best way to confirm that your understanding of the code is actually how the code works.<p>5. Remove code and see what breaks.  (Don&#x27;t check it in though!)<p>Performance work:<p>0. Don&#x27;t, unless you&#x27;ve built it and it&#x27;s too slow for users.  Have performance targets for how much you need to improve, and stop when you hit them.<p>1. Before all else (even profiling!), build a set of benchmarks representing typical real-world use.  Don&#x27;t let your performance regress unless you&#x27;re <i>very</i> certain you&#x27;re stuck at a local maxima and there&#x27;s a better global solution just around the corner.  (And if that&#x27;s the case, tag your branch in the VCS so you can back out your changes if you&#x27;re wrong.)<p>2. Many performance bottlenecks are at the intersection between systems.  Collect timing stats in any RPC framework, and have some way of propagating &amp; visualizing the time spent for a request to make its way through each server, as well as which parts of the request happen in parallel and where the critical path is.<p>3. Profile.<p>4. Oftentimes you can get big initial wins by avoiding unnecessary work.  Cache your biggest computations, and lazily evaluate things that are usually not needed.<p>5. Don&#x27;t ignore constant factors.  Sometimes an algorithm with asymptotically worse performance will perform better in practice because it has much better cache locality.  You can identify opportunities for this in the functions that are called a lot.<p>6. When you&#x27;ve got a flat profile, there are often still very significant gains that can be obtained through changing your data structures.  Pay attention to memory use; often shrinking memory requirements speeds up the system significantly through less cache pressure.  Pay attention to locality, and put commonly-used data together.  If your language allows it (shame on you, Java), eliminate pointer-chasing in favor of value containment.<p>General code hygiene:<p>1. Don&#x27;t build speculatively.  Make sure there&#x27;s a customer for every feature you put in.<p>2. Control your dependencies carefully.  That library you pulled in for one utility function may have helped you save an hour implementing the utility function, but it adds many more places where things can break - deployment, versioning, security, logging, unexpected process deaths.<p>3. When developing for yourself or a small team, let problems accumulate and fix them all at once (or throw out the codebase and start anew).  When developing for a large team, never let problems accumulate; the codebase should always be in a state where a new developer could look at it and say &quot;I know what this does and how to change it.&quot;  This is a consequence of the reader:writer ratio - startup code is written a lot more than it is read and so readability matters little, but mature code is read much more than it is written.  (Switching to the latter culture when you need to develop like the former to get users &amp; funding &amp; stay alive is left as an exercise for the reader.)