Live data from Hacker News

Simplistic programming is underrated

lemire.me

61–70 of 93 posts

Re: Simplistic programming is underrated

#61
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…

I dunno, I find the second one harder. Because now you have to know about array indices and things like that. The for loop forces you to deal with petty details. The map reduce lets someone else deal with that. I tend to think there's some additional overhead from Javascript's particular object oriented implementation of mapping and reducing when compared with haskell's i.e. f xs = foldr + 0 (map (\x -> x * x) xs) se…

since a map and a sum are both folds, you can simplify it further:

f = foldr (\x total -> total + (x * x)) 0

but this is actually a counter argument. look at all these ways of doing this simple operation with higher order functions. plenty of replies from intellectual napoleons like me, too. whereas with the for loop, there's nothing much to say, which seems like a good thing.

i genuinely don't know how to feel about this.

Re: Simplistic programming is underrated

#62

Earlier quoted context omitted.

> Off by one errors can't happen in the functional version. No? Not only can they happen, but I'd argue that it's easier for them to occur when using `reduce`, because you have to remember the initializer. Omitting it has no effect in the given example, but the given example is contrived. It's not rare to be dealing with something more complex than a list of numbers, so let's try that instead. Let's say your items ar…

> No? Not only can they happen, but I'd argue that it's easier for them to occur when using `reduce`, because you have to remember the initializer. I would say that's not an off by one error. Its a similar scale and type of error, but not the same.

It's much more insidious than an off-by-one error in a for-loop - the initializer is hidden!

Re: Simplistic programming is underrated

#63
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.

My pet peeve on HN is people writing comments like they're gonna be peer reviewed. Either the less common words that they use are obviously out of place like someone just discovered a thesaurus (conflated is my favourite example), or it's consistently formal and quasi-academic so I have to put extra effort into reading it. Either way it just makes the authour sound like a pretentions wanker.

Re: Simplistic programming is underrated

#64
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…

This is interesting to me because the map reduce has way less cognitive load for me. With map reduce I see the following: - We've got an array - We're going to loop through it and square everything - We're going to take that and add it all together - The result is r When I read the for-loop counterpart: - We have a variable called r that we're initializing to 0 - We're starting a loop with j as the index initialized…

The main advantage that I’ve seen when writing and reading functional instead of procedural/imperative code, is that the intention is usually clear.

We have a list of numbers that we want to square and add up, instead of the more mechanical steps with the loop approach.

Re: Simplistic programming is underrated

#65
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…

For me, any talk about what is the best way to loop over or enumerate an array is not the most helpfull in talk about code simplicity. Using a loop, an enumeration, or a functional map, should not really matter that much, most of the time they all do similar things. I would think that any intermediate programmer recognizes them. Thinking too much about which is better, is just loosing time better spend elsewhere.

Re: Simplistic programming is underrated

#66
post #63
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.

My pet peeve on HN is people writing comments like they're gonna be peer reviewed. Either the less common words that they use are obviously out of place like someone just discovered a thesaurus ( conflated is my favourite example), or it's consistently formal and quasi-academic so I have to put extra effort into reading it. Either way it just makes the authour sound like a pretentions wanker.

Yep. "Orthogonal" is one of my favorites. Along with "order of magnitude".

Re: Simplistic programming is underrated

#67
post #54

I don't think it's underrated; it's that it's hard to write. You almost go full-circle. You start off writing highly procedural code (with too much branching), join the GOF-all-the-things religion and eventually revert to highly procedural code (more specifically "algorithmic code" or "functional code"). As an example, many years ago I wrote a dependency resolver. It needed to find cycles (as we had some rules that c…

I agree. There seems to be two interpretations of "simple" - simple in being concise like that of a beautiful mathematical equation, or simple in being easy to follow and understand. I assume the latter is preferable when factoring in having other pairs of eyes reading/maintaining your code, especially since the latter does not always imply less efficient code

Actually, I think the interpretation of simplicity as ease is an awful thing in the context of programming and should be actively discouraged. Rich Hickey’s talk “simple made easy” is the best explanation I’ve ever seen of this.

Re: Simplistic programming is underrated

#68
post #63
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.

My pet peeve on HN is people writing comments like they're gonna be peer reviewed. Either the less common words that they use are obviously out of place like someone just discovered a thesaurus ( conflated is my favourite example), or it's consistently formal and quasi-academic so I have to put extra effort into reading it. Either way it just makes the authour sound like a pretentions wanker.

As a non-native english speaker trained in academia, I'm pretty sure that sometimes my comments must come out like that. I'm not doing it on purpose, it's just that I don't know better!

I suspect there are many others in my situation here, specially those whose native language is of latin origin, because latin-based words are considered more formal/academic in english, yet they're much easier for us to learn!

Just keep that in mind when judging other's comments please ;)

Re: Simplistic programming is underrated

#70
post #54

I don't think it's underrated; it's that it's hard to write. You almost go full-circle. You start off writing highly procedural code (with too much branching), join the GOF-all-the-things religion and eventually revert to highly procedural code (more specifically "algorithmic code" or "functional code"). As an example, many years ago I wrote a dependency resolver. It needed to find cycles (as we had some rules that c…

“I didn't have time to write a short letter, so I wrote a long one instead.” - Mark Twain

It's both hard and underrated - it's underrated because it's so hard that a lot of developers haven't developed the skill of writing simple code, and so don't recognize the value when others do it.

Post reply on HN