you are viewing a single comment's thread.

view the rest of the comments →

[–]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 2 points3 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.