Live data from Hacker News

Simplistic programming is underrated

lemire.me

11–20 of 93 posts

Re: Simplistic programming is underrated

#11
post #3

> I like the concept of “simplistic programming” by which I mean “programming that is so simple that people will criticize you for it”. At first, that sounds strange… can we really get criticized for being “too simple”? Of course, we do. Oh man, this hits home. I've attempted to be a voice of reason on this front so many times, I've practically given up on it. I've come to the conclusion that most programmers suffer…

what's funny is that the code compiles the small map-reduce and the for loop to exactly the same bytecode probably. :)

Re: Simplistic programming is underrated

#12
Simple vs. non-simple isn't the best way to think about code.

Rather I would think about the requirements of the code. Who is going to be reading it? Maintaining it? Do advanced language features give some kind of advantage (runs faster?, less likely to have bugs?, more extensible?). Will new team members likely introduce bugs? Is spaghettti code better or worse than using less known patterns/language features?

Don't use advanced language features in production code for these reasons: (i) impress people or (ii) develop your CV.

Don't avoid using advanced language features just because someone wrote a blog post saying it's a bad thing to do.

In a nutshell: Think.

Re: Simplistic programming is underrated

#13
post #10
post #8

Earlier quoted context omitted.

Is map-reduce really less simple than a for-loop? I agree with your other examples, but I see these too things as totally equivalent (unless you're in a language that make a dog's dinner of this type of thing, like old C++).

I think so, consider[1]: var r = array.map(x => x*x).reduce((total, num) => total + num, 0); vs its for-loop counterpart: var r = 0.0; for (var j = 0; j Maybe I'm just not as smart as everyone else, but I only have to keep like two things in my mind when looking at the for loop (easy), whereas in the map-reduce case, I need to have a very "holistic" view of what's going on (hard). [1] https://stackoverflow.com/questi…

C++ guy but anecdotally, the first one really does read better.

Re: Simplistic programming is underrated

#14
post #10
post #8

Earlier quoted context omitted.

Is map-reduce really less simple than a for-loop? I agree with your other examples, but I see these too things as totally equivalent (unless you're in a language that make a dog's dinner of this type of thing, like old C++).

I think so, consider[1]: var r = array.map(x => x*x).reduce((total, num) => total + num, 0); vs its for-loop counterpart: var r = 0.0; for (var j = 0; j Maybe I'm just not as smart as everyone else, but I only have to keep like two things in my mind when looking at the for loop (easy), whereas in the map-reduce case, I need to have a very "holistic" view of what's going on (hard). [1] https://stackoverflow.com/questi…

I think your giving a bad map reduce example. It is written in a very immature functional programming style.

It should be written like this, IMO:

  var r = array
          .map(square)   
          .reduce(sum, 0);
Differences:

1. Separating out actions by line

2. Pass named functions that describe what they do

Re: Simplistic programming is underrated

#15
post #10
post #8

Earlier quoted context omitted.

Is map-reduce really less simple than a for-loop? I agree with your other examples, but I see these too things as totally equivalent (unless you're in a language that make a dog's dinner of this type of thing, like old C++).

I think so, consider[1]: var r = array.map(x => x*x).reduce((total, num) => total + num, 0); vs its for-loop counterpart: var r = 0.0; for (var j = 0; j Maybe I'm just not as smart as everyone else, but I only have to keep like two things in my mind when looking at the for loop (easy), whereas in the map-reduce case, I need to have a very "holistic" view of what's going on (hard). [1] https://stackoverflow.com/questi…

Except the over head of that loop is orders of magnitude higher than the reduction. Did you get the bounds right; what happens if you accidently start at 1 or end at "Simple" is great until you're debugging off by one errors or any other errors between chair and keyboard. Complexity, in the sense that this guy rails against, is expressiveness. And, expressive code beats "simple" code every day of the week.

--Quick edit Imagine that loop in assembly. It's objectively "less complex" yet you didn't express it that way. Why? I think the answer to that question is the heart of the positive argument for programming abstractions (and the "complexity" they bring).

Re: Simplistic programming is underrated

#16
post #7

I agree that overcomplicating code is bad, but then again, what is "simplistic"? Let's talk Python. To me, using comprehensions is way simpler than loops. Using for i, item in enumerate(my_list): # do some stuff with i and item is way simpler than for i in range(len(my_list)): # do some stuff with i and my_list[i] And still, I bet that most C/Java folks will look at these things with disdain. Also, higher-order funct…

The first is Pythonic code. I'm guessing the author isn't talking about conventional code, but a more agnostic point of creating complexity for complexity sake, which, unfortunately, is a very common issue.

The other way can also be a problem. If you are manually writing out range(len(stuff)) in Python on all your loops, you are writing code that is complicated, overly verbose, difficult to understand, and error-prone.

Re: Simplistic programming is underrated

#17
post #10
post #8

Earlier quoted context omitted.

Is map-reduce really less simple than a for-loop? I agree with your other examples, but I see these too things as totally equivalent (unless you're in a language that make a dog's dinner of this type of thing, like old C++).

I think so, consider[1]: var r = array.map(x => x*x).reduce((total, num) => total + num, 0); vs its for-loop counterpart: var r = 0.0; for (var j = 0; j Maybe I'm just not as smart as everyone else, but I only have to keep like two things in my mind when looking at the for loop (easy), whereas in the map-reduce case, I need to have a very "holistic" view of what's going on (hard). [1] https://stackoverflow.com/questi…

Might look nicer to write the first version as:

  let square = (n)   => n*n
  let sum    = (s,n) => s+n
  
  let r = array.map (square).reduce (sum,0)

Re: Simplistic programming is underrated

#18
post #10

Earlier quoted context omitted.

I think so, consider[1]: var r = array.map(x => x*x).reduce((total, num) => total + num, 0); vs its for-loop counterpart: var r = 0.0; for (var j = 0; j Maybe I'm just not as smart as everyone else, but I only have to keep like two things in my mind when looking at the for loop (easy), whereas in the map-reduce case, I need to have a very "holistic" view of what's going on (hard). [1] https://stackoverflow.com/questi…

Except the over head of that loop is orders of magnitude higher than the reduction. Did you get the bounds right; what happens if you accidently start at 1 or end at "Simple" is great until you're debugging off by one errors or any other errors between chair and keyboard. Complexity, in the sense that this guy rails against, is expressiveness . And, expressive code beats "simple" code every day of the week. --Quick e…

> Except the over head of that loop is orders of magnitude higher than the reduction.

Except that it's not. Read the SO answer I linked.

> The nooks for bugs in your "simple" loop are so profound that, in a language with expressive maps, I wouldn't accept that code in a review.

Yep, I've definitely worked with people like you. With all due respect, I just think you're fundamentally wrong. Off-by-1 errors will happen no matter what, and even a rudimentary test suite can catch those.

Re: Simplistic programming is underrated

#19
post #2

Your apparent mental prowesses will fail to impress those who find it easy to do the same. I have met my share of college students and professors who excel at dropping the name of a few philosophers, at using words only 1% of the population knows about… but, at a certain level, it does nothing for them. People simply roll their eyes and move on… Solid life advice.

Since he's a professor, I have no doubt that what he says is true in his environment.

On the other hand, it's all relative. After having worked in Silicon Valley for over 15 years, I think the more common mistake is knowing too little philosophy rather than too much. (Of course, I agree that 5 dollar words confuse issues more often than they illuminate them.)

It wouldn't hurt a lot of engineers and tech companies to learn more about the past and be more literate.

As an example, off the top of my head, here is a concept which comes up a lot in software:

"The Map is not the Territory"

https://en.wikipedia.org/wiki/Map%E2%80%93territory_relation

Likewise:

https://en.wikipedia.org/wiki/Ludic_fallacy

You don't have to do statistics / big data for very long before you hit philosophy. It bottoms out pretty quickly, i.e. how do you learn about the world. Likewise programming is about making things, and sometimes about modelling the world, and there are a lot of useful philosophical concepts in that realm too.

This is without even getting into the "morals" of technology, which is a big thing in the news lately.

Post reply on HN