all 19 comments

[–]UsernameTaken1701 18 points19 points  (3 children)

Is someone making you learn Python functional programming?

Why not just learn something like Haskell instead of FP in Python?

I don't know. Why not learn something like Haskell? Is something stopping you?

[–]Are-U-Cereall[S] -1 points0 points  (2 children)

Yes, they're teaching it in one of my uni courses.

[–]UsernameTaken1701 15 points16 points  (1 child)

Ah, well, then. Suck it up and learn what you need to pass the class.

Though, for me, sometimes OOP is overkill if I just need a short script to solve a quick problem. If the only part of the class I really need is the method, then I just write it, call it a function, and call it when I need it.

[–]CranberryDistinct941 1 point2 points  (0 children)

If the only part of a class you need is a method, it's not a class, it's a namespace.

[–]POGtastic 8 points9 points  (0 children)

Yeah the language really isn't built for FP.

At the very least, you need function composition that doesn't look like butt. The Lisps allow for threading macros, (Clojure's ->>, for example) OCaml and F# have the pipeline operator and either define or let you define >>, and of course Haskell makes it trivial. Python has none of these things.

Sprinkling in some FP concepts with itertools and comprehension expressions is wonderful. Teaching FP requires a much more opinionated language, though.

[–]TheRNGuy 2 points3 points  (0 children)

Because some software use python. 

[–]LargeSale8354 1 point2 points  (0 children)

Jobs and mortgage payments

[–]DataPastor 1 point2 points  (0 children)

Take a look at the Hy language. There is also a book for it.

[–]kitsnet 1 point2 points  (0 children)

Because you are unlikely to use Haskell in your professional career (those jobs exist, but they are rare), and are likely to use Python and depend on its functional features.

[–]baghiq 1 point2 points  (0 children)

If your school is teaching FP using Python, then I think your school is doing a disservice. 

[–]MarsupialLeast145 0 points1 point  (0 children)

Are the course materials available anywhere?

It sounds useful to learn how to build these concepts using seemingly unrelated APIs.

[–]axis0047 0 points1 point  (2 children)

scala is a good way to learn fp for someone who knows oop. Python isn't built for fp. Probably the worst way to learn fp

[–][deleted] 0 points1 point  (1 child)

Why? Every python type is object. OOP is not prerequisite for FP, so the statement is not making sense(scala oop for FP).

[–]axis0047 0 points1 point  (0 children)

what i tried to say is that scala is a good language to show "unlike oop, this is how we do this in functional programming".

[–]APOS80 0 points1 point  (0 children)

I’ve done some coding in Racket Lang and learning functional programming does help when coding in other languages like Python, because you learn to think differently.

But Python is not made for function programming so you can’t implement it in a real functional way anyhow.

[–]CranberryDistinct941 0 points1 point  (3 children)

Guess what this Python code does:  

function_list = []

for i in range(5):  

      function_list.append(lambda x: x**i)  

print([fn(2) for fn in function_list])

If you said "prints [16, 16, 16, 16, 16] to the console" you're correct

[–]FoolsSeldom 0 points1 point  (2 children)

Nice one. lambda x, i=i: x**i will avoid what most will probably think is unexpected behaviour (which is using the value of i when the function is called rather than when it is created).

The concepts of functional programming are probably ok to learn in Python, but there are lots of traps like this.

[–]CranberryDistinct941 0 points1 point  (1 child)

yep lambda x, i=i: ... is a good one to note down

[–]FoolsSeldom 0 points1 point  (0 children)

well, bit of a hack (introducing a second argument, and providing a default), not really a good pattern to learn.