From: Boris Glawe Date: 2005-04-07T05:24:41+09:00 Subject: Re: new! Robert wrote: > thanks a lot. > But what's the difference brtween C++ and Ruby? > I mean, why i should prefer ruby out of other programming languages? > Thank you again! > If you program ruby, you spend all your energy in solving your problem and not in writing a very cryptic language. Ruby is a very clean and easy to read object oriented language. The difference is speed!! I have an algoithm that runs 5 seconds with c++ and 16 minutes with ruby on my machine. The speed "problem" exists with all skripting languages (perl,php, etc), it's not ruby's fault. greets Boris ########### IN C++: ###################### #include using namespace std; class Base { public: Base(int x) : var(x) {} int getVar() const { return var; } void increase() { var++; } private: int var; }; class Derived : public Base { public: Derived(int x, char* t) : Base(x), text(new string(t)) {} ~Derived() { delete text; } string* getText() const { return text; } void append(string* t) { text->append(*t); } private: string* text; }; int main (){ Derived *d = new Derived(5, "hallo"); cout << d->getVar() << endl; cout << *d->getText() << endl; string tmp = "bye"; d->append(&tmp); cout << *d->getText() << endl; } ############ IN RUBY:######################## #!/usr/bin/ruby class Base attr_reader :var def initialize(v) @var = v end def increase @var = @var + 1 end end class Derived < Base attr_reader :text def initialize(x, t) super(x) @text = t end def append(t) @text = @text + t end end d = Derived.new(5, "hallo") d.increase print d.var.to_s + "\n" print d.text + "\n" d.append("bye") print d.text + "\n"