Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Programming in the Ruby Language

Posted by michael on Sat Aug 11, 2001 05:11 PM
from the no-semicolons dept.
ShoeHorn writes: "Here is a good article (1st of a 4 part series), that introduces you to the Ruby language. If you are currently a programmer coming from the likes of C++, Perl, or Python, you will see some strong similarities (especially to Python)."
This discussion has been archived. No new comments can be posted.
Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • by niekze (96793) on Saturday August 11 2001, @05:24PM (#2109940) Homepage
    when you have to deal with another stupid language every 6 months. You should only need 3 languages:

    Pick one from each of the following:

    (C/C++)
    (Perl/Tcl)
    (sh,ksh)

    Now for the 'bonus' round. [pass go and collect $200 more a month]
    (php,python)
    and for the MS route, you only get 3:

    (C++/C#)
    (Visual Basic/there is no other option)
    (Java/no other language is as useless to compete with Java)

    Now...how far off am I?
  • 15 languages is enough. (Score:2, Insightful)


    I'm just guessing, but I think I have learned at least 15 programming languages. Maybe it is 30, if you count assembly languages. At some point, learning languages must come to an end. At some point, I would like to see all the good features put into one or two languages. I have no intention of using my life learning languages that then die very quickly, like Pascal.

    It seems that, at some point, every skilled programmer becomes interested in writing either an editor or a computer language. I wrote one myself, for use with some H-P data acquisition equipment. Now both the equipment and language are obsolete.

    With every new language, there are years of extending the language, finding and curing the bugs, and wrestling with incompatibility problems. At some point, this must stop.

    Language writers should put their creativity into extending C++ rather than abandoning it.

    Consider Java, for example. There have been literally years of hassle and discussion about Java, when it could have been implemented merely as a compiler switch to a C++ compiler. The compiler switch could have provided automatic garbage collection, given error messages for use of pointers, and provided the other features of Java.

    Microsoft, following its usual abusive practices, put many ease-of-use features into Visual Basic, while keeping them out of Visual C++. The result was that there are maybe 1,500,000 programmers who know Visual Basic, but don't know a real language. And what language is Visual Basic itself programmed in? C++, of course.

    When you write in Visual Basic, you are just a dog on a leash. Anytime Microsoft wants to yank your chain, it can. If Bill Gates happens to lose interest, Microsoft can kill this one-OS language, the way it killed xBase (dBase, FoxPro), for example, by making quirky additions that no other vendor could/would follow, and then abandoning development.

    It is a shortcoming of the U.S. culture that so many men feel that they must play King on the Mountain, and try to knock everyone else down, rather than cooperate.

    Like everyone, Bill Gates has inner conflict. But don't let his anger and obsessive desire to make money reduce the quality of your life!

    So now it is Ruby, supposedly the next big thing. How long will it be until the books are all written? How long until we discover the shortcomings? Is there some feature in Ruby that can't possibly be added to another language?

    I reviewed Ruby a little about a year ago, but came to the conclusion that the documentation was extremely poor. The overall value of a language is the value of the language itself, plus the quality of documentation of the language.

    At some point, I want the merry-go-round to stop, so that I can get off.

    Is there something in C# that simply could not be made a compiler switch to C++? Do we really need more syntax? I'm not saying I know all the answers to some of these issues. But I sense that something bad is happening.

    For a few years, languages were interesting to me. But now, I just want to do the job, not discover other ways to do the job. Let's move on, rather than repeating what we have done before. Let's improve what we have, rather than starting again.
  • by ConsumedByTV (243497) on Saturday August 11 2001, @06:17PM (#2117029) Homepage
    I like the way this one teaches, is there a tutorial similar to this one for perl?
  • Please clarify (Score:1)

    by halftrack (454203) <jonkje AT inbox DOT lv> on Saturday August 11 2001, @05:31PM (#2119809) Homepage

    ... you will see some strong similarities (especially to Python).

    Yes that I can see, but what about the favorable differences.

  • by trance9 (10504) on Saturday August 11 2001, @05:43PM (#2121418) Homepage Journal

    otherwise someone worked too hard.
  • Performance, gentlmen (and ladies)? (Score:2, Interesting)

    by Quixote (154172) on Saturday August 11 2001, @06:45PM (#2125414) Homepage Journal
    Most of the advantages being quoted are "ease of use", "rapid development", etc. Fine. But what about runtime? How does Ruby compare with Perl in running efficiency? Are there any benchmarks out there?
  • Lots like PHP (Score:1)

    by SumDeusExMachina (318037) on Saturday August 11 2001, @06:29PM (#2126477) Homepage
    Except for the lack of semicolons at the end of statments, Ruby comes off looking incredibly like PHP in its basic syntax. Anyone else care to comment on the possible relation between the languages?

    This looks really cool. Sure beats the hell out of learning Perl for system administration scripts, since I already know PHP and have a basic understanding of OOP...

  • by beanerspace (443710) on Saturday August 11 2001, @10:29PM (#2129825)


    We've all seen the usenet post in the coffee room or on various websites. Usually under some title like:

    So how does one go about shooting themselves in the foot with Ruby ?
  • Horses for Courses (Score:2, Interesting)

    by Hairy1 (180056) on Sunday August 12 2001, @03:32PM (#2130411) Homepage

    A associate once said about programming its "Horses for courses". What he meant was that we should use the best tool for the job at hand. When he said it he was talking about using Clipper (an dBase clone) over Quick Basic in 1990.

    Today I know two languages to what I consider 'professional level'. On Windows I develop stand alone applications with Delphi. Its easy to develop quality code - I define quality in this case by not crashing due to obscure memory errors. Its very hard to write code in Delphi which causes memory handling issues. Writing Delphi feels like the IDE wants to help you, but if you want to get your hands dirty you still can (unlike VB).

    For Web Development I now use Java. I wouldn't use Java for stand alone GUI apps because its still too slow compared to Delphi, but for server side web development it has the features I want - portability, easy to develop in, connects with SQL etc.

    Learning a new syntax takes time. You need to be sure that a new language is going to have a payoff in terms of being able to achieve something you can't in others. For years I wrote Delphi, as it was the best horse for the course. Now with Web Develoipment the course has changed, and Java is best (for me).

    That said, a programmer should be able to learn any language. But just because you can doesn't mean you should...

  • As the guy who wrote the article. (Score:5, Informative)

    by poet (8021) on Saturday August 11 2001, @07:14PM (#2135449) Homepage
    It is important not to judge Ruby on this article.
    The content in the article is specifically designed to look like either Perl or Python. This was to generate a similarity that programmers from other languages can understand.

    The second one, article in the series looks a lot less like Perl and more like Python. This is due to Ruby being a true OO, very similar to Python.

    The third article will (if they let me write it) cover advanced Ruby structures and illustrate them by interfacing with the PostgreSQL database.

    The fourth article will cover Ruby/Qt.

    If you guys want to see these articles you may want to give some decent feedback on the Developer Works site.
  • word math (Score:1, Interesting)

    by ToWnSaVeR2 (471641) on Saturday August 11 2001, @05:20PM (#2137112)
    $salut = $salut * 3 will result in the following: Oh, I am sorry. I didn't mean to warn you... Oh, I am sorry. I didn't mean to warn you... Oh, I am sorry. I didn't mean to warn you... I am sorry but i dont see the point in performing math operations on a strings. Oh, the line noise of Ruby...
    • Re:word math by swagr (Score:3) Saturday August 11 2001, @05:25PM
      • Re:word math by ToWnSaVeR2 (Score:1) Saturday August 11 2001, @05:30PM
        • Re:word math by warfare (Score:1) Saturday August 11 2001, @05:57PM
        • Re:word math by j7953 (Score:1) Saturday August 11 2001, @05:46PM
          • Re:word math by Rumble (Score:1) Saturday August 11 2001, @10:38PM
          • 1 reply beneath your current threshold.
        • Re:word math by TheTitan (Score:1) Saturday August 11 2001, @07:20PM
          • Re:word math by stesch (Score:1) Saturday August 11 2001, @07:30PM
            • 1 reply beneath your current threshold.
        • Re:word math by ConsumedByTV (Score:3) Saturday August 11 2001, @05:39PM
          • 1 reply beneath your current threshold.
        • Re:word math by fault0 (Score:1) Saturday August 11 2001, @05:40PM
          • Re:word math by defaulthtm (Score:1) Sunday August 12 2001, @02:12PM
        • Re:word math by swagr (Score:2) Saturday August 11 2001, @05:40PM
        • Re:word math by uchian (Score:1) Saturday August 11 2001, @05:43PM
    • Re:word math by smallpaul (Score:1) Saturday August 11 2001, @05:26PM
      • 1 reply beneath your current threshold.
    • Re:word math by _Stryker (Score:2) Saturday August 11 2001, @05:34PM
      • Re:word math by b0r1s (Score:2) Saturday August 11 2001, @07:49PM
        • Re:word math by reverius (Score:1) Sunday August 12 2001, @01:24AM
          • Re:word math by naasking (Score:1) Sunday August 12 2001, @09:02AM
            • Re:word math by pyite (Score:1) Sunday August 12 2001, @12:38PM
              • Re:word math by naasking (Score:1) Monday August 13 2001, @12:37PM
            • Re:word math by reverius (Score:1) Sunday August 12 2001, @12:05PM
              • Re:word math by naasking (Score:1) Monday August 13 2001, @12:40PM
    • Re:word math by andrewgaul (Score:1) Saturday August 11 2001, @07:04PM
      • 1 reply beneath your current threshold.
    • In the words of Henry David Thoreau. . . by kfg (Score:1) Sunday August 12 2001, @04:48AM
    • Re:word math by j7953 (Score:1) Saturday August 11 2001, @05:38PM
    • Re:word math by stesch (Score:1) Saturday August 11 2001, @06:50PM
    • 1 reply beneath your current threshold.
  • so many choices (Score:2, Insightful)

    by RestiffBard (110729) on Saturday August 11 2001, @05:21PM (#2137113) Homepage
    I'm just learning python now. There just aren't enough hours in the day for me to learn all of these languages.
  • by El_Nofx (514455) on Saturday August 11 2001, @06:18PM (#2141034)
    Wow, ok so now besides having to take classes on Cobal, Java, C, C++, Pearl, Python, and Assembly I would of had to learn this one now. That makes me glad I changed my Major to Computer Engineering.
  • by Mubarmij (176563) on Sunday August 12 2001, @04:34PM (#2141670)
    This article is a good introduction, as advertised. The The Pragmatic Programmers Ruby Guide [rubycentral.com] is an excellent book on Ruby as well.. but for a really nice book on Ruby, go to Ruby User's Guide [ruby-lang.org]. It is a translated book from Japanese, and since the Japanese had Ruby 7 years before we even heard about it, it out to be good.
  • by MrSquish (459359) on Sunday August 12 2001, @02:59AM (#2141709)
    I don't like ruby mabey it's because of the name or that i like perl and python and C++ but for some reason it just seems lame to me that some language can just like say it's as good if not better then ALL thouse.. i think that with perl python php sh and C++ you can get really anything done ^_^ so why have another langauge? besides i'm already learning 3 right now! =]
  • by swagr (244747) on Saturday August 11 2001, @05:22PM (#2142326) Homepage
    here [rubycentral.com].
  • by BlackHat (67036) <TahkcalbNO@SPAMgmail.com> on Saturday August 11 2001, @05:17PM (#2144267) Journal
    ...which is the same functionality Perl uses. You said it not me, bub!
  • Time for an icon.... (Score:3, Insightful)

    by jeffy124 (453342) on Saturday August 11 2001, @08:01PM (#2145130) Homepage Journal
    I think it's time for Slashdot to draw up an icon for Ruby topics. This story is about the 5th maybe 6th Ruby related item to appear on /. in the past few months. A simple picture of a good red-ruby you would find in a jewelery store would do fine, such as one of these [israel-diamonds.com]. Anyone for it? Against it? Got a better pic to use?
  • Lots o' languages (Score:2)

    by cluening (6626) on Saturday August 11 2001, @05:36PM (#2146013) Homepage
    You know, lots of scripting languages are fun and all (TCL, Perl, Python, etc) except for one thing: They each need their own interpreter. So if I have 5 programs that people have written, each in a different scripting language, I need all 5 interperters installed. This is especially annoying on a system with limited resources. Unfortunately, I can't think of a good way to fix this problem. So I guess we will just have to get by with it...
    • Re:Lots o' languages by xanth (Score:1) Saturday August 11 2001, @05:45PM
    • Re:Lots o' languages by lavaforge (Score:2) Saturday August 11 2001, @06:16PM
      • 1 reply beneath your current threshold.
    • Re:Lots o' languages (Score:4, Interesting)

      by ChadN (21033) on Saturday August 11 2001, @07:44PM (#2125877)
      Actually, there is a lot of talk going on between L Wall and GvR to try to unify their bytecode interpreters (and maybe object models, etc.) for just this reason. I'm not awareof the details, but perhaps in some distant future, Python, PERL, and maybe even Ruby will all converge on a common backend (forget about TCL, though. It ain't never gonna happen)
      [ Parent ]
    • Re:Lots o' languages by halftrack (Score:1) Saturday August 11 2001, @05:49PM
    • Re:Lots o' languages by flippety_gibbet (Score:1) Saturday August 11 2001, @10:30PM
  • DB access? (Score:1)

    by [amorphis] (45762) on Saturday August 11 2001, @05:35PM (#2146221)
    Maybe I'm just jaded, but I don't see what the use of a language is these days without a good DB connectivity library. Did I miss it in the FAQ or the Reference Manual?
    • Yes, there is DB access (Score:4, Informative)

      by JimWeirich (466045) on Saturday August 11 2001, @05:52PM (#2147016) Homepage
      There is a DBI module at http://www.ruby-projects.org/dbi/ . There are also a number of DB specific modules. See the Ruby Application Archive ( http://www.ruby-lang.org/en/raa.html ) for a list of other software modules that are available for Ruby.
      [ Parent ]
  • Don't judge ruby based on the article (Score:5, Interesting)

    by MeowMeow Jones (233640) on Saturday August 11 2001, @06:23PM (#2146774)
    There's nothing wrong with it, it just doesn't get into any of the crazy stuff that makes ruby ruby. So wait until the other parts come out or check out the Pragmatic Programmers Guide.

    If Python was the result of Lisp and C++ having a baby, Ruby is the result of Perl and Smalltalk having a baby.

  • Strict languages vs. hacked languages (Score:4, Interesting)

    by Anonymous Coward on Saturday August 11 2001, @05:24PM (#2146983)
    I notice strong distinctions between those languages that have been developed by actual programming language researchers and those who hack together a language to scratch an itch.
    Usually the latter turns out to be some baroque conglomeration of features piled on features, creating a very top heavy feeling to the language, while the former classification languages all have a purity to them, e.g. smalltalk, lisp, and c.

    Some would defend the "hack languages" as a means to Rapid Application Development, but Smalltalk has been shown to be the most productive language, and Ruby/Python/Perl all seem to me to have a BASIC odor to them; I'm wondering if people are afraid to learn a new way of speaking?
  • ICFP (Score:1, Troll)

    by smasch (77993) on Saturday August 11 2001, @05:53PM (#2147017)
    So when are we going to see this at ICFP [inria.fr]? Oh wait, we already did, all the ruby entries failed. [inria.fr]
    • Re:ICFP by harryo (Score:1) Saturday August 11 2001, @06:23PM
  • Why learn another language? (Score:5, Informative)

    by Dalroth (85450) on Saturday August 11 2001, @07:36PM (#2153745) Homepage Journal
    Well, I see a lot of people complaining as usual... Why should they learn another language? So I thought I would throw in my $0.02 for all a languages (not just Ruby, which I am particularly fond of).

    A lot of you people come from what I call the Computer Science Student mentality. This unfortunately something I've noticed as a side effect of the way computer science is taught in most schools. It's quite unfortunate, because that clearly isn't the aim of the Professor's when they are teaching classes this way.

    I'll use my school as an example. When I started at the University of Dayton, about 7 years ago, every class was taught in ADA. It was a horrible horrible expierence. The ADA compilers were horribly lacking at the time, and anybody who has done any work in ADA will know that it is an extremely strict and picky language. That has it's good and bad sides when it comes to teaching programming, but I'll save that for a different discussion. I had no problems, since, well, I had a good solid 4 years for Pascal and C/C++ programming experience before I even started college, but this seriously affected the other students in my class.

    The problem was, about two years into the program, my school decided (thank god) to switch the department over to C++. This was a great move, because now the students were being taught a language that they could actually apply in the real world (beyond the confines of the Wright Patterson Air Force base anyway). It worked out quite well for the newer students, but my classmates were blindsided. Most of them suffered through half a semester of C (the other half of the semester was 360 assembler) and never even touched upon C++. They should have just been able to pick up a C++ book, apply the concepts they learned from their ADA classes and the syntax from the C++ book and their C course and move on, but most of them had a hard time doing it.

    Why was that? They all knew the concepts. They all knew how to write their algorithms, and their trees, and their stacks and queues. Yeah, they weren't taught how to write real software, but they clearly knew the basics. I spent more time helping others learn these concepts than I did doing my own homework the first two years, so I know what they were capable of from first hand experience.

    The problem was entirely in their minds. C++ is a huge ugly beast, and it is a bit imposing when you first start. But if you've got two solid years of programming behind you, it should be a relatively smooth and easy transition. Most of them didn't realize this though. They were scared of C++, they were scared of new languages, and they suffered as a result.

    The simple fact of the matter is, if you know one language, you know them all. It's not the syntax that makes the difference, it's the concepts that you express within the framework of the language's syntax that are the real guts of programming. My classmates took awhile to realize this (and I'm sure many of them still don't). That's the same thing with Ruby, or Python, or Perl, or just about any language. Unless you are making the jump from procedural to OOP, or OOP to Functional for the first time, you *CAN* pick up a book and learn a new language in a days time. The only thing stopping you is yourself.

    Now, the other part of this is, why would you do that? I love learning new languages, and I love learning new languages for a few reasons. These reasons apply to every programmer, and I honestly don't understand why some people are so opposed to learning something new. I guess that's what seperates a good programmer from a bad programmer. So if you want to know why you should learn Ruby, or LISP, or Haskell, or even Visual Basic, I'll tell you why.

    1. It helps keep your skills in tip top shape. Perusing a computer manual may remind you of algorithms or techniques you haven't used in a long time and forgotten.

    2. You always seem to learn something new. Not some new technical trick that only works in one lanuage (although that definitely happens), but just a different way of approaching problems that sometimes can transcend language boundaries.

    3. You may find a new language that allows you to get the job done faster!

    4. You're enhanced knowlege of languages looks great on your resume no matter what you use as your primary language.

    5. You learn the way other people think. And I don't want to gloss over this one. As a programmer, you frequently have to work with other programmers. Learning new languages is a *GREAT* way to see how other people do things. To learn the way other people think, so to speak. By learning Ruby and Smalltalk, you start to learn why people in those communities are so die hard about OOP programming styles. By learning LISP or Haskell you start to learn why Functional styles even exist! And it all comes back full circle. Techniques I learned from Haskell I now use when writing C++ programs and vice versa. It only made my C++ code better.

    Knowlege is power, and learning new languages is one (of many) ways of increasing your knowlege. Go ahead and try it, even if you think you won't use the language, and even if you're just starting out and don't think the transition from your learning language to a new one will be easy. You just might be surprised by how much you already know, and how much you have yet to learn. That's the real benefit of it.
  • Okay, it looks simple enough.. (Score:3, Insightful)

    by jcr (53032) <jcr AT idiom DOT com> on Saturday August 11 2001, @08:46PM (#2169595) Journal
    ..so, what does it offer over Python once you get past "Hello World" * 3?

    Is there anyone who can fill us in on why this language is worth using?

    -jcr
  • Mod Parent UP Funny, not DOWN Troll (Score:2, Interesting)

    by ccoakley (128878) on Saturday August 11 2001, @10:18PM (#2118261) Homepage
    Come on people, this is (meant to be) funny, not a troll. It doesn't even remotely try to make a sound argument. A troll would say:

    For embedded systems: C# has a defined bytecode that can be JIT compiled onto a variety of special purpose chips without rewriting anything.

    Web Programming: C# has built in XML and network support, and don't forget that because everything tunnels over port 80, no firewall will prevent your code from executing!

    Instead, all of the statements are absolutely absurd. Maybe you don't think it is funny, but it is absolutely NOT a troll. Trolls try to say things that have a basis in reality but are completely non-constructive for the purposes of discussion to have people respond (I'm not sure where the line to Flamebait is, but...). This is just a joke.

    [ Parent ]
  • Re:RUBY=SUCKS (Score:1)

    by Peaker (72084) <gnupeakerNO@SPAMyahoo.com> on Saturday August 11 2001, @05:40PM (#2123056) Homepage
    Microsoft was out there INNOVATING
    Name a single feature in C# that hasn't appeared in at least 3 languages prior to it.

    Anyhow, I'd take Python, C++ or LISP before I'd take C#, for any task. (The first for elegance and ease, the second for performance, and the third for its power).
    [ Parent ]
    • Re:RUBY=SUCKS by Brad Wilson (Score:1) Saturday August 11 2001, @07:13PM
      • Re:RUBY=SUCKS by Peaker (Score:1) Sunday August 12 2001, @04:31PM
      • Re:RUBY=SUCKS by TummyX (Score:1) Sunday August 12 2001, @04:48AM
        • Re:RUBY=SUCKS by Anonymous Brave Guy (Score:1) Monday August 13 2001, @07:02AM
      • 1 reply beneath your current threshold.
    • Re:RUBY=SUCKS by TummyX (Score:1) Sunday August 12 2001, @03:59AM
      • 1 reply beneath your current threshold.
  • Re:productive? (Score:2)

    by smallpaul (65919) <paul AT prescod DOT net> on Saturday August 11 2001, @05:59PM (#2125220)
    I think a developers productivity has less to do with the language hes using and more to do with how much experience he has with that language

    If that were true, you could just as easily write a text processing system in raw assembly or in a scripting language. I don't believe that. Languages are tools. Different tools effect your productivity in different ways. A farmer's productivity does depend on his tools and so does a programmer's.
    [ Parent ]
  • Re:So (Score:1)

    by Abdul2112 (308430) on Sunday August 12 2001, @12:01PM (#2134780)
    RIGHT ON. MAN, I wish I had some mod points!
    [ Parent ]
  • by ahfoo (223186) on Sunday August 12 2001, @03:34AM (#2141710) Journal
    I used to have great respect for people who could speak multiple languages --I'm off topic here talking about language in general rather than programming in specific. I've got a little anecdote though and I'd like to share it.
    I moved to Asia from California in my early twenties looking for fame and fotrune and sleazy discos. In the latter, I met all these cute asian babes who could speak three or four languages on average. As an American I was so impressed by this. I assumed these lurid disco dollies were really on the ball. Over time, I realized how far from the mark I was and how totally disconnected language skills and intelligence were.
    I knew girls who were raped and beaten repeatedly and I made the mistake of trying to step in and act all righteous like an American boy thinks he oughtta, but boy did I find out the hard way that my assistance was not welcomed and even led to hostility from the victims themselves even when they had come to me crying and asking for help.
    Fair enough, I learned a bit about the real world and how to detatch myself from other people's affairs --even the cute ones asking for help. I also learned that the ability to memorize languages is not an indicator of intelligence as I understand the term.
    Having said this, I'm very proud of my own Chinese and English literary skills and I consider myself a sophisticated programmer although I wouldn't know C code from a chemistry formula.
    It goes back to the phrase "to be well read." You know the deal, you can read three books and be well read; wheras you can read variations on the same trash all your life and never make the grade.
    [ Parent ]
  • Re:productive? (Score:2)

    by Sludge (1234) <slashdotNO@SPAMtossed.org> on Saturday August 11 2001, @06:03PM (#2146317) Homepage

    The best tool for the job isn't always the one the developer is most familiar with. There are many things I would rather develop with Perl over C, even though I've only been using it heavily for two years. I've been a C programmer of the almost-every-day sort for two years short of a decade now.

    Us younger programmers who are blessed with languages that are more articulate allow us to see the big picture sooner, and more clearly.

    [ Parent ]
  • 14 replies beneath your current threshold.