Python 和集体智慧

发布于 2024-07-19 10:13:58 字数 238 浏览 5 评论 0原文

我目前正在阅读 Toby Segaran 写的一本很棒的书,名为《集体智慧编程》(我强烈推荐)。

代码示例都是用 Python 编写的,而且我今年已经学习了一门新语言(从 VB.net 毕业到C#)我不热衷于跳上另一条学习曲线。

这给我留下了将 python 示例翻译成 C# 的问题。

问题是:代码保留在 python 中有多重要? python 中是否有一些我无法用普通托管静态类型语言执行的操作?

I'm currently reading a great book called 'Programming Collective Intelligence' by Toby Segaran (which i highly recommend)

The code examples are all written in Python, and as I have already learnt one new language this year (graduating from VB.net to C#) i'm not keen to jump on another learning curve.

This leaves my with the issue of translating the python examples into C#.

Question is: How critical is it that the code stay in python? Are there thing in python that I can't do in a normal managed statically typed language?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

榆西 2024-07-26 10:13:58

您会发现的一个挑战是,不仅算法是用 Python 实现的,而且本书还大量使用了 Python 库,如 BeautifulSoup、Numpy、PIL 等(请参阅附录 A)。

我怀疑算法的某些细节是您无法移植到另一种语言的,但是您在完成练习时会遇到困难。 另外,要翻译代码,你至少需要学习一点Python,不是吗?

我建议你深入学习Python。 如果您对与 C# 项目的互操作性有任何疑问,可以使用 IronPython。

One challenge you'll find is that not only are the algorithms implemented in Python, but the book makes extensive use of Python libraries like BeautifulSoup, Numpy, PIL, and others (see appendix A).

I doubt there are any specifics of the algorithms that you couldn't port to another language, but you'll have trouble working through the exercises. Also, to translate the code, you'll have to learn Python at least a little bit, no?

I suggest you just dive in and learn Python. You can use IronPython if you have any concern about interoperability with your C# projects.

毁梦 2024-07-26 10:13:58

您可以在所有图灵完备的语言中做同样的事情。 这里是一个用于渲染 Mandelbrot 分形的示例 SQL。 这个例子表明:即使你会使用任何语言,付出的努力也会不同。

所以我的猜测是,由于 Python 如此灵活和开放,代码会变得更长。

You can do the same things in all Turing-complete languages. Here is an example for rendering a Mandelbrot fractal in SQL. The example shows: Even if you can use any language, the effort will be different.

So my guess is that the code will become much longer since Python is so flexible and open.

饮湿 2024-07-26 10:13:58

我建议将它们翻译成 C#。 我已将第 2 章“建议”移植到 VB.Net。 一路走来,我学习 Python 作为一个副作用。 Toby 使用 Python 列表做了一些令人惊奇的事情。

处理额外的 Python 库是另一回事。 Ndelicious 与 pyDelicious 非常接近,但它缺少一些关键功能(热门帖子!)。

I suggest translating them to C#. I have been porting chapter 2 "Recommendations" to VB.Net. Along the way I'm learning Python as a side-effect. Toby does some amazing things with Python lists.

Dealing with the the extra Python libraries is another story. Ndelicious is a close match to pyDelicious, but it is missing a few key features (popular posts!).

不知所踪 2024-07-26 10:13:58

强制性 XKCD: http://xkcd.com/353/

我知道你明确表示你不想要学习 Python(今年),但将 Python 示例转换为 C# 肯定会是一个更陡峭的曲线。 只需潜入!

Obligatory XKCD: http://xkcd.com/353/

I know you explicitly say you don't want to learn Python (this year), but translating the Python examples to C# will definitely be a much steeper curve. Just dive in!

李白 2024-07-26 10:13:58

这本书是关于算法的,而不是编程的细节,选择的语言只是为了使示例具体化。 正如作者所说,“本书中的代码示例是用 Python 编写的……但我提供了所有算法的解释,以便其他语言的程序员可以遵循。” (p. xv)

Python 是一门很棒的语言,而且很容易学习,但我怀疑应用书中思想的困难不在于将代码翻译成另一种语言或一组库,而在于理解思想并修改适合您需求的代码。 我认为坚持使用你熟悉的语言有两个主要原因:1)当你的代码不起作用时,如果你用不熟悉的语言编写,你将不知道从哪里开始寻找错误,例如,如果您像大多数人一样,您甚至会开始怀疑这是否是由于 Python 中的错误造成的,但事实并非如此,但您会想知道,这会分散您的注意力。 2)在一定时间内你能记住的东西是有自然限制的; 同时学习一门语言会让你记住的东西是原来的两倍。

这取决于您对 C# 的了解程度,以及离开它后您会失去什么。

The book is about algorithms, not the details of programming, and the language of choice is just to make the examples concrete. As the author says, "The code examples in this book are written in Python... but I provide explanations of all the algorithms so that programmers of other languages can follow." (p. xv)

Python is a great language and easy to learn, but I suspect the difficulties in applying ideas from the book will not be in the translating of the code to another language or set of libraries, but in understanding the ideas and modifying the code to suite your needs. I think there are two main reasons to stay with a language you're familiar with: 1) when your code doesn't work, if you're writing in an unfamiliar language, you won't know where to start looking for errors, e.g. if you're like most people you'll even start wondering if it's due to a bug in Python, which it won't be, but you'll wonder and it will distract. 2) There are just natural limits to how much you can remember in a certain length of time; and learning a language at the same time will give you twice as much to remember.

It depends though how well you know C#, and what you lose by leaving it.

只想待在家 2024-07-26 10:13:58

Python 之于人工智能编程就像数十年来 LISP 之于人工智能编程一样。 Russel/Norvig 的名著 AI: A Modern Approach 也提供了很多 Python 示例

Python seems to be to AI programming what LISP was for for many decades. Russel/Norvig's famous book AI: A Modern Approach also provides lots of examples in Python.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文