[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Robert

4/6/2005 7:07:00 AM

dear all, i'm very new to the Ruby lang: could you suggest me a good web
site to learn something more? like history, potentiality, .... but above
all ... where can i find a good tutorial about Ruby?

thanks to all
13 Answers

Robert Klemme

4/6/2005 7:16:00 AM

0


"Robert" <robert@none.com> schrieb im Newsbeitrag
news:uUL4e.741656$b5.33421881@news3.tin.it...
> dear all, i'm very new to the Ruby lang:

Welcome!

> could you suggest me a good web
> site to learn something more? like history, potentiality, .... but above
> all ... where can i find a good tutorial about Ruby?

Links to introductions
http://www.rubygarden.org/rub...

The Guide
http://poignantguide...

Reference
http://www.rub...

Basics, Download etc.
http://www.ruby-la...

Kind regards

Robert

Robert

4/6/2005 2:27:00 PM

0

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!


Robert wrote:
> dear all, i'm very new to the Ruby lang: could you suggest me a good web
> site to learn something more? like history, potentiality, .... but above
> all ... where can i find a good tutorial about Ruby?
>
> thanks to all

Peter Hickman

4/6/2005 2:49:00 PM

0

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!

The first question is how well you know C++?

How long have you been a C++ programmer? With that we can pitch our
answer correctly. However if it turns out that you know nothing about
C++ then you might find yourself being labelled as a troll and you
wouldn't want that. Was there anything in the six links you were given
that was unclear and you would like clarified.

You should not prefer ruby out of other programming languages, but you
should use the best tool for the job. Programs I have developed in ruby
have ended up as C. Ruby was ideal to get the program worked out but C
gave me the speed I required.



Phlip

4/6/2005 3:00:00 PM

0

Robert wrote:

> But what's the difference brtween C++ and Ruby?

C++ is designed to compile to the most efficient machine code possible. All
other considerations, such as programmer comfort, are secondary.

Ruby is interpreted, which means it can change anything about its situation
at runtime. That makes programming super-easy, and execution a little slow.

For example, there is no C++ eval("") function. You cannot load a string
full of C++, evaluate it, and have it change C++'s context.

The top level of a program should be only command-and-control code, which
uses short loops and few hard algorithms. Write this in Ruby, and write the
lower layer in C++, for speed:

http://www.rubygarden.org/ruby?FractalLifeEngine/...

The first images shows Ruby in the left panel, and C++, C, Qt, and OpenGL in
the right. You edit the Ruby code, and the program passes it into eval() to
change the shape on the right.

> I mean, why i should prefer ruby out of other programming languages?

You should prefer to learn many languages, and then pick the right one for
each job. You are not getting married to Ruby.

--
Phlip
http://industrialxp.org/community/bin/view/Main/TestFirstUser...


Steven Jenkins

4/6/2005 3:33:00 PM

0

Phlip wrote:
> C++ is designed to compile to the most efficient machine code possible. All
> other considerations, such as programmer comfort, are secondary.

I hesitate to feed language comparison threads, but this is wrong. The
only person who can state with authority the design criteria for C++ is
Bjarne Stroustrup, and he said "My initial aim for C++ was a language
where I could write programs that were as elegant as Simula programs,
yet as efficient as C programs." You can't conclude from this statement
that elegance is secondary to efficiency.

Steve


Phlip

4/6/2005 4:03:00 PM

0

Steven Jenkins wrote:

> I hesitate to feed language comparison threads, but this is wrong. The
> only person who can state with authority the design criteria for C++ is
> Bjarne Stroustrup, and he said "My initial aim for C++ was a language
> where I could write programs that were as elegant as Simula programs,
> yet as efficient as C programs." You can't conclude from this statement
> that elegance is secondary to efficiency.

No advocacy is needed to discuss this - it's an axiom of C++'s design. If
you don't have a virtual destructor, and you delete thru a base class
pointer, you get undefined behavior. C++ programmers learn their art by
learning a humongous list of trivial ways to create undefined behavior. The
language won't do anything you don't explicitly tell it to; this gives
compilers freedom to optimize aggressively.

To Bjarne's credit, the language he built works relatively elegantly within
the framework of that era's compilers (and linkers). That's why C++ won the
"C wars".

--
Phlip
http://industrialxp.org/community/bin/view/Main/TestFirstUser...




Boris Glawe

4/6/2005 8:20:00 PM

0

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 <iostream>

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"

Bill Kelly

4/6/2005 9:14:00 PM

0

From: "Phlip" <phlip_cpp@yahoo.com>
>
> Steven Jenkins wrote:
>
> > I hesitate to feed language comparison threads, but this is wrong. The
> > only person who can state with authority the design criteria for C++ is
> > Bjarne Stroustrup, and he said "My initial aim for C++ was a language
> > where I could write programs that were as elegant as Simula programs,
> > yet as efficient as C programs." You can't conclude from this statement
> > that elegance is secondary to efficiency.
>
> No advocacy is needed to discuss this - it's an axiom of C++'s design. If
> you don't have a virtual destructor, and you delete thru a base class
> pointer, you get undefined behavior. C++ programmers learn their art by
> learning a humongous list of trivial ways to create undefined behavior. The
> language won't do anything you don't explicitly tell it to; this gives
> compilers freedom to optimize aggressively.

Agreed. Reading Stroustrup, "You don't pay for what you
don't use" was cited repeatedly as an unbreakable constraint
governing the design of C++. That's why new [] has to be
matched with delete [], - despite this being inconvenient and
an easy pitfall for programmers. "You don't pay for what you
don't use" trumps programmer convenience every time in C++.

I think it's also one of the reasons C++ succeeded - because
you *can* write C++ that's identically efficient to C when
you need to.

In the mid 90's I worked at a game shop that was wary of
starting a new project in C++ because of rumors that C++ was
inherently inneficient. What helped me get C++ approved for
that project was to compile our previous game's C code base
with the C++ compiler, and show that, apart from
inconsequential things like some values stored in different
register names, the disassembly between the C and C++
compiled versions was identical.

"You don't pay for what you don't use" is an important aspect
of C++ -- but it's also what contributes to it being a pain
in the butt. :)


Regards,

Bill




Jacob Fugal

4/6/2005 9:17:00 PM

0

On Apr 6, 2005 2:24 PM, Boris Glawe <boris@boris-glawe.de> wrote:
> 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.

While I won't dispute the relative slowness of scripting languages
compared to compiled languages, I must assume you made a typo. 16
minutes?! I copy the script you paste below into a file and run it and
it takes fractions of a second. Possibly benchmarking it for 10^X
iterations will take longer than C, but not by 2 orders of magnitude
(5 seconds to 960 seconds). Probably 5 seconds versus 16 *seconds*
when benchmarked?

I'm too lazy to actually perform the benchmark myself, but felt it
necessary to call this to attention...

Jacob Fugal

(ruby version included below for reference)

> #!/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"


Jacob Fugal

4/6/2005 9:40:00 PM

0

On Apr 6, 2005 3:16 PM, Jacob Fugal <lukfugl@gmail.com> wrote:
> On Apr 6, 2005 2:24 PM, Boris Glawe <boris@boris-glawe.de> wrote:
> > 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.
>
> While I won't dispute the relative slowness of scripting languages
> compared to compiled languages, I must assume you made a typo. 16
> minutes?! I copy the script you paste below into a file and run it and
> it takes fractions of a second. Possibly benchmarking it for 10^X
> iterations will take longer than C, but not by 2 orders of magnitude
> (5 seconds to 960 seconds). Probably 5 seconds versus 16 *seconds*
> when benchmarked?
>
> I'm too lazy to actually perform the benchmark myself, but felt it
> necessary to call this to attention...

Ok, so maybe I'm not that lazy. Just too lazy to write true to life
benchmarks. Here are my "benchmarks". I fixed the C++ version to
include a call to increase (was missing from the version Boris posted,
probably another typo) stuck both of the main bodies in loops to be
run 1000000 times. This is the output from timing them (./test is
test.cc compiled with g++ at default optimization):

$ time ./test.rb
<snip lots of output>

real 2m19.652s
user 0m38.469s
sys 0m16.091s

$ time ./test
<snip lots of output>

real 1m54.417s
user 0m21.358s
sys 0m12.703s

You can see the user time differs by about a factor of 2. The large
real time (which applies to both) is due to the bottleneck of actually
printing to the terminal. I remove that consideration by retiming with
output redirected to /dev/null:

$ time ./test.rb > /dev/null

real 0m25.565s
user 0m21.829s
sys 0m1.393s

$ time ./test > /dev/null

real 0m14.807s
user 0m10.806s
sys 0m1.065s

Again, the difference is about a factor of 2 -- not 192.

Jacob Fugal

Code used in the benchmark:

######### test.rb ##########

#!/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

1000000.times do
d = Derived.new(5, "hallo")
d.increase

print d.var.to_s + "\n"
print d.text + "\n"

d.append("bye")

print d.text + "\n"
end

######### test.cc ##########

#include <iostream>

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 (){

for (int i = 0; i < 1000000; i++) {
Derived *d = new Derived(5, "hallo");
d->increase();

cout << d->getVar() << endl;

cout << *d->getText() << endl;

string tmp = "bye";
d->append(&tmp);

cout << *d->getText() << endl;
}
}