|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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. ![]() |
|
#4
|
|||
|
|||
|
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.
__________________
-- I'll provide you with reference points; if they dont work, refer to something else. If you process text, this might make your life a little easier. |
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||
|
|||
|
Thanks Jeff. Appreciate the reply. Makes sense.
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Straight into OO ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|