6 ms·
> 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 st
by dvt 9y ago
> 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 from an intellectual Napoleon complex (which I've seen in academic Philosophy, as well). I've argued for the use of simple "for loops" in lieu of complex map-reduce logic, argued against overly-complex threading logic where threading wasn't necessary, argued against using Spark where the dataset was so tiny, it could be handled by my iPhone. All my suggestions often fall on deaf ears. The counter-argument tends to be some contrived edge-case which (by that point in the discussion), I'm simply too fatigued to argue against. I've lost this war of attrition many (many) times.
The irony is that most OSS code tends to be "so simple it's dumb" -- why? Because simple code is easy to contribute to! I think if more professional programmers actually looked at real code outside of their corporate Bitbucket, working as a programmer would be much more enjoyable.
- Y_Y 9y agoIs 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++).
- frankmcsherry 9y agoI mean, it can be, right? Take todays Advent of Code problem, where you want to grab the index of the largest element in a sequence breaking ties toward early elements, then re-distribute that element one at a time over other positions starting from the largest element (looping around as required). I can write that using various maps, folds, flat_maps, and reduces, but no one else would understand what is going on in the code. Maybe someone will post the right idiomatic functional way to do that, but nothing elegant comes to mind.
- dvt 9y agoI 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 < array.length;j++){ var x = array[j]; r += x*x; } 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/questions/17546450/for-array-is-it-more-efficient-to-use-map-reduce-instead-of-foreach-in https://stackoverflow.com/questions/17546450/for-array-is-it...
- banachtarski 9y agoC++ guy but anecdotally, the first one really does read better.
- RubenSandwich 9y agoI 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
- jasonkostempski 9y agoEliminating the map, named functions or not, makes it pretty clear: var r = array.reduce((total, num) => total + (num * num), 0);
- lordCarbonFiber 9y agoExcept 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 <=; what if you're nested; did you use i and j in the right place? 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. "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).
- sanderjd 9y agoI agree: one of these things is not like the other. Map / filter / collect is not better because it is "fancy" but because those operations match the semantic intent of most operations on collections while being constrained to do a single thing. Conversely, for loops are unconstrained and reflect no intent in particular.
- maxxxxx 9y agoMost corporate problems are most likely solved by pretty simple code. The problem is that you are not building your resume that way and your future job searches will suffer. To stay up to date I often squeeze things into my work that are not strictly necessary.
- liveoneggs 9y agowhat's funny is that the code compiles the small map-reduce and the for loop to exactly the same bytecode probably. :)
- RandomInteger4 9y agoNot my area of expertise, so I want to ask this question: Do compiler optimizations exist to automatically parallelize a for loop, which can be parallelized, no matter how to programmer wrote their for loop? If not, then map / reduce offers non-trivial performance benefits over a for loop. Mapping, as far as I'm aware, is "embarrassingly parallel", assuming the function that's mapped is pure? I think?
- deleted 9y ago[deleted]
- liveoneggs 9y agoin perl6 this is done with the hyper operator, but for a small data set a for loop (non parallel) will almost always just run faster.
- fpisfun 9y agoNo, map reduce can be run in parallel, at least in some cases.
- kls 9y agosuffer from an intellectual Napoleon complex I call it the low talent to ego ratio. While I disagree on the map -> reduce I agree on the other positions you articulated.
- dominotw 9y agoPeople are constantly quizzed on map-reduce, spark type of stuff in interviews. Resume 1: > Did simplistic programming using for loops. Resume 2: > Map reduce using spark. Guess which resume gets picked up by filters? Noone wants to get caught with their pants down when they have to look for their next job. Pressure to "keep up" is unfortunate reality of our profession. Resume Driven Development is a thing.
- sideproject 9y agoI can't... agree with you more. Just lost one recently. There was no need to go "microservice" but we did (I have nothing against that structure). Argued against it, got shot down and they went around and are implementing it now. Happened so many times and it's.. dead tiring.