Slashdot Mirror


Exploring Active Record

An anonymous reader writes "Everyone knows that no programming language is a perfect fit for every job. This article launches a 'new series by Bruce Tate that looks at ways other languages solve major problems and what those solutions mean to Java developers. He first explores Active Record, the persistence engine behind Ruby on Rails.'"

15 of 266 comments (clear)

  1. Re:Still looking for an IDE by gnud · · Score: 2, Informative

    - http://wiki.python.org/moin/IntegratedDevelopmentE nvironments
    If you need a drag'n'drop gui editor, try Eric (pyQT( or BoaConstructor (wxWindows).

  2. Re:Still looking for an IDE by lifeisgreat · · Score: 3, Informative

    Try RadRails - it's the best Rails-specific IDE I found during my brief searching. I noticed a few bugs, but at least it's still being developed.

  3. Re:Anyone else Railed-out? by Dante+Shamest · · Score: 2, Informative
    I want init() functions.

    90% of the time, when you call an init() function, you're going to call a free() function too. Let C++ do the grunt work for you. Use the RAII pattern.

    Put your init() code in the constructor and your free() code in the destructor. That way you won't forget to call free().

    Heck I don't even like C++ for fogging-over-functionality with inheritance, virtual functions and overloading.

    You don't have to use those C++ features if you don't want to. You can program in C-style in C++ if you wish. virtual and inheritance are optional. These days templates do most of what inheritance and virtual functions can do. And I don't understand why you would dislike overloading. Aren't you tired of thinking up names for functions that do the same thing, but just take different number of arguments?

  4. Re:Now, more buzzword-friendly? by ziplux · · Score: 2, Informative

    An object-relation mapping (ORM) that "just works" and uses reflection on the database to produce business objects without the developer writing more than 3 lines of code is anything but a minor improvement. ActiveRecord is also more than an ORM. It allows developers to declare that an object "acts as a list," which then allows the object to be sorted in an array. There are many other such "meta-programming" constructs in ActiveRecord.

    It also gives you a lot of stuff for free; migrations from one database schema to another, for example, are wrapped in ActiveRecord calls and are thus database-agnostic. You don't have to worry about packaging one SQL update file for MySQL and another for Postgres and another for MS SQL. The console is really cool too...it allows you to interactively play with your objects. You can even run it in 'sandbox' mode, so that all of your changes are rolled back when you're done playing.

  5. ActiveRecord for the New Developer by Anonymous Coward · · Score: 1, Informative

    I have to give a shout-out to Ruby on Rails and database handling - specifically for the new developer. I've seen clients of mine (whom I consult and help deploy Rails apps) new to OO latch on to ActiveRecord very quickly, and the rapidly growing support (and marketing!) for the Rails community is promising for its long-term success.

    Kudos to Yukihiro, David, Dave, Thomas, and the hundreds of others who have put together Ruby and the Rails framework to help developers grow the Web 2.0.

    ~William
    www.RailsHosting.org

  6. Rails rocks (but isn't a silver bullet) by PetriWessman · · Score: 5, Informative

    I've been playing around with Rails and AR quite a bit lately, and it has changed the way I think about programming in many (positive) ways. I come from a heavy Java / J2EE background (do that for a living, serverside systems), and Ruby + Rails is a breath of fresh air. Ruby is simply a wonderful language, there is something very "zen" about it, and Rails is inspired. Sure, it builds on a lot of old concepts, but the brilliance is where it leverages the power of the Ruby language to do things in very efficient and nice ways.

    Yes, there is a lot of "black automagic" involved in Rails. It's where the power is, and you can override pretty much everything is you want to. If you're uncomfortable with magic stuff happening behind the scenes and don't want to learn Ruby so you really understand that magic, Rails might not be for you.

    I'd claim that pretty much every serious programmer (VB scripters don't count :) should learn Ruby, at least the basics. It might not become your new favorite language (like it has for me), but it will give you a fresh new perspective on how to code stuff.

    Ruby does have a few downsides:

    • There is no Unicode support. For a language coming from Japan that's surprising (and sucks). I'm given to understand that fixing this is in the roadmap for Ruby(?).
    • It's an interpreted language (like Perl, Python etc), so if speed really is an issue for you then it's not a good choice (for most things nowadays, Ruby is more than fast enough)
    • The scoping of variables in blocks is a bit funky.
    • Some of the organization in the standard libraries is a bit weird, and there is some repetition of functionality. I think this is due to historical reasons (std lib code has evolved over the years)

    (there are probably more, but I'm still only learning the language)

    As for Rails, well, again there are downsides. Nothing is perfect.

    • No Unicode support (inherits Ruby weakness). For web apps, this really sucks.
    • Poor localization support in general (again, sucks).
    • ActiveRecord is nice, but works best for from-the-ground-up projects. Integrating with a legacy schema might get ugly, a mapping layer (like Java's Hibernate) would work better there.
    • No support for clustering and other heavy-lifting technologies. If you're building a seriously big app, Rails might not be the optimal choice. But face it, 99% of web apps don't need stuff like that. Right tool for the job, and all that
    • Still a young framework, and evolving. This is both good and bad. Bad, since the framework is changing while you code. Good, since it means that bugs (and maybe the above weaknesses, too) are getting fixed.

    So: it's not a silver bullet. Nothing is. But for a large majority of the modern-day web app use cases, it's very nice, productive and, well, elegant. It lets you to do quick prototypes and keep your code clean, you don't end up with the insecure and ugly mess most PHP apps end up being.

    1. Re:Rails rocks (but isn't a silver bullet) by consumer · · Score: 3, Informative

      I don't know about Python, but Perl and more recent versions of PHP are not interpreted. They are compiled to opcodes and then the opcodes are executed. With a persistent environment like mod_perl, you are always running the compiled code after the inital load. Both of them have much better base language performance than Ruby does at this point. I expect that Ruby will eventually work this way too.

    2. Re:Rails rocks (but isn't a silver bullet) by revscat · · Score: 3, Informative

      Well rails is a very good framework + toolset, but like every other enforcing toolset which tries to cover a lot of ground by automating stuff it has a huge problem, follow the road and you are set, if you cannot follow the road you are screwed.

      I have seen this complaint lodged many times, and at first I was concerned about it because of this, but I have yet to actually run into it. Rails is flexible enough that all the conventions it uses are overridable, and if you know of any exceptions to this please let me know, because I am still evaluating it. For example: by default AR assumes your primary key column is named id, but you can override that per-table if you like, or globally via environment.rb:

      ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore

      Similarly, while AR expects plural table names, you can override that with the following:

      ActiveRecord::Base.pluralize_table_names = false

      So I don't agree with the (overly stated, IMHO) belief that Rails falls on its face when you move outside its conventions. My experience does not match this.

  7. Re:Anyone else Railed-out? by Anonymous Coward · · Score: 1, Informative

    I'm not a Rails expert, but Ruby is one of the few languages that has a built-in complete line-by-line trace mode.

    ruby -rtracer myprogram.rb

    See here for instructions.

    This prints a complete line-by-line trace of the execution of your program. You can use this to work out exactly what paths were taken by the code (I can imagine it would be very big for rails, but grep is your friend :)

  8. Re:In a comparison, Ruby suffers for one big reaso by LarsWestergren · · Score: 2, Informative

    Java though, treats people who want to use UTF-32 as second-class citizens.

    Java has support for Unicode 4 since Java 5, released september 2004.

    --

    Being bitter is drinking poison and hoping someone else will die

  9. Re:language matters a great deal by AArmadillo · · Score: 2, Informative
    Programmer productivity in different languages can be orders of magnitude different.
    Most studies show that this is blatantly untrue -- programmer productivity is generally independent of language chosen. In other words, given an 'average' programmer with X years of experience in their language, they will take about the same amount of time to complete a given task in their language.
  10. Re:language matters a great deal by aricusmaximus · · Score: 4, Informative

    Most studies show that this is blatantly untrue -- programmer productivity is generally independent of language chosen.

    Excuse me? Which studies?

    Certainly not this one:

    http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpp rt_computer2000.pdf

    Nor this one:

    http://www.erlang.se/publications/Ulf_Wiger.pdf

    Nor even this one:

    http://www.theadvisors.com/langcomparison.htm

    And this well-regarded programmer certainly doesn't agree that the choice of language doesn't matter:

    http://www.mindview.net/WebLog/log-0025

    I tell you what -- interview a group of experienced programmers for a prospective project to write a database-backed web application with complex requirements. Tell them that they will be required to program in assembly language because "most studies show that... programmer productivity is generally independent of language chosen." Record their responses and post them to Slashdot.

  11. Re:Now, if he could apply the same wisdom to SQL, by Decaff · · Score: 2, Informative

    Great, "rich query languages" that wrap richer query languages.

    No, in some cases the portable query language is more featured that the language it wraps. JDOQL implementations can provide rich querying even on systems with no built-in query language (like filesystem storage).

    That are highly portable across databases, but themselves are not portable across application layers (do *any* reporting tools support them?

    Of course they are. There are reporting tools like JasperReports that can use Hibernate Query Language directly.

    is there an ANSI standard for ORMs?)

    There are JCP standards for Java ORMs that are fully supported by many vendors.
    Is there any modern standard for SQL that is fully supported by any vendor? No.

    When a developer needs to run adhoc queries in order to diagnose problems with data in a database, to test impacts of schema migration, etc - do they write SQL or application code? Keep in mind that these are not likely to be simplistic queries...

    They can use either. Why on Earth are you assuming that these portable query languages are restricted to simplistic queries?

    Seriously SQL isn't the greatest language in the world, but I have a hard time understanding why anyone that works with database applications can't handle complex queries.

    You are missing the point. Of course they can handle complex queries. What they don't want to have to do is to re-implement thousands of those complex queries in order to migrate to another database product.

    It's like someone working on the linux command line that refuses to learn bash. Or like a web developer that refuses to learn HTML and just uses FrontPage instead.

    No. The portable query languages aren't less rich than SQL. They are simply portable. That is the big difference.

    And aside from the "When in Rome" argument, consider the benefits of learning a data-oriented approach to working with data.

    Who says this isn't the case?

    SQL is more different from java, python or ruby than lisp is. One of the best things a programmer can do is to to become fluent in multiple different types of languages. Compare SQL's set-based logic to lisp or python. Learn to think of data in terms of sets and aggregates instead of just one row at a time. Until you do that you'll never understand reporting, which is really about how to answer basic business questions.

    This is completely irrelevant. Portable query systems in Java are data-oriented, and work with sets and aggregates just like SQL. The difference is that they are 100% portable.

    But maybe that's why we've never seen a powerful reporting tool come out of the java community?

    No - you have never seen a powerful reporting tool. This does not mean there aren't any. There are plenty.

    JasperReports is a good one.

    I think posters really need to do some more research before commenting on matters like this - I keep reading posts like this that bear little relation to reality.

  12. Re:Hmm... by Decaff · · Score: 3, Informative

    That stuff sounds really interesting. Do you have links for some of the research?

    Yes. The best place to look is the specifications at the JCP.

    JDO 2.0 is

    http://www.jcp.org/en/jsr/detail?id=243

    EJB 3.0 (including JPA) is

    http://www.jcp.org/en/jsr/detail?id=220

    I've heard of hibernate, but not the JPA. Is that going to be part of the standard JRE? I hate having my code rely on goofy 3rd party add-ons.

    JPA is going to be a standard part of J2EE, but can be used stand-alone with JRE. There are many vendors providing implementations - Sun, Oracle, JBoss, BEA, JPOX, Versant. A significant number of these are going to be open source (JBoss, Oracle, BEA). Hibernate is also going to provide an implementation of JPA.

  13. Re:Anyone else Railed-out? by ikarys · · Score: 2, Informative

    Rails is MUCH more than an ORM tool with default forms. It provides you with database versioning, Scriptaculous integration (including AJAX stuff (stupid buzzword)) Elegant field validation, Mailing, Kickass MVC, Unit testing, Fairly advanced cache model, Beautiful syntax etc etc etc And combined with ruby gems (like plugins that will update/install with ease), its just too good to pass up. Every aspect of it is elegant, except unicode, and cross database transactions .... And.. i love the fact that google/yahoo will buy your company if you use it :)