

Ask HN: What Algorithms or patterns do you use? - lakeeffect

As I begin to code more and more, I am reminded of my ignorance of algorithmic conventions.  What are your top most helpful patterns?
======
jtfairbank
It is super helpful to have a working knowledge of common data structures-
most algorithms are optimized for data in a particular format.

------
angersock
So, probably the single most important one for me has been the concept of
immutable data structures: whether in C, C++, Java, or Javascript, treating my
data immutable has made debugging things a lot easier, _especially_ in
environments with parallel execution and shared memory.

The next one would be abstraction of storage. Whether using an array, linked-
list, or something more exotic, I usually want to hide that from the rest of
my program if possible. In general, abstraction is a very handy tool--though
you are going to screw up and overdo it until you've got some experience
(mainly gained by screwing up).

Next top one would be recursive functions to operate on tree-based structures
--though I hesitate to use them automatically in languages that don't have
mandatory TCO unless I know I won't blow the stack. So many things are plain
elegant when you write the problem recursively.

Those are three general principles of engineering and design that have served
me well. Some specific things that are useful are: the general idea behind
finite-state machines and when to recognize if they apply to your problem,
regular expressions and their use, pitfalls of the floating-point
representation of numbers, basic linear algebra for graphics and simulation.

