Rail 的“陷阱”和学习曲线——它会停止吗?

发布于 2024-11-09 01:38:31 字数 1994 浏览 0 评论 0 原文

我已经开发一个新的 Rails 项目几个星期了,虽然我对框架中的出色插件和一些非常出色的功能感到惊讶......但我也有点失望。我很担心。

我想我犯了一个错误。

我应该继续前进,还是回到我熟悉的地方? (Java/Spring)

  1. 除非您正在寻找“简单的示例”,否则在谷歌上搜索规则的例外情况、特殊情况等确实会降低生产力,并且对我来说越来越成为常态。

  2. 主站点、博客、截屏视频等中的文档和示例大多已过时。对于每 5-10 个示例,其中 1 个实际上是正确的。

  3. 做任何应该“有效”的新事情几乎永远不会成功。我尝试遵循文档和示例,但我的结果似乎有所不同,并且我发现文档和示例中从未提到的问题。事实上,这种情况似乎一直在发生。

  4. 我尝试 CoffeeScript 及其与 Rails 集成的经历是一场灾难。每当发生“编译器错误”时,无法看到问题所在,这真是令人沮丧。

  5. ActiveRelation 真的很棒,直到您需要进行连接 7 个表的查询。然后它开始崩溃。我认为您可以在第一次学习 Hibernate 时更快地完成 7 个表连接查询并可靠地完成它。

  6. 在 Rails 中测试实际上非常困难。发生了太多的“魔法”。由于 Ruby 是动态的,我不知道需要调用什么来正确测试某些东西。规则似乎总是有例外。

    例如,Devise 的工作方式与您期望的一样......直到您想在助手中测试 Devise。它根本行不通,因此您必须在测试中发明 Devise 生成的方法才能使测试通过。您不需要为控制器执行此操作。

    有一些博客教授如何使用 Rails 进行测试,但它们非常琐碎并且没有多大帮助。其中一些实际上很糟糕。我发现如何以比我发现的许多博客更好的方式有效地测试验证。我只是发现在测试方面我经常独自一人。

  7. 为什么当您切换到生产环境时图像和样式表无法正常工作?这太疯狂了。如果你用谷歌搜索的话,很多人都会问这个问题……但这个框架并不能“正常工作”。

    我最终害怕部署这个应用程序。生产版本似乎不像开发版本那样工作。可怕。

  8. 由于某种原因,在添加 jquery-rails 和 devise 后,在 ajax 请求期间未传递身份验证令牌。我必须添加 4 行 JavaScript 代码才能使其工作。这花了我5个小时。在 Java 中,因为您有适当的会话,所以您甚至不需要考虑此类内容。

  9. 测试运行速度非常慢。我有大约 780 个测试,这比有 1800 个测试的 Java 项目花费的时间要长得多。

  10. 在浏览器中测试应用程序非常慢。渲染某些页面大约需要 1/4 秒...而且甚至没有进行太多的 ORM 操作!即使对于具有 1 个数据库查询的页面,也需要 100-200 毫秒。这太疯狂了。

  11. 文档通常已经过时。例如,尝试覆盖 Devise 中的内容是一件痛苦的事情,因为文档实际上告诉我要做错误的事情。经过数小时的谷歌搜索并在另一个论坛上等待 48 小时后,我才得以有人告诉我我需要做什么。我想做的就是让登录表单拒绝 User.enabled 为 false 的用户。就是这样。事实证明,我压倒了“主动?”而不是“active_for_authentication?” - 这是 RDoc 中的一个错误。

  12. ORM 的行为方式非常奇怪,一点也不直观。当您关联新对象时,插入/更新的工作方式有所不同。它也不像 Hibernate 那样级联...这让我怀疑它没有跟踪脏对象?如果是...那么为什么默认情况下不设置级联?像这样的事情很难默认。 Rails 不应该在良好的默认设置方面表现出色吗?

两周后,“陷阱”的数量并没有真正减少。我真的很担心和害怕。我知道 Java 也不能免于陷阱和问题,但我通常每月会遇到 2-3 次问题,而不是一周遇到 30 次问题。

我几乎认为,当您考虑到该平台的稳定性、快速性和可预测性时,使用 Java/Spring 时缺乏敏捷性现在不再是太大的负担。您可能会编写更多的代码,但您确切地知道发生了什么...您永远不会真正处理无声的故障...而且事情确实往往会更加可靠地工作。

我开始质疑在这个新项目中使用 Rails 的方法。

I've been developing a new rails project for a few weeks, and while I am amazed at the awesome plugins and some of the really great features in the frameworks... I am a little disappointed too. And I am worried.

I think I made a mistake.

Should I press on, or go back to what I was familiar with? (Java/Spring)

  1. It seems that unless you are looking for "simple examples", googling for the exceptions to the rule, special cases and so on really hampers productivity and is increasingly becoming the norm for me.

  2. Documentation and examples from the main site, blogs, screencasts, etc. are mostly out of date. For every 5-10 examples that are out there, 1 of them is actually correct.

  3. Doing anything new that should "just work" almost never does. I try and following documentation and examples, but my results seem to vary and I discover problems never mentioned in the documentation and examples. This seems to happen all the time actually.

  4. My experience with trying out CoffeeScript and it's integration with Rails was a disaster. Not being able to see what the problem is whenever a "compiler error" occurs is beyond frustrating.

  5. ActiveRelation is really awesome, until you need to make a query that joins 7 tables. Then it starts to break down. I think it's possible that you can get that 7-table join query done in Hibernate quicker and finished reliably the first time you are learning it.

  6. Testing is actually really hard in Rails. There's just too much "Magic" going on. Since Ruby is dynamic, I have no idea what I need to call to test something appropriately. There always seems to be exceptions to the rule.

    For example, Devise works like you would expect... until you want to test Devise in helpers. It just won't work, so you have to invent the Devise-generated methods in your tests to make the tests pass. You don't need to do this for controllers.

    There are some blogs that teach how to test using Rails, but they are extremely trivial and not very helpful. Some of them are just bad actually. I found how to effective test validations in a far superior manner than many of the blogs I found for example. I just find that I am often on my own when it comes to testing.

  7. Why does images and stylesheets not work properly when you switch to production for? This is insane. Tons of people ask this if you google it... yet the framework doesn't "just work".

    I am scared to death to deploy this application eventually. The production version doesn't seem to work anything like the development version would. Scary.

  8. For some reason, after adding jquery-rails and devise, the authentication token wasn't getting passed during ajax requests. I had to add the 4 lines of javascript code to make it work. This took me 5 hours. In Java, because you have proper sessions, you never even need to think about this type of stuff.

  9. Tests run really slow. I have about 780 tests, and it already takes much longer than a Java project which has 1800 tests.

  10. Testing the application in the browser is really slow. It takes like 1/4 of a second to render some of the pages... and there isn't even that much ORM action going on! Even for pages with 1 database query, it takes 100-200 milliseconds. This is crazy.

  11. Documentation is often out of date. For example, trying to override things in Devise was a pain because the documentation actually told me to do the wrong thing. Only after hours of googling and waiting 48 hours on another forum was I able to have someone tell me what I needed to do. All I wanted to do was have the login form reject a user where User.enabled was false. That's it. It turns out, I was overriding "active?" instead of "active_for_authentication?" - which was an error in the RDoc's.

  12. The ORM behaves in really strange ways that are not intuitive at all. Inserts/updates work differently when you are associating new objects. It also doesn't cascade like Hibernate would... which makes me suspect that it's not tracking dirty objects? If it is... then why isn't cascading set by default? Things like this are hardly good defaults. Isn't Rails supposed to be great at good defaults?

After 2 weeks, the number of "gotchas" hasn't really slowed down. I am really worried and scared. I know Java isn't immune to gotchas and problems, but I generally ran into problems about 2-3 times a month - not 30 in one week.

I am almost thinking the lack of agility when using Java/Spring is not much of a burden now when you consider how stable, fast and predictable the platform is. You maybe write a bit more code, but you know exactly what's going on... you never really deal with silent failures... and things do tend to work a lot more reliably.

I am starting to question using Rails for this new project.

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

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

发布评论

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

评论(1

傲性难收 2024-11-16 01:38:31

你能做的最好的事情就是掌握“使用 Rails 进行敏捷 Web 开发”,当我几年前开始学习时,阅读和研究这本书中的示例确实帮助我理解了事情应该如何工作,它也充当了非常好的参考资料,每当您想阅读某些主题时都可以深入研究。

最新版本似乎是:
http://www.amazon.co.uk/Agile-Development-Rails-Pragmatic-Programmers/dp/1934356549/ref=sr_1_1?ie=UTF8&qid=1305991885&sr=8-1

Best thing you can do is get hold of the 'Agile Web Development with Rails', when I started out a few years back, reading and working over the examples in this book really helped me understand how things should work, it also acts as a great reference that you can dive into whenever you want to read up on certain topics.

The latest version seems to be:
http://www.amazon.co.uk/Agile-Development-Rails-Pragmatic-Programmers/dp/1934356549/ref=sr_1_1?ie=UTF8&qid=1305991885&sr=8-1

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