在不使用任何框架的情况下使用 Ruby 完成 Web 应用程序 - 有多难?陷阱? [英] Complete web apps in Ruby without using any frameworks - how difficult? Pitfalls?

查看:18
本文介绍了在不使用任何框架的情况下使用 Ruby 完成 Web 应用程序 - 有多难?陷阱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个 Ruby 菜鸟.这个社区有没有人写过没有任何框架的 Ruby 应用程序?(我的目标是自己写一篇.)告诉我们你的经历.有多难?您使用的最低抽象是什么?有哪些陷阱?谢谢.

I am a Ruby noob. Has any one in this community written a Ruby app without any frameworks? (edit:My goal is to write one on my own.)Tell us about your experience. How difficult is it? Whats the lowest abstractions you used? What are the pitfalls? Thanks.

推荐答案

这是一个非常非常广泛的问题.您是要编写自己的框架,还是只是一个简单的类似 CGI 的应用程序(您可以使用 ERB 轻松做到这一点).

This ia a very, very broad question. Are you looking to write your own framework, or just a simple CGI-like application (you can do that with ERB quite easily).

我认为不使用框架(包括您编写的框架)的最大缺陷是,其他人很难弄清楚您的代码在做什么以及为什么要这样做.此外,您还失去了框架捆绑在一起的所有自动化测试、数据绑定、打包、文档生成和其他好处.

The biggest pitfall I can see to not using a framework (including one that you've written) is that it will be much, much harder for other people to figure out what your code is doing, and why. Plus, you lose all the automated testing, data binding, packaging, document generation, and other goodies that frameworks tie together.

当然,如果您自己完成所有的工作,那么您只是编写了一个框架.:)

Of course, if you do all the tying-together yourself, you've just written a framework. :)

如果没有,你写的意大利面条代码很糟糕.

If not, you've written a horrible mess of spaghetti code.

由于您是 Ruby 初学者,我会阅读 Rails(或 Sinatra)源代码,并尝试弄清楚它的作用.不是因为它一定是一个很好的例子,而是因为你对 Web 框架的理解将通过深入研究几个来更加完整.这是非常非常有价值的.

What I'd do, since you're a beginning Rubyist, is read the Rails (or Sinatra) source, and try and figure out what it does. Not because it's necessarily a great example, but because your understanding of web frameworks will be a lot more complete by diving into a couple. And this is very, very valuable.

我看了你的一些其他帖子,看起来你是学生,所以我要告诫你不要编写自己的框架,不是因为它本身是一个坏主意,而是因为一个软件框架代表 - 即使用 X 语言的多年经验的总和.

I looked at a few of your other posts, and it looks like you're a student, so I'm going to caution you against writing your own framework, not because it's a bad idea per se, but because of what a software framework represents -- namely, the sum total of years of experience in working with language X.

程序员就像海狸——我们想要构建.我们希望自己构建一切,始终以修复现有工具的缺点为理念.虽然这是一件非常崇高的事情,但它往往会导致人们走上很少完成的道路,因为他们不愿意使用其他人编写的工具,通常归结为一些次要的、美观的原因.年轻的程序员对此尤其感到内疚,我也不例外——我浪费了数年的时间来写网络服务器和数据库抽象层,而不是写我本可以赚钱的软件.

Programmers are like beavers -- we want to build. We want to to build everything ourselves, always with the idea of fixing the shortcomings of the existing tools. While this is a very noble thing, it tends to lead people down the path of getting very little done, because they aren't willing to use tools that other people have written, often for what boil down to minor, cosmetic reasons. Younger coders are especially guilty of this, and I was no different -- I wasted literally years screwing around with writing webservers and database abstraction layers, instead of writing software that I could have made money with.

如果我可以回去做不同的事情,我会开始为已经存在的框架做出贡献,而不仅仅是试图从头开始做正确的事".

If I could go back and do things differently, I would have started contributing to the frameworks that already existed, rather than just trying to "do it right" from scratch.

现在,首先使用其他人的工作"的规则有一个例外,那就是当您拥有使用工具的经验时,可以知道什么时候该构建新东西了.DHH(Rails 的创始人)在决定编写 Rails 之前是一名长期的 Ruby 编码员.

Now, there is an exception to that rule of "use other peoples' work first", and that is when you've got the experience with the tools to know when it's time to build something new. DHH (the guy who started Rails) was a very long-time Ruby coder before he decided to write Rails.

作为 Ruby 新手,您可能更擅长阅读其他人编写的内容并修补/改进它,而不是仅仅从自己开始.您将更多地了解该语言,为社区做出宝贵贡献,并为自己提供一些不错的简历素材.

As a Ruby newbie, you're probably better-served at reading what other people have cooked up, and patching/improving that, rather than just starting on your own. You'll learn more about the language, make a valuable contribution to the community, and give yourself some good resume fodder.

这篇关于在不使用任何框架的情况下使用 Ruby 完成 Web 应用程序 - 有多难?陷阱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆