Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   What are the differences between c++ and Ruby? (http://www.velocityreviews.com/forums/t846255-what-are-the-differences-between-c-and-ruby.html)

duddilla's 12-03-2007 01:38 AM

What are the differences between c++ and Ruby?
 
Hi
I would like implement multiple inheritance in java by using ruby
mixin mechanism.Is that possible? And my other question is what are
exact differences between C++ and Ruby? and Ruby and Java?

Thanks

Todd Benson 12-03-2007 12:15 PM

Re: What are the differences between c++ and Ruby?
 
On Dec 2, 2007 7:40 PM, duddilla's <radhika.duddilla@gmail.com> wrote:
> Hi
> I would like implement multiple inheritance in java by using ruby
> mixin mechanism.Is that possible? And my other question is what are
> exact differences between C++ and Ruby? and Ruby and Java?
>
> Thanks


You do understand, of course, that to answer these questions, one
might have to write an entire book. By asking these, you come
dangerously close to a RTFM response.

Java cannot behave exactly like Ruby when it comes to module/mixin
behavior if that's what you're asking.

Todd


Todd Benson 12-03-2007 12:38 PM

Re: What are the differences between c++ and Ruby?
 
On Dec 3, 2007 6:15 AM, Todd Benson <caduceass@gmail.com> wrote:
> Java cannot behave exactly like Ruby when it comes to module/mixin
> behavior if that's what you're asking.


I should qualify ... I'm not sure this last statement of mine is
entirely true. It has been a while since I've used Java for
productive use. I'd like to dive into JRuby, but just haven't had the
time recently. Ah, well...

Todd


Sebastian Hungerecker 12-03-2007 02:29 PM

Re: What are the differences between c++ and Ruby?
 
duddilla's wrote:
> And my other question is what are
> exact differences between C++ and Ruby? and Ruby and Java?


There are a lot of differences. Here are some that come to mind right away:

In ruby everthing is an object:
5.class #=> Integer
Integer.class #=> Class

Ruby has convenient introspection methods:
some_object.class # What's some_object's class?
some_object.respond_to?("meth") # Does some_object have the method "meth"
some_object.methods # Which methods does this object have
SomeClass.instance_methods # Which methods do instances of the class have
...

In ruby you can reopen classes:
5.double #=> Error: No such method
class Integer
def double()
self * 2
end
end
5.double #=> 10

Ruby has dynamic typing:
x = 5
x.class #=> Integer
x = "lala"
x.class #=> String

Ruby has blocks and a lot of methods that make good use of them:
[1,2,3,4].map {|x| x+3} #=> [4,5,6,7]
[5,7,11,8].any? {|x| x>10} #=> true
[5,7,11,8].all? {|x| x>10} #=> false
5.times { puts "Hello world" } # Prints "Hello World" five times.

In ruby you can easily define methods dynamically:
class String
(2..10).each do |i|
define_method("print_#{i}_times") do
i.times {puts self}
end
end
end
"hi".print_4_times # Prints "hi" 4 times

And a lot of other things.


HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826


Ilan Berci 12-03-2007 02:36 PM

Re: What are the differences between c++ and Ruby?
 
duddilla's wrote:
> Hi
> I would like implement multiple inheritance in java by using ruby
> mixin mechanism.Is that possible? And my other question is what are
> exact differences between C++ and Ruby? and Ruby and Java?
>
> Thanks


Java does not support MI nor will it ever support MI. In fact one of
the reasons it initially gained popularity IMO was that it didn't
support MI. Java decided to stay away from the major compiler
complexity head ache and developers never looked back.

MI in C++ eventually leads to diamond ambiguities which eventually leads
to scope resolution operators spread throughout your entire code base
and/or private inheritance. For more on this subject, please consult
Lippmann, Meyers, Fowler

Oh... one more thing.. mixins are not MI. Ruby doesn't support MI and I
believe it doesn't intend to. Anyone who has dealt with diamond
ambiguities is very glad of this fact. Each class in Ruby has one and
only one super.

ilan


--
Posted via http://www.ruby-forum.com/.


Robert Klemme 12-03-2007 03:43 PM

Re: What are the differences between c++ and Ruby?
 
2007/12/3, Ilan Berci <coder68@yahoo.com>:
> MI in C++ eventually leads to diamond ambiguities which eventually leads
> to scope resolution operators spread throughout your entire code base
> and/or private inheritance. For more on this subject, please consult
> Lippmann, Meyers, Fowler
>
> Oh... one more thing.. mixins are not MI. Ruby doesn't support MI and I
> believe it doesn't intend to. Anyone who has dealt with diamond
> ambiguities is very glad of this fact. Each class in Ruby has one and
> only one super.


Mostly agree. But: you can include any number of modules and thus
achieve /MI of behavior/ in Ruby. The diamond issue does not come up
for two reasons: first, there is just one scope for instance
variables, not multiple like in C++. Second, Ruby imposes an order on
all super classes and mixins, that's why there is only one "super".
So while Ruby works differently than C++ and Eiffel you can justify
the claim that it supports MI.

Kind regards

robert

--
use.inject do |as, often| as.you_can - without end


Ilan Berci 12-03-2007 05:00 PM

Re: What are the differences between c++ and Ruby?
 
Robert Klemme wrote:

>
> Mostly agree. But: you can include any number of modules and thus
> achieve /MI of behavior/ in Ruby. The diamond issue does not come up
> for two reasons: first, there is just one scope for instance
> variables, not multiple like in C++. Second, Ruby imposes an order on
> all super classes and mixins, that's why there is only one "super".
> So while Ruby works differently than C++ and Eiffel you can justify
> the claim that it supports MI.
>
> Kind regards
>
> robert


I stand corrected, thanks for the clarification Robert

ilan
--
Posted via http://www.ruby-forum.com/.


John Carter 12-04-2007 04:37 AM

Re: What are the differences between c++ and Ruby?
 
On Mon, 3 Dec 2007, Todd Benson wrote:

> On Dec 2, 2007 7:40 PM, duddilla's <radhika.duddilla@gmail.com> wrote:
>> Hi
>> I would like implement multiple inheritance in java by using ruby
>> mixin mechanism.Is that possible? And my other question is what are
>> exact differences between C++ and Ruby? and Ruby and Java?
>>
>> Thanks

>
> You do understand, of course, that to answer these questions, one
> might have to write an entire book. By asking these, you come
> dangerously close to a RTFM response.


Don't be so unhelpful... it's obvious that Ruby is like a writing desk
and C++ is like a Raven.

(Before you go ballistic... Read Alice in Wonderland and realize I'm
pulling legs left right and center! :-))

C++ statically type, compiled. Ruby dynamically (duck typed) interpreted.

C++ designed as an incremental improvement on C to improve code reuse
whilst adding the minimum number of new keywords. (If you think about
it, that's a really really lousy objective function.)

Ruby designed as a best of all worlds (perl/smalltalk/....) new language.

Java statically typed compile to interpreted byte code.

C++ and Java are not "objects all the way down" Ruby is.

C++ has multiple inheritance, Java has single inheritance but "extends" stateless interfaces.

You can duplicate Javarish behaviour in C++ by inheritaing from
stateless abstract class where all methods are "pure virtual".

You can emulate Rubyish mixin behaviour in C++ by multiple inheritance
from stateless classes.

There is no easy root to emulate mixins in java.


kevin cline 12-04-2007 07:34 AM

Re: What are the differences between c++ and Ruby?
 
On Dec 2, 7:38 pm, "duddilla's" <radhika.duddi...@gmail.com> wrote:
> Hi
> I would like implement multiple inheritance in java by using ruby
> mixin mechanism.Is that possible? And my other question is what are
> exact differences between C++ and Ruby? and Ruby and Java?


All three languages are Turing-complete, and consequently there are no
important differences between C+, Ruby, and Java.


Vitor Peres 12-05-2007 07:37 PM

Re: What are the differences between c++ and Ruby?
 
QWxsIHBlb3BsZSBoYXZlIHRoZSBzYW1lIGJhc2ljIHBoeXNpY2 FsIHRyYWl0cywgdGhlcmVmb3Jl
IHRoZXJlIGFyZSBubwppbXBvcnRhbnQgZGlmZmVyZW5jZXMgYm V0d2VlbiBTYXJhaCBKZXNzaWNh
IFBhcmttYW4gYW5kIEdpc2VsZSBCw7xuZGNoZW4uCgpPbiBEZW MgNCwgMjAwNyA1OjM1IEFNLCBr
ZXZpbiBjbGluZSA8a2V2aW4uY2xpbmVAZ21haWwuY29tPiB3cm 90ZToKCj4gT24gRGVjIDIsIDc6
MzggcG0sICJkdWRkaWxsYSdzIiA8cmFkaGlrYS5kdWRkaS4uLk BnbWFpbC5jb20+IHdyb3RlOgo+
ID4gSGkKPiA+IEkgd291bGQgbGlrZSBpbXBsZW1lbnQgbXVsdG lwbGUgaW5oZXJpdGFuY2UgaW4g
amF2YSBieSB1c2luZyBydWJ5Cj4gPiBtaXhpbiBtZWNoYW5pc2 0uSXMgdGhhdCBwb3NzaWJsZT8g
QW5kIG15IG90aGVyIHF1ZXN0aW9uIGlzIHdoYXQgYXJlCj4gPi BleGFjdCBkaWZmZXJlbmNlcyBi
ZXR3ZWVuIEMrKyBhbmQgUnVieT8gYW5kIFJ1YnkgYW5kIEphdm E/Cj4KPiBBbGwgdGhyZWUgbGFu
Z3VhZ2VzIGFyZSBUdXJpbmctY29tcGxldGUsIGFuZCBjb25zZX F1ZW50bHkgdGhlcmUgYXJlIG5v
Cj4gaW1wb3J0YW50IGRpZmZlcmVuY2VzIGJldHdlZW4gQyssIF J1YnksIGFuZCBKYXZhLgo+Cj4K
Pgo=


All times are GMT. The time now is 01:23 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.