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
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
"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
The Guide
http://poignantguide.net/ruby/
Reference
Basics, Download etc.
http://www.ruby-lang.org/en/
Kind regards
Robert
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
Robert wrote:
could you suggest me a good web site to learn something more?
:
where can i find a good tutorial about Ruby?
I am unsure if you want the tutorial to be available on the web (and for
free) or not. An excellent printed tutorial is "Programming Ruby - The
Pragmatic Programmers' Guide, 2nd edition" by Dave Thomas and others. It
is also available in PDF form but that version is non-free as well.
The only major drawback of the book is its binding - glued single pages
are a bad choice for books that are not read-once. If I would have had
the choice I would rather have payed some extra EUR for a binding with
longer lifetime. My copy started disassembling within just two weeks of
heavy flip-back-and-forth use :-<
Josef 'Jupp' Schugt
- --
Your software shall grant you the freedom to run for any purpose; to
study and adapt to your needs; to redstribute, so you can help others;
to release improvements, so everyone benefits.
For details see Free Software Foundation Europe http://www.fsfe.org/
Hello,
I wrote a tutorial for someone who has never programmed before. (Even
so, a lot of programmers of other languages have found it useful.)
http://pine.fm/LearnToProgram/
It starts very gently, and has lots and lots of examples. Also, the
examples are all guaranteed correct: the code samples are run every
time you request the webpage! (So you can reload the random number
examples and see different outputs, for example.) In fact, the whole
tutorial is actually being generated by a Ruby program. It seemed
appropriate.
I hope you enjoy it,
Chris
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.
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:
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.
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"
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
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)
On Apr 6, 2005 2:24 PM, Boris Glawe <boris@boris-glawe.de> wrote:
#!/usr/bin/ruby
class Base
attr_reader :vardef initialize(v)
@var = v
enddef increase
@var = @var + 1
end
endclass Derived < Base
attr_reader :text
def initialize(x, t)
super(x)
@text = t
enddef append(t)
@text = @text + t
endend
d = Derived.new(5, "hallo")
d.increaseprint d.var.to_s + "\n"
print d.text + "\n"d.append("bye")
print d.text + "\n"
"Boris Glawe" <boris@boris-glawe.de> schrieb im Newsbeitrag
news:d31gaa$sio$1@newsreader3.netcologne.de...
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.
Your Derived#append is suboptimal because it creates new string instances
all the time. Try
def append(t) @text << t; self end
And I'd rewrite Base#increase like this
def increase() @var += 1 end
It's shorter and it seems to be a tad faster:
Benchmark.bm(10) do |b|
@var = 0
b.report("+=") { 1000000.times { @var += 1 } }
@var = 0
b.report("= +") { 1000000.times { @var = @var + 1 } }
end
user system total real
+= 1.125000 0.000000 1.125000 ( 1.132000)
= + 1.141000 0.000000 1.141000 ( 1.146000)
Kind regards
robert
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 :vardef initialize(v)
@var = v
enddef increase
@var = @var + 1
end
endclass Derived < Base
attr_reader :text
def initialize(x, t)
super(x)
@text = t
enddef append(t)
@text = @text + t
endend
d = Derived.new(5, "hallo")
d.increaseprint d.var.to_s + "\n"
print d.text + "\n"d.append("bye")
print d.text + "\n"
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".
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;
}
}
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...
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
From: "Phlip" <phlip_cpp@yahoo.com>