Fork me on GitHub
#off-topic
<
2022-11-07
>
Martynas Maciulevičius11:11:49

I'm watching "OOP and FP: Reducing Complexity Together" https://youtu.be/p3Rb7uxtQs4?t=1483 and one of the questions they talk about is "Why not use for-loop directly?". They say "there's one line version of this" but it implies that oneliner is always better which I can't fully agree with. I think the proper answer is "Why not allocate memory directly?" or "Why not code in machine code directly?". :thinking_face:

💯 1
marrs16:11:49

I quite like the answer Normand gives in that video, The one-liner thing points to an optimal efficiency of expression. I take your point that it doesn't quite get to the heart of the matter, but I think he gets there as he expands on his answer, particularly when he gets to the part on being able to interrogate data with a set of questions and abstract the concept of questions away from the datasets. That might be the most useful and enduring feature of list comprehensions.

slipset11:11:52

There is this thing called https://en.wikipedia.org/wiki/Turing_tarpit which also adresses that question, I believe

Wanja Hentze11:11:10

I think what matters for the beginner in this hypothetical situation is: • They know for-loops • They may not know filter/map/fold or whatever the function in question is So what they're really saying is not "Oh this high-level thing is really just a wrapper around this lower-level thing, so I'll use that instead" but "Oh this thing I don't yet know is really just a wrapper around this thing I already know, so I'll stick with that"

slipset12:11:58

I would argue that it should be possible to see that

const r = xs.map(foo);
has a lot less room for mistakes than the corresponding for loop in eg js
const r = [];
for (var i = 0; i< xs.length; i++) {
   r[i] = foo(xs[i]);
}

slipset12:11:51

and, if we were talking about C, I could probs implement such a thing in assembler as well, but why on earth would I choose to go such pains?

borkdude12:11:13

the higher level thing like xs.map might be more optimized well by intrinsics in the compiler or mappings to native functions, such that doing it yourself in more verbose code is actually slower. It highly depends on the runtime / implementation and what is more performant today could change tomorrow

Wanja Hentze12:11:59

all I'm saying is: the people who are saying "I'll do it in a for-loop because I know that's faster in gcc 9.8.3-ubuntu2" or whatever are probably not the same crowd that's saying "I'll do that in a for-loop because I have no idea what map is"

Wanja Hentze12:11:48

And yes, sometimes assembly is (still) the best tool for the job. For example, we do not have any good production-ready languages for writing cryptographic primitives without side-channel issues. Your options are 1. Write C, use all the compiler flags you can and pray 2. Use some experimental academic thing like [FaCT](https://github.com/PLSysSec/FaCT) and pray 3. Write assembly, don't mess it up

marrs15:11:51

> It highly depends on the runtime / implementation and what is more performant today could change tomorrow The trouble with this argument is that the opposite can also be true: what is more performant today may remain more performant tomorrow. I'm still waiting for JS's let and const not to be substantially slower than var , even though I'm always told that the runtime will "fix that problem" soon enough. Last I checked, C and Assembly were still considerably faster than high level languages. The issue with these languages is their safety and expressiveness, not their performance. Given that performance is one of the biggest signifiers of application success, and given how slow modern apps are today, I think there's a good case to be made that we may not have this balance entirely right

Wanja Hentze11:11:59

i.e. for-loops are "easy" to this particular persion but filter/map/fold are not

Wanja Hentze11:11:53

most people are taught for-loops early on, but not how to do manual memory management or assembly language. so that's why I think the simile doesn't quite work

Martynas Maciulevičius11:11:54

It does work because they weren't even being though the low level stuff because of this same reason. Because then why not learn that low level thing if it's better. i.e. if you start with for loops you already skip the ASM. Why do you skip it? Then they should be tought ASM instead of for loops to understand the for loops...

marrs15:11:34

They should be taught ASM. ASM no longer being on the curriculum would explain a lot about the state of programming today

skylize23:11:45

I think if I share this, I will be less likely to forget it exists, and hopefully someone will benefit that didn't know it exists: Chromium browsers now have a Search Tab feature accessed with Ctrl-Shift-A on Linux (probably same on Windows, and I would guess Cmd-Shift-A for Mac). It seems to be a fuzzy search, which is great, and is also available by clicking the roughly V-shaped symbol at or near the top right corner of the browser. The hotkey is broken when Slack is the current tab, because Slack hijacks it for Open the *All unreads* view. But if you enable the Quick Commands flag in chrome:flags, you then you can still get there via Ctrl(Cmd)-Space S E Enter, which is not too bad.

1
🙏 1
Martynas Maciulevičius06:11:32

Vimium plugin has Shift+t tab search too. So you can use this either in Chromium or Firefox.