多范式语言

发布于 2024-07-05 10:41:09 字数 95 浏览 9 评论 0原文

使用 PHP(因为我现在正在使用它)等语言,它支持过程和面向对象的范例。

是否有一个好的经验法则来确定哪种范例最适合新项目? 如果没有,你如何做出决定?

In a language such as (since I'm working in it now) PHP, which supports procedural and object-oriented paradigms.

Is there a good rule of thumb for determining which paradigm best suits a new project? If not, how can you make the decision?

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

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

发布评论

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

评论(2

扮仙女 2024-07-12 10:41:09

这完全取决于您想要解决的问题。 显然,您可以用任何一种风格(过程式或面向对象)解决任何问题,但您通常可以在开始编写代码之前的规划阶段找出哪种风格更适合您。

有些人喜欢编写用例,如果他们看到很多相同的名词一遍又一遍地出现(例如,一个人从银行取钱),那么他们就会走面向对象路线并使用这些名词作为他们的对象。 相反,如果您没有看到很多名词并且确实有更多动词,那么过程式或功能性可能是正确的选择。

Steve Yegge 有一篇很棒但很长的帖子 像往常一样,从不同的角度探讨这一点,您可能会发现它也有帮助。

It all depends on the problem you're trying to solve. Obviously you can solve any problem in either style (procedural or OO), but you usually can figure out in the planning stages before you start writing code which style suits you better.

Some people like to write up use cases and if they see a lot of the same nouns showing up over and over again (e.g., a person withdraws money from the bank), then they go the OO route and use the nouns as their objects. Conversely, if you don't see a lot of nouns and there's really more verbs going on, then procedural or functional may be the way to go.

Steve Yegge has a great but long post as usual that touches on this from a different perspective that you may find helpful as well.

Spring初心 2024-07-12 10:41:09

如果您正在为自己做一些事情,或者您只是做一个原型,或者测试一个想法……请使用脚本语言为您提供的自由风格。

之后:始终以对象的方式思考,尝试围绕 OO 范式组织您的工作,即使您正在编写过程性内容。 然后,重构、重构、重构。

If you're doing something for yourself, or if you're doing just a prototype, or testing an idea... use the free style that script languages gives you.

After that: always think in objects, try to organize your work around the OO paradigm even if you're writing procedural stuff. Then, refactorize, refactorize, refactorize.

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