News for hackers. Stuff that matters.
Re:Go + Services = One Goliath Project by StillBored on Saturday December 21, 2019 @07:59PM (#21854396)
Fundamental? IMHO, they are just syntactic sugar on a foreach loop. Which in many ways is bad because it provides yet another way to express the same concept, without a significant difference in the method of execution. What am I missing?
Re:Go + Services = One Goliath Project by UK-Al05 on Saturday December 21, 2019 @08:22PM (#21854486)
I mean a for loop is just a syntatic sugar of a if and a go-to, but go-to is easier to mess up.

Same with map, they are a constrained for each that is guaranteed to be a correct implementation.

Re:Go + Services = One Goliath Project by dwaltrip on Saturday December 21, 2019 @08:21PM (#21854479)
Map and filter allow for a very concise and clear indication of the intention of the code, so it is much quicker for the reader to parse what it is doing.

Edit: Also, for loops are just a way of implementing a mapping, where you have data A that you want transformed into data A*. The map is the fundamental concept here, not the for loop.

Re:Go + Services = One Goliath Project by StillBored on Saturday December 21, 2019 @09:01PM (#21854643)
Which is more generic, the 'for' or the 'map'? I think its the 'for' because it has additional capabilities contained in the base concept, which is why I would call it more "fundamental".

In fact in many languages much of filter() can be implemented in the for construct rather than its body.

Re:Go + Services = One Goliath Project by kinjba11 on Saturday December 21, 2019 @10:10PM (#21854925)
There are two sorts of 'fundamental'. You are correct that the 'for' is just syntactic sugar for 'goto' which is more fundamental than map/filter in the sense that it translates into assembly/machine language, upon which all programs are built. Then you can say the silicon logic gates are even more fundamental, you can do even more things with them, etc.

The map/filter is more fundamental in a mathematical sense. If you turn a list of A turned into a list of A*, the 'mapping' is the fundamental concept, the 'for' loop is just an implementation detail. Maybe the computer did it in parallel, or in random order, or I asked you to turn a pile of towels into a folded stack of towels. The same way if I say 'want to watch a movie' - the movie the fundamental concept, whether it's digital, film, etc. is irrelevant.

Re:Go + Services = One Goliath Project by WoodTree on Saturday December 21, 2019 @08:30PM (#21854522)
They don’t have to be glorified for loops, even if they usually are. Map and Filter should be capable of running in parallel or asynchronously, and some languages provide this.
Re:Go + Services = One Goliath Project by StillBored on Saturday December 21, 2019 @09:09PM (#21854682)
And many languages, have parallel for constructs. The openmp #pragma parallel extensions in C/C++ for example. Of course its possible to create constructs which provide the messages passing for clustered environments too.

And maybe that is part of the problem with a generic 'map' your not really sure the underlying implementation, is it parallel, clustered, serial, etc? So you end up with map(), parallel_map(), mpi_map(), etc, and how to you control the parallelism. Do you just let it default or do you have levers to control the batch & interleave. Pretty soon, its not such a simple construct anymore.

Re:Go + Services = One Goliath Project by WoodTree on Saturday December 21, 2019 @10:41PM (#21855034)
In a functional language those details should be irrelevant. But of course they are relevant in practice, and map is usually just a for loop.
Re:Go + Services = One Goliath Project by jimbokun on Saturday December 21, 2019 @08:51PM (#21854608)
Why isn’t the foreach form the syntactic sugar?