August 26th, 2007, 08:13 PM
Straight into OO ?
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.
August 26th, 2007, 09:11 PM
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
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.
August 26th, 2007, 09:43 PM
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.
August 27th, 2007, 07:39 AM
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
True happiness is not getting what you want, it's wanting what you've already got.
March 17th, 2008, 04:23 PM
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.
March 17th, 2008, 07:29 PM
Thanks Jeff. Appreciate the reply. Makes sense.
Originally Posted by JeffCT