News for hackers. Stuff that matters.
Re:Magic is often used to describe confusing code by btilly on Friday March 25, 2016 @06:20PM (#11363133)
Many programming languages have features about which I would say, "You should either use them never, or all the time, but nowhere in between."

map is one of those features. Closures are another.

The reason is simple. The cost of learning the feature gets amortized over all of the times you use it. It really isn't worth learning the feature just to see it used a single time. But if you've paid the price to learn it, then there is no reason not to use it wherever it makes sense.

Unfortunately there are some very large languages with many reasonable working sets of features, but sharp corners when you combine the wrong ones. C++ is notorious for this, but it is hardly the only one. In that case it is important to agree on the subset of features that you will use. And not introduce others willy nilly.

I would therefore appreciate the right to use map. But if my co-workers do not know it, I would think hard about how hard to press for adding it to what is needed to understand my code.

Re:Magic is often used to describe confusing code by deanCommie on Friday March 25, 2016 @06:30PM (#11363199)
That makes no sense. Maps and closures are tools like any other. Just as with many other tools, they are powerful, and should be used WHEN APPROPRIATE.

With maps, for instance, yes generally declarative programming is preferable to imperative programming (http://stackoverflow.com/questions/1784664/what-is-the-diffe...)

However, I've seen monster Java8 stream and C# LINQ statements that would benefit from additional intermediary variables, helper functions, and even cases where loops make things more clear.

Re:Magic is often used to describe confusing code by hueving on Friday March 25, 2016 @08:47PM (#11363830)
>Just as with many other tools, they are powerful, and should be used WHEN APPROPRIATE.

You can't work in a vacuum on large projects. To be an effective engineer you have to understand the limitations of your team members. Forgoing map in lieu of a more verbose loop is completely appropriate if you're working with a bunch of junior people that need to maintain and fix bugs in the same codebase.

Re:Magic is often used to describe confusing code by stickfigure on Saturday March 26, 2016 @03:19AM (#11364770)
I didn't downvote you, but I'm guessing the reason for your downvotes is that in this day and age, even junior programmers should be expected to understand map. It's such a simple concept that anyone who writes code for a living should be reasonably expected to understand it. If you're on a team with a bunch of programmers and nobody understands map, GTFO. It will not end well.
Re:Magic is often used to describe confusing code by wtetzner on Saturday March 26, 2016 @10:09AM (#11365679)
In fact, map is simpler than a loop.
Re:Magic is often used to describe confusing code by weinzierl on Friday March 25, 2016 @07:06PM (#11363412)
btuilly probably meant map as in mapreduce not map as in hashmap.
Re:Magic is often used to describe confusing code by lostcolony on Friday March 25, 2016 @07:58PM (#11363669)
Btilly rather clearly meant it in the sense of the higher order function (from which mapreduce gets its name), a fact deanCommie clearly grasped.
Re:Magic is often used to describe confusing code by duaneb on Friday March 25, 2016 @07:14PM (#11363456)
So I agree with pretty much everything you said, but it surprised me that people would consider "map" and "closure" a) at all difficult to learn and b) an all-or-nothing business. Could you elaborate? I've found them to be complementary to traditional iteration, object, and macro oriented patterns—they have their strength and weaknesses, and the idea of seeing them either nowhere or everywhere is weird.
Re:Magic is often used to describe confusing code by btilly on Monday March 28, 2016 @12:16PM (#11375132)
You underestimate the bias caused by our initial language. If you're an imperative programmer who has seen some OO, you can learn what map and closures are, but still have no idea what design patterns fit with them. And will be taken aback the first time you encounter them.

The first time I encountered a program that used them in an interesting way, I spent 20 minutes of utter confusion trying to figure out where anything HAPPENED. When I finally found the magic line, I went to the person who wrote it and said, "Why didn't you at least leave a comment!??" He looked at me, slightly puzzled, and said, "What comment would have helped?"

Today these are much more widely understood than they used to be. Mostly because JavaScript forced people to learn it. Though at one point I did have a role in popularizing the concepts in the Perl community with http://www.perlmonks.org/?node_id=34786.

Re:Magic is often used to describe confusing code by sgt101 on Saturday March 26, 2016 @03:52AM (#11364823)
Maps have a very clear and discrete semantic, no need for a flag or a comment, when someone reads the code if they are not familiar with map(x, things) then they will look it up and quickly become familiar. On the other hand closures say "the rules about variables that you might have thought were the rules are not the rules, these are not the rules you are looking for, move on, move on". People who haven't seen them before will be genuinely puzzled.

Yes, a good programmer will find out what is going on, they will be a better programmer there after. However alot of code is picked up by contractors or off shore, or even just by an intern and what happens then is that they hide their incompetence and introduce lots of bugs, or just fake the tests or lie about the tests.

Re:Magic is often used to describe confusing code by blaze33 on Friday March 25, 2016 @06:58PM (#11363370)
So maybe I'll start to use python metaclasses all the time ;)

But good point poiting out to think hard about it when having co-workers working with your code, readability counts too !