#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    15
    Rep Power
    0

    Straight into OO ?


    Hi all,
    I"d like to start learning just Ruby without the Rails for now, by converting some of my DOS batch scripts into Ruby scripts. I"ve got batch files that do everything from, commit some files to my SVN repos, to copying some files to a particular destination, to switching directories via a menu with choices.

    I'm wondering if it would be worth it to immediately start using the OO features in Ruby and actually write objects that I could reuse in some way or another. Like maybe a base class that takes care of basic copying, and then unzipping at the destination.

    And then I can inherit from that, but specify with the subclasses, what directories to copy to?

    Or is that not a good idea.. and maybe I should just focus on learning syntax and other stuff and just write ruby procedural scripts for now.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2006
    Posts
    2,270
    Rep Power
    1737
    I never thought of OO as primarily a coding issue. It's really about design. So learning OO syntax means absolutely nothing about whether you can use OO properly. This is akin to seeing the technical description of a hammer (the handle is x inches long, the hammer head is made of x composite material with y added in, shaped like so and so), and seeing the fact that a hammer is used to pound something, preferably on a nail and not your thumb.

    If you have experience with OO design, sure go ahead and learn OO syntax. That really isn't all that hard to do. Whether it's OO in Java, Ruby, PHP, Python, C++, C#, you're looking to apply the same concepts and just need to figure out the syntax variations.

    But based on your question, I figure that you are relatively a new programmer. And you might be jumping on to the OO thing because it's a commonly cited buzzword. You'll use OO syntax and all, but that doesn't mean your design may be any good. OO syntax does not make your code any better.

    If you have a bunch of scripts, writing equivalently procedural code may the best translation. Is there a point to writing those objects? Maybe there is. Maybe there isn't. But it has nothing to do with whether you are new to Ruby. It's a code design question. If you are unable to see intuitively that your code could use an OO paradigm, then don't stretch and make up ways to use an OO syntax feature. Are you creating a number of base classes and so on for the sake of accomodating a design, or are you creating a design that tries to make use of all those features? The second is a sure sign of bad code.

    Comments on this post

    • Yawmark agrees
    • Joseph Taylor agrees : Excellent response. Made me laugh, too.
    When you ask a question, be prepared to tell us: what have you tried? If you think you don't need to try anything, we will never be interested in helping you. If you agree with the link, and you refuse to answer that question, you are being a hypocrite.

    Need help with broken code? Your question should be like a good bug report: (1) It has the smallest number of steps to reproduce the problem you see (2) It tells us precisely what you expected to see and (3) It tells us what you saw and how it differed from what you expected. We need all three to help you.
    Want better answers? Tell us what you Googled for and what steps you took to answer your own question.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    15
    Rep Power
    0
    Wow, you're very intense

    I really don't take my batch scripts that seriously, .. this was just a casual question asked in a casual mood on a sunday eve. but thanks. Have a beer though, would ya.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    Careful. You got good advise for free. Remember that in the future you may need to get another, less trivial, question answered. If you tell people that you dont like the way they inform you, you are likely to get nothing when you need it.

    Comments on this post

    • Yawmark agrees
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog
  8. #5
  9. No Profile Picture
    Dev
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2001
    Posts
    1,436
    Rep Power
    41
    You're already using the OO features of Ruby. Everything in Ruby is an object. If you mean the advanced features, like blocks, or actually writing your own classes - why not? No reason to continue using it like a functional language when it has that kind of power.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    15
    Rep Power
    0
    Thanks Jeff. Appreciate the reply. Makes sense.

    Originally Posted by JeffCT
    You're already using the OO features of Ruby. Everything in Ruby is an object. If you mean the advanced features, like blocks, or actually writing your own classes - why not? No reason to continue using it like a functional language when it has that kind of power.

IMN logo majestic logo threadwatch logo seochat tools logo