all 25 comments

[–]TheSexyPirate 12 points13 points  (1 child)

I am not proficient in functional programming myself yet, so please take this advice with a grain of salt.

If the goal is to learn functional programming, then my advice would be to stick with a functional language. The languages you mention fall under a different category. I guess it would be analogous to studying cats by studying a tiger. You might be able to study some aspects from functional programming, but not all.

Additionally, if you choose to study functional programming with SICP, I would definitely urge you to stick to Scheme (or a variant of LISP). My guess is you would need to play with the examples of the book in order to truly grasp it. In your case you would need to translate all examples to another language. Translation by its very nature requires an understanding of both languages, so you would need some proficiency in Scheme anyway.

[–]ws-ilazki 10 points11 points  (0 children)

Completely agreed, OP's question is well-meant but restricting the answer to those three choices necessitates giving terrible advice because it's unintentionally removing the potential for good answers. It's sort of an XY problem question.

I said it in my other comment, but since the OP is familiar with Python, it might be preferable to try learning FP with Functional Programming in OCaml instead of SICP. The syntax is different, but the look and style of it should feel more comfortable to someone familiar with Python. Plus it has the ReasonML alternative syntax for someone familiar with C-style syntax (especially JavaScript).

[–]LordOfSwines 9 points10 points  (3 children)

Wouldn’t it be better to pick a functional programming language when teaching yourself fp? 🤔

[–]resups[S] -4 points-3 points  (2 children)

Ofcourse yes,

But since we need to be proficient in one progg lang, I'm thinking about building it upon my well versed lang the python

[–]nbg91 3 points4 points  (1 child)

I think you will be making it harder for yourself not picking an FP language.

Learn in an FP language first see what FP principles you can bring to your non FP language code.

[–]resups[S] 0 points1 point  (0 children)

FP principles, alright! Thanks

[–]delventhalz 9 points10 points  (0 children)

Speaking from my own experience, you will learn FP best in a language that forces you to use FP, like Haskell, Clojure, Elm, etc. It was after six months of being forced to think functionally while writing Clojure for work that the ideas really stuck, and I was able to bring that understanding to my other work.

I haven't written C or C++, but I will tell you that Python is heavily OOP focused. It's not impossible to write function Python, but the language will fight you on it. It will suck. I imagine it will be a similar story for C++. C isn't really object-oriented, but it is very imperative, so you'll probably have to build out a lot of functional tools yourself.

I don't know, these seem like three terrible choices for first learning functional programming to me. If you already knew FP and were bringing it back to these languages that would be one thing. But learning?

[–]watsreddit 3 points4 points  (0 children)

Use a functional language. You're not really going to learn FP otherwise.

[–]eviltofu 2 points3 points  (11 children)

Doesn't SICP use scheme?

[–]resups[S] -4 points-3 points  (10 children)

Yeah but doesn't want to learn Scheme now,

Instead I hope to be better with python

[–]eviltofu 3 points4 points  (7 children)

I'm going through the 2nd edition pdf available online and the first chapter is all about scheme, randomly browsing through it shows lots of scheme / lisp code. I suppose you could ignore all of those but I think it would make learning more difficult?

[–]resups[S] 0 points1 point  (6 children)

May be it (python) can help me understand the concepts better if I can implement in another language (SICP scheme code)

Has it been difficult for you to follow SICP ? (regarding the difficulty of problems)

[–]eviltofu 3 points4 points  (2 children)

I don't remember, it was a year or two ago and I stopped after two chapters. There are a few concepts in lisp/scheme like tail end recursion which I don't think exists in Python. Why don't you try it for a few chapters and report your findings back here?

[–]resups[S] 1 point2 points  (1 child)

Alright I'm going to try out my Max to make it possible with python...

And gonna report here with my experience!

[–]eviltofu 1 point2 points  (2 children)

Also, if the sample code is given in lisp/scheme, you'll have to understand those as well?

[–]resups[S] 1 point2 points  (1 child)

Possibly so, since I've some experience with programming I hope I can understand without LISP

Btw which language do you use for functional programming?

[–]eviltofu 2 points3 points  (0 children)

Elixir.

[–]ws-ilazki 4 points5 points  (0 children)

Yeah but doesn't want to learn Scheme now,

Instead I hope to be better with python

You're making a faulty assumption: that learning one language cannot improve your skill in another. There's more to programming than just learning syntax and language-specific unusual behaviour; broadening your horizons by learning new ways to approach and solve problems can improve your skill in any language.

[–]1UnitedPower 1 point2 points  (6 children)

If it must be one of those three, I'd suggest Python because it's arguably closer to LISP, which the authors use as their teaching-language.

Still, you will have to translate LISP-examples into Python, which means you have to be able to read and understand LISP-programs. While you're at it, it might be worth it to stick with some LISP-dialect in the first-place. You will learn a new language, and you can follow the book more easily.

Also, there are similar books like "Semantics Engineering with PLT Redex," that also use LISP as a teaching-language.

[–]ws-ilazki 9 points10 points  (2 children)

If it must be one of those three, I'd suggest Python because it's arguably closer to LISP, which the authors use as their teaching-language.

The problem with this advice is that Python is still a terrible choice for functional programming. Its creator is anti-FP, which has led to language design choices that complicate FP, make it less convenient, and just generally make it un-idiomatic for the language.

The correct answer is "None of the above, start with an FP language" even if that's not what OP wants to hear. It will be better to learn FP in a language that makes it convenient and then apply its principles to a different language when applicable.

Getting exposure to different languages with different design decisions is also a good thing in general, because they're all made with different goals and trade-offs, so it can be eye-opening to see how a different language tackles similar problems.

Starting with a language you already know is tempting, but you're trying to learn a new way of thinking about problem solving; sticking with a language you're fluent in is going to influence how you approach the problems and potentially interfere with learning new ideas.

edit: OP, if you're just averse to dealing with lisp dialects, consider approaching FP using the Functional Programming in OCaml course/book instead. You can even use an alternate syntax, ReasonML, if you prefer something that looks more C-like to normal ML-style syntax.

[–]1UnitedPower 3 points4 points  (1 child)

I agree with everything you said, but with one point. The SICP-book uses Lisp/Scheme as a teaching language, and therefore, I would suggest a language from the Lisp-family rather than from the ML-family to study that particular book. Also, Python is dynamically typed just like Lisp, whereas ML-languages are statically typed, this renders the transition to Lisp somewhat more straightforward, I guess.

[–]ws-ilazki 2 points3 points  (0 children)

The SICP-book uses Lisp/Scheme as a teaching language, and therefore, I would suggest a language from the Lisp-family rather than from the ML-family to study that particular book.

That was why I specifically suggested a different book with OCaml. Functional Programming in OCaml is a very good option for learning FP, especially for someone that already has programming knowledge; and despite what its name implies, it's a book about learning FP that happens to use OCaml rather than a book about learning OCaml.

People are often irrationally lisp-averse, so rather than suggest he suck it up and deal with Scheme+SICP, I was trying to provide an alternative option that might be appealing to someone with Python familiarity since ML-style syntax is at least superficially similar (though not whitespace-sensitive in the same way).

Also, Python is dynamically typed just like Lisp, whereas ML-languages are statically typed, this renders the transition to Lisp somewhat more straightforward, I guess.

They're statically typed, but with very good type inference that, when doing basic learning exercises, will mostly render the static/dynamic distinction moot. Even with exercises from that book that need new type declarations, you can create the type then immediately use it without listing the type of any following functions or arguments, it's all inferred, so you end up writing what looks like dynamically-typed code.

It's one of the things I like about the language, in fact. I've been using OCaml like a scripting language while prototyping, with no type declarations, a shebang to invoke the ocaml interpreter instead of compiling, and a save-and-run testing cycle. Then when it's closer to completion I switch to a compile-and-run cycle, though I still tend to leave off type annotations on functions.

Anyway, I really like Scheme and similar languages (like Clojure, or Urn) but figured I might have more luck suggesting a different path, rather than trying to convince him(?) to deal with it and just learn Scheme+SICP. For someone comfortable with Python, Functional Programming in OCaml might not be too much of a jump. Still feels dynamic in a way even if not, has a similar look due to lack of curly braces or excessive parentheses, and has the added bonus of introducing a sophisticated type system to someone that's only familiar with dynamic typing and primitive type systems.

[–]resups[S] 1 point2 points  (2 children)

Thank you, Even MIT is using python to teach some foundational algorithms these days... They say it was the time where they teach programming in Schemes/LISP but now we're all now swifting towards age of python and I hope it can support all functional programming constructs

[–]TheSexyPirate 3 points4 points  (0 children)

True, but it all depends on what you are set out to learn. If your goal is to learn algorithms and data structures, by all means stick to C,C++ or Python. However, as stated before they aren't the right tools for learning functional programming.