Is using higher order functions in algorithm cheating

Is using higher order functions in algorithm cheating
0

#1

Hey guys,

What I mean is, is learning to accomplish these algorithms with higher order functions robbing you from really learning how to use the basic tools available to you.

Since higher order functions are just functions that the language has built in, is it not like just copying and pasting someone else’s code without really knowing how to do it yourself.

Surely not every language has functions like this, and when you need to implement these algorithms how do you solve it? Since the only way you learnt how was with these functions available to you.

I know this would make the challenges a lot harder but i just get the feeling we’re cheating ourselves by doing this.

I’m really interested in what everyone’s thoughts are on this.


#2

Given that higher order functions are part of standard JS, I don’t think it’s out of line to use them.

I’d think it was less useful to rely on a library like lodash which includes functions that replicate many of the algorithms, though, since that really does a lot more of the heavy lifting.


#3

But surely it hurts when you have implement these type of algorithms in a language other then JS.


#4

Surprisingly, the tasks that higher-order functions accomplish aren’t always trivial to solve, at least not well. Learning to sort, search, and modify arrays is frequently the first challenge students in algorithm classes are faced with because it’s so easy to screw it up by exploding into quadratic time.

This is arguably all a programming language is. We are invoking pre-written commands.

Most of the cool languages share quite a bit of functionality. I’ve been doing a fair amount of C# and lots of Ruby lately, and I have been able to find most of what I need. I imagine Java and Python offer similar faculties. Not that I’ve yet tried it, but I would imagine that learning to write JavaScript in a more functional style would make for an easier transition to purely functional languages. Even when transitioning to highly imperative languages like C, JavaScript developers will have a harder time with data structures and typing than anything else.

I’m absolutely sympathetic to this point of view, though I don’t think we would have anything to gain by writing code for the challenges that we wouldn’t want to use in production. If you’re truly interested in the low level stuff, there’s no substitute for learning it in the context of computer science.

  • CS50 - Intro to computer science
  • Build a tiny compiler - Because why not?
  • Introduction to Algorithms - I actually prefer the Harvard course, but this one is excellent and taught by Robert f%&king Sedgdwick!
  • Functional Programming - This is difficult to get through because it’s buggy and very advanced, but you will implement all of the major higher order functions. The last part gets into observables, which I love, but require a separate library to use for now, so you may want to skip.

#6

Thanks guys, does make me feel a bit better about it.

I am already taking CS50 so hopefully that will fill in any gaps.


#7

Thanks for the links PortaStick!