What are some advanced concepts in programming that most average programmers have never...

Quora Feeds

Active Member
Mickael Bergeron Neron

  1. Purity, as in side-effect free functions. I have never met a programmer in person who knows this concepts, yet this is one of the most important aspects of modularity, scalability and robustness.
  2. Functional programming. Almost none of my colleagues had heard about that before I first mentioned it. Same for my teachers when I was in college.
  3. Higher-order functions, that is, functions that take a function as an argument and/or return a function. Such functions are so versatile and powerful. They allow to write less code that does more. All programmers should know about higher-order functions.
  4. Partial function application. When you don’t provide all the arguments a function needs and it creates a new function that take the missing arguments. For example, let say that we have a function draw(Bitmap bmp, int x, int y), with languages supporting PFA, you can create a function drawTree = draw(theTreeBitmap).
  5. Tuples, that is, sequences of values. The next version of C# will have better support for tuples so hopefully more programmer will discover and use these little marvels.
  6. Monads. They are so powerful and so clever, yet the vast majority of programmers have never heard of that term. I won’t try to explain what they are: It seems that nobody quite can explain that concept in a way that another programmer will actually understand, and I’m not going to be the next one to venture there…

The 4th point explained with code:

In Haskell:

drawTrees :: [(Float, Float)] -> IO()
drawTrees positions = do
treeBitmap <- loadTreeBitmap
forEach positions (draw treeBitmap)

draw :: Bitmap -> (Float, Float) -> IO()
draw bmp position = ...

loadTreeBitmap :: IO (Bitmap)
loadTreeBitmap = ...

forEach :: [a] -> (a -> IO()) -> IO()
forEach list action = mapM_ action list


In C#, if it supported partial function application:

void drawTrees(List<Vector2> positions)
{
Bitmap treeBitmap = loadTreeBitmap();

positions.forEach(draw(treeBitmap));
}

void draw(Bitmap bmp, Vector2 position)
{
...
}

Bitmap loadTreeBitmap()
{
...
}

static void forEach(this List<T> list, Action<T> action)
{
for (int i = 0; i < list.Count; i++)
action(list);
}


Edit: In reply to some of the comments, I wrote that almost none of my professors in college had heard about FP. As it happens, only the younger ones had heard about it.

Again, I wrote that almost none my colleagues had heard about FP. The fact is, only the younger ones who studied programming at a university had heard about it.



See Questions On Quora

Continue reading...
 
Top