面向对象程序员方案
我对Scheme非常感兴趣,并从一些玩具编程示例开始,并且正在阅读Paul Graham的On Lisp 。
我还没有找到一本旨在向“面向对象的人”教授Scheme的书或网站,即像我这样99%的编码都是用c++/Java/Python完成的人。
我认为闭包是一种 object-y,因为它们具有本地状态,并提供一个或多个可以访问该状态的函数。但我不想学习Scheme只是为了将我现有的习惯移植到它上面。这就是为什么我现在正在学习Scheme而不是Common Lisp;我担心 CLOS 可能只会成为我现有的面向对象习惯的拐杖。
理想的情况是有一本书或一个网站,提供以 OO 语言以及以 Schemey 方式解决的问题的案例研究。我想我最喜欢科学计算和/或计算机图形问题,但任何事情都可以。
任何教学线索将不胜感激。
I'm thoroughly intrigued by Scheme, and have started with some toy programming examples, and am reading through Paul Graham's On Lisp.
One thing I haven't been able to find is a book or website intended to teach Scheme to "OO people", i.e. people like myself who've done 99 % of their coding in c++/Java/Python.
I see that closures are sort of object-y, in the sense that they have local state, and offer one or more functions that have access to that state. But I don't want to learn Scheme only to port my existing habits on to it. This is why I'm learning Scheme rather than Common Lisp at the moment; I fear that CLOS might just serve as a crutch to my existing OO habits.
What would be ideal is a book or website that offers case studies of problems solved in both an OO language, and also in Scheme in a Schemey way. I suppose I would most appreciate scientific computing and/or computer graphics problems, but anything would do.
Any pedagogical leads would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
恭喜你,我的朋友!热爱cs,热爱函数式编程。
如果你是Python开发人员,需要3-4天的时间来思考方案
这是我见过的最好的简单教程http://www.shido.info/lisp/idx_scm_e.html
我找到了这门课程http://cs.gettysburg.edu/~tneller/cs341/scheme-intro/index.html 它可能对您有用
Congrat you, my friend ! Love cs, love functional programming.
If you are python developer it takes 3-4 days to think in scheme
Here is the best simple tutorial I have ever met http://www.shido.info/lisp/idx_scm_e.html
I found this course http://cs.gettysburg.edu/~tneller/cs341/scheme-intro/index.html and it may be useful for you
“The一个Pythonista在Schemeland中的历险记”。它(显然)是从 Python 程序员首次使用Scheme 的角度编写的。它的一个特别好的事情是,它包含当前实现的概述以及每个方案实现之间的兼容性问题,不幸的是,这可能会在您刚开始时引起一些头痛。
对于对象系统,这两个 文档(链接自 这里)给出了使用闭包的非常简单的玩具实现的很好的例子,我发现这些例子有助于理解它们在捕获状态中的使用。
One beginner's resource that is very helpful and geared very much toward the casual reader is "The Adventures of a Pythonista in Schemeland". It's written (obviously) from the point of view of a Python programmer taking first steps with Scheme. One especially nice thing about it is that it includes an overview of the current implementations and compatibility issues between each scheme implementation, which, unfortunately, can cause some headaches when you're just starting out.
With regards to object systems, these two documents (linked from here) give nice examples of very simple toy implementations using closures that I found helpful in understanding their use in capturing state.
如果您开始使用Scheme,请查看如何设计程序。本书介绍了解决问题的“Schemey”方法。我认为没有一本书可以针对相同的编程问题对面向对象和函数式解决方案进行比较。但是有一个很好的演示展示了像Scheme这样的动态语言如何为需要复杂的问题提供简单的解决方案静态类型 OOP 语言中的设计模式。
If you are starting off with Scheme, have a look at How to Design Programs. This book presents the "Schemey" approach to problem solving. I don't think there is a book that compares OO and functional solutions to the same programming problems. But there is a nice presentation that shows how dynamic languages like Scheme could provide simple solutions to problems that demand complex design patterns in statically typed OOP languages.
我怀疑 CLOS 会成为旧习惯的拐杖,我发现它与 C++/Java/Python 中的 OO 风格有很大不同,而且非常有趣。我不明白所有的细节,但我会推荐 Peter Seibel 的 Practical Common Lisp。如果您在阅读On Lisp时没有遇到太多麻烦,那么您应该能够深入了解 PCL中介绍CLOS的章节。另外,我还推荐他的 Google 技术讲座,比较 Java 和 Common Lisp。
这里还有一些建议可以使其成为更全面的答案:
经典文本计算机程序的结构和解释 涵盖了第 3 章中使用闭包构建模块化系统的相当多的示例(并解决了引入状态和可变性的问题)。第 2 章包括一些通用的和数据/类型导向的编程,这可能有助于激发 CLOS 的研究。这本书确实不需要介绍,它是一本巨著,我从春天开始才慢慢地读它。如果您对Scheme感兴趣,强烈推荐。
虽然 SICP 是一本很棒的书,但它也并非没有缺陷:文章 “计算机科学课程的结构和解释”详细阐述了对 SICP 的一些批评,由如何设计程序的作者撰写(我没有读过 HTDP,但是听说非常好)。虽然这篇文章不会具体教你你正在寻找什么——比较函数式编程和面向对象编程——但无论如何它确实很有趣。他们的新生本科课程从第一学期介绍使用Scheme(我认为是PLT/Racket)的函数式编程开始,然后是一个学期使用C++或Java进行面向对象编程……至少这是他们在论文中描述的课程。
Peter Norvig 的这些幻灯片解决了面向对象编程中常见的一些设计模式,并展示了为什么它们在像Scheme和Lisp这样的动态函数式语言中缺失或不必要:http://norvig.com/design-patterns/
我谨慎地推荐这本书,作者与《Little Schemer》书籍相同:一点 Java,一些模式。我不能确定这是否是一本真正的好书,它非常奇怪,并且有一些非常糟糕的排版决策(斜体、衬线、可变宽度、上标不属于编程文本) ,但看一下可能会很有趣。无论如何,你可能会发现它很便宜。不要那么认真地对待这个建议。我认为最好坚持计划文本。
ps 我不同意一项评论,该评论指出函数式编程在面向对象编程中并不那么复杂,我认为这是严重错误的表述。函数式编程的所有广度确实令人难以置信。当您超越 map/filter/reduce 和一流函数,并查看函数领域中的其他内容(例如惰性求值、避免副作用和突变以及强大的静态类型语言)时,它会变得非常有趣,并且肯定与传统 OO 编程一样复杂。我自己只是触及了皮毛,但已经发现了很多新想法。编程是一件复杂的事情,无论是面向对象还是函数式编程。
I doubt CLOS would serve as a crutch for old habits, I found it to be pretty different from the OO style in C++/Java/Python, and very interesting. I don't understand all the details, but I would recommend Peter Seibel's Practical Common Lisp. If you are reading On Lisp without much trouble, you should be able to dive into the chapters introducing CLOS in PCL. Also, I'd recommend his Google Tech Talk comparing Java and Common Lisp.
Here's a few more recommendations to make this a more full-fledged answer:
The classic text Structure and Interpretation of Computer Programs covers quite a few examples in chapter 3 of building modular systems using closures (and addresses issues with introducing state and mutability). Chapter 2 includes some generic and data/type-directed programming which could be helpful for motivating study of CLOS. This book really needs no introduction though, it's a towering work, and I've only been reading it slowly since the spring. Highly recommended if you are interested in Scheme.
While SICP is a great book, it's not without its flaws: A really interesting look at these is the essay "The Structure and Interpretation of the Computer Science Curriculum" which elaborates on a few criticism of SICP, and is written by the authors of How to Design Programs (I haven't read HTDP but I hear it's very good). While this essay won't teach you specifically what you are looking for - comparing functional and OO programming - it is really interesting anyway. Their freshman undergraduate course starts with a first semester introduction to functional programming using Scheme (I think, PLT/Racket) and is followed by a semester of OO programming with C++ or Java... at least that's the course they describe in the essay.
These slides from Peter Norvig address some of the design patterns common in OO programming and show why they are missing or unnecessary in dynamic, functional languages like Scheme and Lisp: http://norvig.com/design-patterns/
I cautiously recommend the book by the same authors as the Little Schemer books: A Little Java, A Few Patterns. I can't say for sure if this is a really a good book or not, it was incredibly strange and there are some really bad typesetting decisions (italic, serif, variable-width, superscript doesn't belong in a text on programming), but it might be interesting to take a look at. You can probably find it cheap, anyway. Don't take this recommendation that seriously. I think it would be better to stick to the Scheme texts.
p.s. I have to disagree with one comment stating that functional programming is not as complicated at OO programming, I think that's grossly misstating it. Functional programming in all its breadth is truly mind-boggling. When you go beyond map/filter/reduce and first-class functions, and take a look at other things in the functional realm like lazy evaluation, avoiding side effects and mutation, and the strong, static-typed languages, it gets pretty interesting, and is certainly just as complicated as traditional OO programming. I've only just scratched the surface myself but have discovered a great deal of new ideas. Programming is complicated business, whether OO or functional.