Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Programming Technology

Is Ruby on Rails Maintainable? 348

kale77in asks: "I've become a big fan of Ruby over the past few months, but I'm not at all sure about Ruby On Rails. Automatic code generation sets of alarm bells in my mind; so that, to RoR's promise of 'Web Development that Doesn't Hurt', I automatically add '...until you have to maintain it'. On the other hand, some writers and coders I respect (like the Pragmatic Programming mob) seem to be fans. I've mainly written generators in Python, to produce PHP/SQL/Java from SQL files, but I've always gone back to well-constructed objects, where extension and overloading offers more precise and maintainable customization than auto-generation allows. So is Rails just a nice RAD tool for disposable, cookie-cutter apps (which have a place, of course)? Is high-level generation just a bad OO substitute? And what has your experience of Rails' maintainability been?"
This discussion has been archived. No new comments can be posted.

Is Ruby on Rails Maintainable?

Comments Filter:
  • Yes, very (Score:5, Interesting)

    by Bruce Perens ( 3872 ) * <bruce@perens.com> on Wednesday December 21, 2005 @01:58PM (#14310512) Homepage Journal
    Maintainability is a combination of several factors. Most important is: can you read and understand the code? Ruby on Rails wins in this category because it's brief - smaller and thus easier to comprehend than Java - without being cryptic like APL. Second most important is: is it easily modified? Here Rails wins again, because of the say it only once philosophy and because of Ruby's duck typing *. Say-it-once means that you don't have to track down the other places where you've had to say the same thing (as in Java) and change them. Duck typing means you can change an object substantially without the user of that object seeing the change, because the user only knows what methods the object is expected to respond to, not the object's type.

    Bruce

    * Duck typing: If it looks like a duck and sounds like a duck, it's a duck! Object types don't matter to the users of Ruby objects. What matters is that the object responds to a particular collection of methods. This is something like virtual functions, but does not require inheritance from any class or virtual class although inheritance from a Ruby module (sort of an abstract base class) is often the best way to implement those methods. So, a Ruby object might export a collection of methods called Enumerable and would respond positively to an is_enumerable? method to identify that those services are available.

  • Eh kindof (Score:2, Interesting)

    by oGMo ( 379 ) on Wednesday December 21, 2005 @02:14PM (#14310657)

    Rails is OK. It's a great way to get into the language and attract users, and for that I appreciate its existance.

    That said, as a fairly long-time user of Ruby myself, I wouldn't use it. Many of the features it provides are more academic proof-of-concept implementations than well-tested, well-polished ones. It requires you to do a lot of things manually that could easily be done automatically, and you still write bits of SQL in your code. Also, more importantly, it doesn't provide an application layer that entirely abstracts the functionality from the interface. This is bad for any number of reasons. Finally, it's pretty much tied to MySQL, so if you use PgSQL or Oracle (and you should), then you're in for a big headache.

    That said, if you're interested in Ruby and/or Ruby on Rails looks cool to you, check it out and play around with it. It's also not the only thing that ruby provides to develop applications, even web applications. If you're developing a more serious app, you may look at stuff like PageTemplate [coolnamehere.com] for the frontend, ObjectGraph [nitrohq.com] for your ORM, and soap4r [ctor.org] for services.

    So regardless of your stance on Rails, check out Ruby... there's a lot of cool stuff.

  • TurboGears (Score:3, Interesting)

    by ultrabot ( 200914 ) on Wednesday December 21, 2005 @02:23PM (#14310733)
    In the meantime, if you want rails-like development but with Python check out TurboGears [turbogears.org].

    It's been raising quite a storm lately, and for a good reason!

  • Re:It's obvious... (Score:5, Interesting)

    by qslack ( 239825 ) <qslack@@@pobox...com> on Wednesday December 21, 2005 @02:28PM (#14310763) Homepage Journal
    This is exactly right. The scaffolding is seen as the major feature of Ruby on Rails by far too many people. It's not. In fact, if anyone were making a serious, production-level app, they wouldn't even use the scaffolding. It serves only three purposes: to help newcomers to the language become familiar, to jumpstart a simple Web app, and to look amazing on the screencasts [rubyonrails.com].

    Ruby on Rails is great. At the very least, everybody should try it. It's no silver bullet, but it is a huge improvement over most everything else out there.

    Using Rails is a bit like using a Mac: you always run into these little helpful features that make you think it was created just for you.
  • Re:Yes, very (Score:3, Interesting)

    by Eivind Eklund ( 5161 ) on Wednesday December 21, 2005 @02:33PM (#14310803) Journal
    No, you're not guaranteed that something that respond to the same methods with the same parameter counts is really implementing the same interface. However, while writing an article and a bunch of code for type checking in Ruby, I read've read probably hundreds of discussions on this and certainly thousands of messages. I've not once heard anybody claim that they'd seen this happen or heard of it happening as a problem in practice.

    Eivind.

  • Re:Yes, very (Score:3, Interesting)

    by Bruce Perens ( 3872 ) * <bruce@perens.com> on Wednesday December 21, 2005 @02:41PM (#14310864) Homepage Journal
    Not only will O'Caml detect this error at compile time, it can do so without forcing the programmer [to] write type declarations everywhere.

    Only if the object's type is explicit at some point in the function call tree at compile time, I suppose. I can think of dynamic scenaroios where this would not be knowable at compile time.

    Static checking as you describe would involve propogating type information from the called function up through its callers while that call sequence is being checked. While nobody does this for Ruby (I think Matz's Ruby compiler is still in alpha-test) it's theoretically possible.

    Thanks

    Bruce

  • Re:Java Interfaces (Score:2, Interesting)

    by Tamerlin ( 940577 ) on Wednesday December 21, 2005 @03:16PM (#14311144) Homepage
    "Java interfaces allow you to declare that something is a Duck, so it must be a duck. However, with Java, I can ensure that anything I think I want to call a duck does indeed fulfill the contract of being a duck. "

    How? If I have an interface with a method "quack" that is supposed to print a message from a string you pass it, and I write a class implementing it that calculates the factorial of 1,023,342 instead, you can call it, and it will compile and even run, but still violate the contract of being a duck.
  • Coincidental naming (Score:3, Interesting)

    by kabloom ( 755503 ) on Wednesday December 21, 2005 @03:19PM (#14311165) Homepage
    The problem that he's referring to in ruby is coincidental naming.

    I implement a function with a name "join" without knowing what the rest of the world uses it for. (e.g. my "join" joins a chatroom, but the standard use of "join" is to concatenate all of the objects in an array together into a string.) Suddenly my object looks like a duck, and quacks like a duck, but doesn't act like a duck. Ruby thinks it can be used in the same context that everything else uses it in, but semantically it can't be used there.

    Inheritance prevents conicidental naming problems by making the default assumption that two similarly named functions *don't* do the same thing, and can't be used in the same place. You override this assumption by indicating that the class inherits from a certain class (C++) or implements a certain interface (Java).
  • Re:Java Interfaces (Score:3, Interesting)

    by Dalroth ( 85450 ) on Wednesday December 21, 2005 @03:26PM (#14311224) Homepage Journal
    Java interfaces allow you to declare that something is a Duck, so it must be a duck. However, with Java, I can ensure that anything I think I want to call a duck does indeed fulfill the contract of being a duck. What in Ruby forces you to properly export the collection of methods in Enumerable when you defined is_enumerable to return true? Nothing?

    I call BS. Just because a Java class implements an interface, does not mean it implements what is expected of the interface. If your compare method returns a -1 when it should return a +1, you aren't a duck, you're a retarded duck and Java let's you do that just like Ruby.

    Bryan
  • by IamTheRealMike ( 537420 ) on Wednesday December 21, 2005 @03:27PM (#14311230)
    Of course it isn't as simple as that. If it was, everybody would use Ruby or Python for everything and Java/C#/C++ would be dead.

    In practice, strong typing and the lack of Ruby-style dynamism allows compilers and runtimes to make optimizations they otherwise couldn't. Those matter, a lot, try looking at the memory usage or execution speed of your average Ruby program sometime! Worse, it's an unfixable problem, at least without modifying the language itself quite heavily.

    I think the way we're going to go with language design, as an industry, is more like Boo [codehaus.org] - a language which on the surface looks like Python and has many of the clarity and programmer efficiency features that make Python so much fun to use, but under the hood is actually a traditional strong/static typed language. In Boo, type inference is used to let you drop many of the redundant type declarations that normally clutter up Java/C#/C++ style code, and a smart compiler plugin system is used to let you add new features to the language easily. This is traded off against the ability to do things like add/remove methods at runtime which are hard to implement in a time/space efficient manner.

  • by meowsqueak ( 599208 ) on Wednesday December 21, 2005 @04:01PM (#14311531)
    I have no experience with Ruby or RoR but I am a software engineer like many people here and I would like to stick up for automatic code generation. Modern software is extremely complex and even when excellently designed and implemented by a skilled person or team it is still subject to faults. Automatic code generation, when done properly, is an excellent way to reduce the effort and risk associated with creating certain types of complex systems. A classic example is a parser - hand writing parsers can be done, of course, but they can be notoriously difficult to test and small grammar changes can upset the entire structure of the parser. In this situation, automatic code generation is not only useful, it's also safer and more reliable. If you have to change the grammar, you just reconstruct the parser code.

    A compiler is a form of automatic code generation - you don't compile your source by hand, usually, you let the compiler do it. The compiler becomes a cornerstone of your industry and is trusted perhaps far beyond what it really deserves. But the important thing is that it is hopefully consistent and can compile to a lower form much more accurately and faster than you or I or anyone can. You can make large scale higher-level changes without worrying too much about the effects of these at the lower level.

    Unfortunately all generalisations fail when you talk about specifics and the implications of this don't need stating, but I think it's unwise to say 'automatic code generation sets off alarm bells' when it is more accurate to think 'writing it manually should set off alarm bells' for many implementations.
  • Re:Uhm... (Score:4, Interesting)

    by Jack9 ( 11421 ) on Wednesday December 21, 2005 @04:02PM (#14311547)
    Practical question about Rails implementation with Ruby.

    I concede that "scaffolding" is used by EVERY PROGRAMMER. That's the idea behind code reuse. "I'll adapt my authentication I made for a BB system to use as auth for an entire website." "I'll use my pretty table CSS from last year for displaying this data."

    Can you alter the templates generated? If I have coding standards implemented, I have serious doubts the default RoR scaffold templates specifically adhere to mine. If I can't alter these templates, the answer to the article is no. If I can alter these templates (I assume it's possible), the answer to the article is yes.

    How is this article generating all this Ruby-anti-Ruby nonsense when it's a question of Rail implementation? More importantly, why isn't there a PHPoR?
  • Generated Code? (Score:3, Interesting)

    by misleb ( 129952 ) on Wednesday December 21, 2005 @04:40PM (#14311878)
    I started my first real Rails project with generated scaffolding, but after a few days there was almost nothing left of it. And I almost wish I had never generated the scaffolding because I had to spend time cleaning up tons of files and method stubs that I was never going to use.

    I do, however, use the basic "scripts/generate " scripts. They save me a minute or two of creating files and directories and class definitons. Handy, I suppose, but I am not sure if this is considered "generated code." The only "code" that Rails really generates for me is HTML and SQL (Tag Helpers and ActiveRecord) which is pretty nice, actually. The less HTML and SQL i have to write and more I can focus on the actual code, the better.

    Re: code generation replacing OO model:

    I have no idea what the OP is talking about. RoR is pure OO.

    Probably the only thing that I find a little frustrating about RoR is the shear volumn of files involved in a project. Navigating through them gets gradually more time consuming.

    -matthew
  • Usage of RoR (Score:5, Interesting)

    by achacha ( 139424 ) on Wednesday December 21, 2005 @05:37PM (#14312336) Homepage
    RoR is pushing this whole codegen thing too much (I personally think codegen is the work of mediocre developers who have ego issues, but that's just me). I used RoR for about a day and wrote a little app then realized that maintenance is a pain and that I would have to manually change all the code anyways to make it behave as I want and that codegen created something I did not want. Then I weighed it against writing sevlets and JSP pages and RoR didn't look so appealing. Ruby is a nice scripting language but I didn't like the architecture of rails. Just not for me. Performance was quite bad too, about 6 times slower than JSP for fetching some data from a database, manipulating it (which is the bulk of the work) and displaying it (given JSP gens compiled into Java and takes advantage of JIT). Ruby is a nice language though, but it's not as useful as python. So I struggle to find a place where I can use it, maybe it can be nice as a simple embedded script language (similar to Lua).

    If asked what I would use to develop a server side app, I would have to look at volume and complexity then go in the order: C/C++ > servlets > JSP/PHP > RoR (from highest volumen/complexity to lowest). For high volume/complexity C/C++ is still the best efficient way to go but not for all, requires more work from the developers and not for average/weak developers. Servlets are a good next step if performance is not extremely important. JSP/PHP is a good way to run a site that doesn't have complex computation or one that is static content based (news, blog, forum, and such). RoR I would use for maybe some prototyping or to build a quick and dirty app to provide a simple view of the database (but even then I would probably lean to PHP). YMMV.
  • Re:Yes, very (Score:3, Interesting)

    by Bruce Perens ( 3872 ) * <bruce@perens.com> on Wednesday December 21, 2005 @06:24PM (#14312709) Homepage Journal
    there's no reason you couldn't have a "Java on Rails", that's almost as good.

    Hibernate, Struts, Spring, and so on add facilities to Java that bring it more in the direction of Rails. There's a famous example of a Java programmer who set out to show that he could write concise code in Java on a par with RoR. He attempted to duplicate an existing RoR program. He sent the result to the RoR creator, claiming success. It's three times the size of the equivalent RoR code. So, I'm still waiting to see someone make Java as concise.

    Bruce

  • by Sircus ( 16869 ) on Thursday December 22, 2005 @02:45AM (#14315425) Homepage
    I'm not saying the other guy's right, but, er, you're revealing your ignorance a bit. ...it's java.lang.String...it can dynamically grow and shrink.

    No it can't, it's immutable. Strings can only create new objects which have grown or shrunk. Admittedly, the optimised implementation uses the same backing array for the new String, but it's still a new String. A StringBuffer (which in my books is another string class) can dynamically grow and shrink. In 5.0/1.5 there's now also StringBuilder.
  • Re:Uhm... (Score:3, Interesting)

    by caseydk ( 203763 ) on Thursday December 22, 2005 @11:49AM (#14317876) Homepage Journal
    I did an interview with Mike Ho - the lead developer of QCodo - just a couple weeks ago. He laid out some pretty good differences between RoR & QCodo. Check it out: http://codesnipers.com/?q=node/187 [codesnipers.com]

He has not acquired a fortune; the fortune has acquired him. -- Bion

Working...