Java 与 Ruby on Rails 相比,Spring 难吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1119692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:59:40  来源:igfitidea点击:

Is Spring hard compared to Ruby on Rails?

javaruby-on-railsspring

提问by johnny

If I have little to no experience in either of them, but know enough Java and Ruby to be comfortable, is one framework harder to learn than the other? Is one easier to use for the beginner on these?

如果我对它们中的任何一个都几乎没有经验,但对 Java 和 Ruby 有足够的了解,那么一个框架比另一个更难学习吗?初学者更容易使用这些吗?

I know it is hard to answer. Just looking for general thoughts on it.

我知道这很难回答。只是在寻找关于它的一般想法。

采纳答案by kgiannakakis

Both Spring and Ruby on Rails share the "convention over configuration" moto. This reduces code lines significantly. Ruby on Rails is a Web Framework and it could be compared with Spring MVC, together with an ORM tool like Hibernate.

Spring 和 Ruby on Rails 共享“约定优于配置”moto。这显着减少了代码行。Ruby on Rails 是一个 Web 框架,它可以与 Spring MVC 以及像 Hibernate 这样的 ORM 工具进行比较。

One could say that Spring together with Spring MVC or another MVC framework and Hibernate are the closest that you can get to Ruby on Rails for the Java world.

可以说,Spring 与 Spring MVC 或其他 MVC 框架以及 Hibernate 是 Java 世界中与 Ruby on Rails 最接近的。

However, Spring has a much wider scope than RoR.

但是,Spring 的范围比 RoR 广泛得多。

回答by cletus

The thing about Spring is that it is mainly two things:

Spring的事情主要是两件事:

  1. It is essentially an "adapter" or "facade" for existing technologies and libraries; and
  2. It is philosophicallydifferent from say J2EE in that it is all about dependency injection or inversion of control, which is a fundamentally different approach than what came previously.
  1. 它本质上是现有技术和库的“适配器”或“外观”;和
  2. 它在哲学上与 J2EE 不同,因为它完全是关于依赖注入或控制反转,这是一种与以前完全不同的方法。

For (1) for example, Spring can do things like help ease the pain of what JMS provider you use or do things like translate exceptions generated by different databases into Spring runtime DataAccessExceptions.

例如,对于 (1),Spring 可以做一些事情,例如帮助减轻您使用的 JMS 提供程序的痛苦,或者做一些事情,例如将不同数据库生成的异常转换为 Spring 运行时 DataAccessExceptions。

Spring is typically labelled a lightweight container for this reason. In the Spring world ("application context"), vendor differences typically become just an issue of configuration. Dependency injection does a lot of things like making testing much easier (done right).

出于这个原因,Spring 通常被标记为轻量级容器。在 Spring 世界(“应用程序上下文”)中,供应商差异通常只是配置问题。依赖注入做了很多事情,比如让测试变得更容易(做得对)。

The biggest challenge in learning and using Spring is learning to think that way if you haven't previously done anything like it.

学习和使用 Spring 的最大挑战是,如果您以前没有做过类似的事情,那么学会以这种方式思考。

Other than that, there's really not a lot to Spring and that's a good thing. Spring doesn't get in your way. You choose whatever technologies you want to use and Spring nearly always just makes using them and integrating them easier.

除此之外,Spring 真的没有太多东西,这是一件好事。春天不会妨碍你。您可以选择想要使用的任何技术,而 Spring 几乎总是让使用它们和集成它们变得更容易。

Once you get into the DI/IoC way of thinking.

一旦你进入了 DI/IoC 的思维方式。

回答by Jeremy French

Spring is quite big, it has two facets that I know ofthe dependency injection and AOP. Ruby on rails is very much geared up towards writing web apps.

Spring 相当大,它有我所知道的依赖注入和 AOP两个方面。Ruby on rails 非常适合编写 Web 应用程序。

If you are looking to write a web app I would expect you would find ROR easier to use as it is much closer to the problem domain.

如果您想编写一个 Web 应用程序,我希望您会发现 ROR 更易于使用,因为它更接近问题域。

If you wanted to use spring to write a web app you would most likely need to learn a few more technologies as well which may get a bit overwhelming. However if you are just learning for fun, combining spring with the head first patterns book can be fun.

如果您想使用 spring 编写 Web 应用程序,您很可能还需要学习更多技术,这些技术可能会让人不知所措。但是,如果您只是为了好玩而学习,将 Spring 与 Head First Patterns 结合起来会很有趣。

回答by Rafe

I suspect this question is really about Spring MVC. One of the hallmarks of Ruby on Rails is "convention over configuration". If you use the right names, you spare yourself a lot of work writing configuration files. With Spring, you're probably going to need to go ahead and type in a lot of that configuration.

我怀疑这个问题真的是关于 Spring MVC 的。Ruby on Rails 的标志之一是“约定优于配置”。如果您使用正确的名称,您就可以节省大量编写配置文件的工作。使用 Spring,您可能需要继续输入大量该配置。

Also Rails routing is much more powerful and concise than the alternatives in Spring. In recent releases, Spring has tried to move to more of a convention over configuration model, but it will still seem burdensome to a Rails developer.

此外,Rails 路由比 Spring 中的替代方案更强大和简洁。在最近的版本中,Spring 试图转向更多的约定而不是配置模型,但对于 Rails 开发人员来说,它仍然看起来很繁重。

回答by Eric the Red

After working with Rails, Spring (and just about any other Java coding) feels tedious and time consuming.

在使用 Rails 之后,Spring(以及几乎任何其他 Java 编码)感觉乏味且耗时。

回答by Rich Kroll

Comparing RoR to Spring directly is not a direct or easy comparison.

直接将 RoR 与 Spring 进行比较并不是直接或简单的比较。

RoR focuses rather tightly on developing websites easily. RoR does a great job of making crafting pages, linking them together, and persisting data very easy. RoR was designed explicitly with web development in mind, and is a great tool for this. That said, when you need to do more "enterprise" development (messaging, integration, etc.), or have a need to do something that does not fit into the RoR conventions, you will feel some pain.

RoR 非常专注于轻松开发网站。RoR 在制作页面、将它们链接在一起以及持久化数据方面做得非常好。RoR 的设计明确考虑了 Web 开发,是一个很好的工具。也就是说,当您需要做更多的“企业”开发(消息传递、集成等),或者需要做一些不符合 RoR 约定的事情时,您会感到一些痛苦。

That said, Spring has many facets: Spring IoC, Spring AOP, SpringMVC, etc. that is aimed at solving a myriad of different development issues faced by developers. Spring has a very wide assortment of technologies that will ease most development challenges you will face.

也就是说,Spring 有很多方面:Spring IoC、Spring AOP、SpringMVC 等,旨在解决开发人员面临的无数不同的开发问题。Spring 拥有种类繁多的技术,可以缓解您将面临的大多数开发挑战。

To directly answer your question, it directly depends on your requirements. If you are developing simply database backed web applications, RoR will allow you to quickly and easily develop an application and is easier for the beginner to get started with. Spring on the other hand has a steeper learning curve and more configuration necessary, but gives you much more flexibility and power.

直接回答你的问题,直接看你的要求。如果您正在开发简单的数据库支持的 Web 应用程序,RoR 将使您能够快速轻松地开发应用程序,并且初学者更容易上手。另一方面,Spring 具有更陡峭的学习曲线和更多必要的配置,但为您提供了更多的灵活性和功能。

Once facet that I think is often missing from this type of discussion is the power of the community, tooling, and libraries available. Java/Spring is a mature platform with extensive community and tooling support, while Ruby/RoR has a great community, the tooling is still catching up IMO.

我认为在这种类型的讨论中经常缺少的一个方面是社区、工具和可用库的力量。Java/Spring 是一个成熟的平台,拥有广泛的社区和工具支持,而 Ruby/RoR 有一个很棒的社区,工具仍然在追赶 IMO。

回答by sal

I don't like this comparison.

我不喜欢这种比较。

You should compare Grails or Spring Roo to Rails. Groovy Grails is a RoR like system built on Spring that uses Groovy for rails-like DSLs. Roo is a vaguely railish pure java DSL for RoR like apps.

您应该将 Grails 或 Spring Roo 与 Rails 进行比较。Groovy Grails 是一个建立在 Spring 上的类似 RoR 的系统,它使用 Groovy 来处理类似 Rails 的 DSL。Roo 是一个模糊的纯 Java DSL,用于类似 RoR 的应用程序。

I really hate to say it this way but Spring is a platform. You use it to wire Java technologies together. You can use it for non-web, non-database, zero UI apps. You can use it to write batch servers. You can use it to write clients.

我真的很讨厌这样说,但 Spring 是一个平台。您可以使用它来将 Java 技术连接在一起。您可以将它用于非 Web、非数据库、零 UI 应用程序。您可以使用它来编写批处理服务器。您可以使用它来编写客户端。

Rails isn't the same. I really like rails for data driven web apps but I shudder at the thought of writing a batch processing system in rails.

Rails 就不一样了。我真的很喜欢 Rails 用于数据驱动的 Web 应用程序,但一想到在 rails 中编写批处理系统,我就不寒而栗。

回答by Scott Schulthess

I've worked with both somewhat extensively, and I found Spring and the most popular "add-ons" hibernate, JSF, JSP, Rich Faces, etc extremely hard to use.

我对两者的使用都比较广泛,我发现 Spring 和最流行的“附加组件”hibernate、JSF、JSP、Rich Faces 等非常难以使用。

Mostly it was because of a personal dissatisfaction with the documentation and the available books and tutorials on the full stack. Also it just is nowhere near as user friendly of a framework as Rails. It really feels like just showed a better way to develop web apps in almost every way.

主要是因为个人对完整堆栈上的文档和可用书籍和教程不满意。此外,它远不及 Rails 那样用户友好的框架。感觉就像是在几乎所有方面展示了一种更好的方式来开发 Web 应用程序。

回答by Jet Abe

I have recently moved to using Spring MVC + WebFlow from 4 years on ruby on rails.

我最近在 ruby​​ on rails 上使用了 4 年的 Spring MVC + WebFlow。

Ruby is great rails is the productivity egde. However, spring MVC is geared more towards the enterprise with layers of design and patterns over patterns.

Ruby 是伟大的 rails 是生产力egde。但是,spring MVC 更适合具有设计层和模式而非模式的企业。

I don't say it is rubbish it's interesting to learn a different approach towards UI development.

我并不是说这是垃圾,学习不同的 UI 开发方法很有趣。

You can not compare the two. Spring MVC is more tailored towards designs that can be reused in Portlet development or development of webflows that can be altered without changing a lot of java code.

你不能比较两者。Spring MVC 更适合可以在 Portlet 开发或 webflow 开发中重用的设计,这些设计可以在不更改大量 java 代码的情况下进行更改。

There are subframeworks like spring security and not to mention Aspects in all shapes and kinds I find all this a big learning curve. The views can be rendered with JSF or JSP/JSTL.

有像 spring security 这样的子框架,更不用说各种形状和种类的 Aspects 我发现所有这些都是一个很大的学习曲线。可以使用 JSF 或 JSP/JSTL 呈现视图。

Honestly, I think java is a language that has not evolved in ages and people have had substantial investments in this stack they have hacked and overwritten ways around code. Annotations and XML or be it Generics they are all with an aim to make the language cater to ever increasing and evolving world around it.

老实说,我认为 Java 是一种多年未进化的语言,人们对这个堆栈进行了大量投资,他们已经破解并覆盖了代码。注释和 XML 或泛型它们都旨在使语言迎合不断增长和发展的世界。

Contrasting that to a modern dynamic language like ruby there is a lot of productivity difference. Ruby is dead simple programmer friendly and superior in every way.

与像 ruby​​ 这样的现代动态语言相比,生产力差异很大。Ruby 在各方面都非常简单,程序员友好且优越。

Rails is a very opinionated piece of software dictated by what DHH and the rest think and want in it.

Rails 是一个非常固执的软件,由 DHH 和其他人所想和想要的东西决定。

Yes, its great for web app development in fact you will feel you have acquired the missing thing when you start programming rails.

是的,它非常适合 Web 应用程序开发,事实上,当您开始编写 Rails 时,您会觉得自己已经获得了缺失的东西。

The trouble is rails has received a lot of negative publicity over the years. I am not sure about it's future at this time and choosing between something proven vs something that is getting cloned in every new web framework is a risk.

问题是这些年来,rails 受到了很多负面的宣传。我现在不确定它的未来,在经过验证的东西和在每个新的 web 框架中被克隆的东西之间进行选择是一种风险。

ASP.net mvc, grails cakePHP every popular MVC framework out there has cloned rails.

ASP.net mvc, grails cakePHP 每个流行的 MVC 框架都克隆了 Rails。

Is spring hard compared to rails?

弹簧比钢轨硬吗?

I think if you apply your mind both are equal in terms of the learning curve.

我认为,如果你运用你的思想,两者在学习曲线方面是平等的。