-
Notifications
You must be signed in to change notification settings - Fork 7
Replacing loops with safer constructs #3
Comments
I have a couple of examples for de-looping in Python |
I could certainly help with this, and I'd be comfortable teaching functional Python after the teaching primer. I've TA'd that class before... But why? Functional programming is honestly interesting mostly for people who are interested in code for code's sake. Wouldn't our target audience be better off being told to use the I think if we want to reduce the use of unpredictable structures, we should look at "a monad is a monoid in the category of endofunctors, what's the problem" as a not do. |
I agree that, in most cases, you'll use loops and list comprehensions. But as soon as it comes to time-consuming calculations on big datasets, I'm very happy to know how to use functional Python to save my day (and lots of time). So it probably depends on the audience we have... |
Another very powerful tool for major efficiency improvements without much programming effort is just in time compilation with numba. This can be used to speed up pure numpy code with lots of loops instead of de-looping ;-) |
Something that meshes with efficiency and correctness concerns is if we teach people to manipulate data with the methods of the data structures they're using. That's especially good when we're teaching people how to write code in languages with a global interpreter lock / green threads only, with data structures provided by libraries written in C++. |
I take the opposite stand here: the functional paradigm avoids |
I think that for loops are more universal between the languages scientists would use, and if we can get them to not use while loops, that would be an effective way of preventing the errors mentioned on that blog recommending functional programming. After all, the choice is between learning how to use for loops, or learning how to use map, reduce, zip, and select (they have to write functions anyway). To someone who sees programming as a tax they have to pay to do science, I'd expect the first sounds more appealing, so they're going to do it, whether they have us around to tell us how to do it or not. |
Rereading my previous comments makes me think we could sell functional programming as "how to work with large datasets." Come for the map-reduce and array broadcasts, stay for clean functional code. |
Hi @david-morris! I'm not an expert in |
Constructing your own
for
-loops is only rarely actually necessary. We'll learn about alternatives here. Bring your own code and let's de-loop it! Good introduction in German: Heise Developer: Weg mit den Schleifen!What should/will the learning objective(s) be?
for
-loops to theapply()
family orpurrr::map()
sWhat do participants need to know / install / bring?
for
loops, or an example we'll provideWhat next? Upvote this topic. It will be scheduled when a) 3 or more people upvoted and b) it has an assignee. If you want to teach this topic, please say so. To schedule the event, create a new file in the
_posts
folder, copy this template's filename and content and fill in the new event metadata.The text was updated successfully, but these errors were encountered: