is rust an 'oopl'?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

is rust an 'oopl'?

Mayuresh Kathe
hello,

i am an absolute newbie to rust.

is rust an object-oriented programming language?

i ask because i detest 'oo', and am looking for something better than
"c".

thanks,

~mayuresh

_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev
Reply | Threaded
Open this post in threaded view
|

Re: is rust an 'oopl'?

Matthieu Monrocq
Hello Mayuresh,

The problem with your question is dual:

 - OO itself is a fairly overloaded term, and it is unclear what definition you use for it: Alan Kay's original? The presence of inheritance? ...
 - Just because a language supports OO concepts does not mean that it ONLY supports OO concepts, many languages are multi-paradigms and can be used for procedural programming, object-oriented programming (in a loose sense given the loose definition in practice), generic programming, functional programming, ...

Rust happens to be a multi-paradigms language. It supports some, but not all, object-oriented concepts, but also thrives with free functions and generic functions and supports functional programming expressiveness (but not purity concepts).

I would also note that I have C striving to achieve some OO concepts (opaque pointers for encapsulation, virtual-dispatch through manually written virtual-tables, ...), some even in C you cannot necessarily avoid the OO paradigm, depending on the libraries you use.

Is Rust a good language for you? Maybe!

The only way for you to know is to give it a spin.

Have a nice day.

-- Matthieu

On Sun, Jan 11, 2015 at 2:59 AM, Mayuresh Kathe <[hidden email]> wrote:
hello,

i am an absolute newbie to rust.

is rust an object-oriented programming language?

i ask because i detest 'oo', and am looking for something better than
"c".

thanks,

~mayuresh

_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev


_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev
Reply | Threaded
Open this post in threaded view
|

Re: is rust an 'oopl'?

Mayuresh Kathe
hello matthieu,

thanks for responding.

you mentioned that "rust" supports some object-oriented concepts.
may i know which?

also, deviating a bit off-topic, would a decent grasp of functional
programming be a pre-requisite to learning "rust"?

thanks,

~mayuresh



On 2015-01-11 17:21, Matthieu Monrocq wrote:

> Hello Mayuresh,
>
> The problem with your question is dual:
>
>  - OO itself is a fairly overloaded term, and it is unclear what
> definition you use for it: Alan Kay's original? The presence of
> inheritance? ...
>  - Just because a language supports OO concepts does not mean that it
> ONLY supports OO concepts, many languages are multi-paradigms and can
> be used for procedural programming, object-oriented programming (in a
> loose sense given the loose definition in practice), generic
> programming, functional programming, ...
>
> Rust happens to be a multi-paradigms language. It supports some, but
> not all, object-oriented concepts, but also thrives with free
> functions and generic functions and supports functional programming
> expressiveness (but not purity concepts).
>
> I would also note that I have C striving to achieve some OO concepts
> (opaque pointers for encapsulation, virtual-dispatch through manually
> written virtual-tables, ...), some even in C you cannot necessarily
> avoid the OO paradigm, depending on the libraries you use.
>
> Is Rust a good language for you? Maybe!
>
> The only way for you to know is to give it a spin.
>
> Have a nice day.
>
> -- Matthieu
>
> On Sun, Jan 11, 2015 at 2:59 AM, Mayuresh Kathe <[hidden email]>
> wrote:
>
>> hello,
>>
>> i am an absolute newbie to rust.
>>
>> is rust an object-oriented programming language?
>>
>> i ask because i detest 'oo', and am looking for something better
>> than
>> "c".
>>
>> thanks,
>>
>> ~mayuresh

_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev
Reply | Threaded
Open this post in threaded view
|

Re: is rust an 'oopl'?

Mayuresh Kathe
whew, that was an exhaustive explanation, thanks for taking the efforts
to write in the detailed response.

i realised one thing, the best way to learn "rust" would be to not have
any preconceived notions about it, as well as to take things a bit easy
and learn the language as it is, one morsel at a time.

~mayuresh


On 2015-01-11 19:17, Kevin McGuire wrote:

> Oh, hell. I forgot about Option<T>.
>
> You see also in Rust nothing can be uninitialized! Unless you use
> unsafe code. This little type is your friend. It gives you the
> equivalent of uninitialized data. So take some time and research it or
> play around with it.
>
> On Sun, Jan 11, 2015 at 7:43 AM, Kevin McGuire <[hidden email]>
> wrote:
>
>> I can not answer very well about the OO capabilities of Rust since
>> it is hard to define, but Rust does support:
>>
>> methods of a type/structure that take a special _self _argument
>>
>> traits which are like interfaces that any type/structure can
>> implement
>>
>> operator overloads like + for one
>>
>> There is no inheritance at the moment although you can get a kind of
>> hack version of it using the Deref trait on an object. The Deref is
>> mostly used by smart pointers. The smart pointer type wraps your
>> inner type and then allows access to the inner type through the
>> de-reference support of Deref.
>>
>> The only other object like feel is of the namespace system.
>>
>> In Rust everything has the capability to have a method although the
>> primitive types are kind of special.
>>
>> Also I have seen and used an operator overload for a structure once
>> so I know it has that ability now which I think may have been fairly
>> recent.
>>
>> So Rust is capable of some object oriented programming. You do not
>> have to do object oriented programming.
>>
>> Also, the per-requisites for Rust - Yes functional programming would
>> be just fine. I am going to go ahead and tell you where you may
>> struggle with learning Rust.
>>
>> The major problem you will have is coming to understand ownership
>> and lifetimes. These two things are what makes Rust memory safe and
>> are fantastic however at first they will seem like a curse. You
>> might even give up on Rust because they will make writing code
>> difficult at first.
>>
>> The second problem you are going to have is feeling a little lost as
>> to how to allocate memory during run-time and also you will feel
>> very confused as how to overcome lifetime limitations by your
>> limited knowledge of the pointer types.
>>
>> _These two problems you are going to face no matter what language
>> you have come from._
>>
>> To help you first I would like to to take note of Box<T> and Rc<T>.
>> Do not worry about understanding them. Just keep them in the back of
>> your head. The first is Box<T> and the next is Rc<T>. There is
>> another one called Arc<T> for data to be shared by threads. Okay..
>>
>> Also, a quick word on ownership. Everything is owned. What being
>> owned is that everything has a home. Some types are Copy which means
>> when you assign them somewhere else they are copied byte for byte.
>> Your native primitives like integers are copyable. The problem you
>> will encounter is when you work with non-copyable types which are
>> abundant. At first you might want to curse the fact that a type is
>> not copyable but it is a very powerful feature not a hindrance.
>>
>> If a type is not copyable and you assign it or pass it into a
>> function by value (sort of speak) you will cause a _move _to happen.
>> A move is part of the ownership system. Think of moving an argument
>> into a function as the function sort of consumes the argument. It
>> leaves it's original home and moves into the function. The function
>> now owns the argument. Also keep in mind that the function can move
>> the type back out through the return value and you could place it
>> back in it's original home.
>>
>> Okay, so now you will run into the situation where you want to have
>> an instance of a type stored in more than one place? Well, you have
>> two options. If the type supports Clone you can call the clone
>> method and produce a duplicate. The exact way clone works is very
>> specific to the type. It might create a completely separate type or
>> the two might still be linked. Do not worry at the moment as this
>> will become evident as you learn Rust.
>>
>> Just keep in mind that for non-copyable types or types in which you
>> do not want a copy you can create a smart-pointer to manage them:
>>
>> let pointer = Rc::new(myothervar);
>>
>> let secondhome = pointer.clone();
>>
>> myfunction(secondhome);
>>
>> Also to note you will find the smart-pointer clunky and you will be
>> confused as how to write libraries or make a good API for your
>> application. I would like to leave you with one more concept. You
>> will find passin Rc<MyType> around cumbersome. To remedy this you
>> can learn the pattern of making MyType wrap the Rc so the Rc is
>> internal to it. So your API will pass around MyType instead.
>>
>> Okay, sorry for such a long mail. I just hope this little tips and
>> things can help you instead of making you quit leaving a bitter
>> taste for Rust!
>>
>> On Sun, Jan 11, 2015 at 7:17 AM, Mayuresh Kathe <[hidden email]>
>> wrote:
>> hello matthieu,
>>
>> thanks for responding.
>>
>> you mentioned that "rust" supports some object-oriented concepts.
>> may i know which?
>>
>> also, deviating a bit off-topic, would a decent grasp of functional
>> programming be a pre-requisite to learning "rust"?
>>
>> thanks,
>>
>> ~mayuresh
>>
>> On 2015-01-11 17:21, Matthieu Monrocq wrote:
>> Hello Mayuresh,
>>
>> The problem with your question is dual:
>>
>>  - OO itself is a fairly overloaded term, and it is unclear what
>> definition you use for it: Alan Kay's original? The presence of
>> inheritance? ...
>>  - Just because a language supports OO concepts does not mean that
>> it
>> ONLY supports OO concepts, many languages are multi-paradigms and
>> can
>> be used for procedural programming, object-oriented programming (in
>> a
>> loose sense given the loose definition in practice), generic
>> programming, functional programming, ...
>>
>> Rust happens to be a multi-paradigms language. It supports some,
>> but
>> not all, object-oriented concepts, but also thrives with free
>> functions and generic functions and supports functional programming
>> expressiveness (but not purity concepts).
>>
>> I would also note that I have C striving to achieve some OO
>> concepts
>> (opaque pointers for encapsulation, virtual-dispatch through
>> manually
>> written virtual-tables, ...), some even in C you cannot necessarily
>> avoid the OO paradigm, depending on the libraries you use.
>>
>> Is Rust a good language for you? Maybe!
>>
>> The only way for you to know is to give it a spin.
>>
>> Have a nice day.
>>
>> -- Matthieu
>>
>> On Sun, Jan 11, 2015 at 2:59 AM, Mayuresh Kathe <[hidden email]>
>> wrote:
>>
>> hello,
>>
>> i am an absolute newbie to rust.
>>
>> is rust an object-oriented programming language?
>>
>> i ask because i detest 'oo', and am looking for something better
>> than
>> "c".
>>
>> thanks,
>>
>> ~mayuresh
>
>  _______________________________________________
>  Rust-dev mailing list
>  [hidden email]
>  https://mail.mozilla.org/listinfo/rust-dev [1]
>
>
>
> Links:
> ------
> [1] https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev
Reply | Threaded
Open this post in threaded view
|

Re: is rust an 'oopl'?

Matthieu Monrocq
Hello,

The main feature of OOP that Rust supports is polymorphism, though it is achieved via type-classes rather inheritance (*). It also features encapsulation, but it may have existed before OOP so it's hard to view it as an OOP-feature...

Regarding the need to learn functional programming first, I would actually see it the other way around: by learning Rust, you will learn a number of functional programming concepts/idioms that may pick your interest in learning more functionally oriented languages. I do not think that prior exposure is required, but then I had already prior exposure so may not be the best qualified here.

Try it out! It just takes 30min to read the Introduction: http://doc.rust-lang.org/intro.html and you'll know if you wish to dig further or if it's not for you yet.


(*) For the uninitiated, this means that the creator of a type does not hardcode the list of interfaces its type support, but rather you can create your own interface and implement it yourself for a 3rd party type. You can also of course implement a 3rd party interface for your own type, but that is already supported in Java-like OO.


On Sun, Jan 11, 2015 at 2:54 PM, Mayuresh Kathe <[hidden email]> wrote:
whew, that was an exhaustive explanation, thanks for taking the efforts to write in the detailed response.

i realised one thing, the best way to learn "rust" would be to not have any preconceived notions about it, as well as to take things a bit easy and learn the language as it is, one morsel at a time.

~mayuresh


On 2015-01-11 19:17, Kevin McGuire wrote:
Oh, hell. I forgot about Option<T>.

You see also in Rust nothing can be uninitialized! Unless you use
unsafe code. This little type is your friend. It gives you the
equivalent of uninitialized data. So take some time and research it or
play around with it.

On Sun, Jan 11, 2015 at 7:43 AM, Kevin McGuire <[hidden email]>
wrote:

I can not answer very well about the OO capabilities of Rust since
it is hard to define, but Rust does support:

methods of a type/structure that take a special _self _argument

traits which are like interfaces that any type/structure can
implement

operator overloads like + for one

There is no inheritance at the moment although you can get a kind of
hack version of it using the Deref trait on an object. The Deref is
mostly used by smart pointers. The smart pointer type wraps your
inner type and then allows access to the inner type through the
de-reference support of Deref.

The only other object like feel is of the namespace system.

In Rust everything has the capability to have a method although the
primitive types are kind of special.

Also I have seen and used an operator overload for a structure once
so I know it has that ability now which I think may have been fairly
recent.

So Rust is capable of some object oriented programming. You do not
have to do object oriented programming.

Also, the per-requisites for Rust - Yes functional programming would
be just fine. I am going to go ahead and tell you where you may
struggle with learning Rust.

The major problem you will have is coming to understand ownership
and lifetimes. These two things are what makes Rust memory safe and
are fantastic however at first they will seem like a curse. You
might even give up on Rust because they will make writing code
difficult at first.

The second problem you are going to have is feeling a little lost as
to how to allocate memory during run-time and also you will feel
very confused as how to overcome lifetime limitations by your
limited knowledge of the pointer types.

_These two problems you are going to face no matter what language
you have come from._

To help you first I would like to to take note of Box<T> and Rc<T>.
Do not worry about understanding them. Just keep them in the back of
your head. The first is Box<T> and the next is Rc<T>. There is
another one called Arc<T> for data to be shared by threads. Okay..

Also, a quick word on ownership. Everything is owned. What being
owned is that everything has a home. Some types are Copy which means
when you assign them somewhere else they are copied byte for byte.
Your native primitives like integers are copyable. The problem you
will encounter is when you work with non-copyable types which are
abundant. At first you might want to curse the fact that a type is
not copyable but it is a very powerful feature not a hindrance.

If a type is not copyable and you assign it or pass it into a
function by value (sort of speak) you will cause a _move _to happen.
A move is part of the ownership system. Think of moving an argument
into a function as the function sort of consumes the argument. It
leaves it's original home and moves into the function. The function
now owns the argument. Also keep in mind that the function can move
the type back out through the return value and you could place it
back in it's original home.

Okay, so now you will run into the situation where you want to have
an instance of a type stored in more than one place? Well, you have
two options. If the type supports Clone you can call the clone
method and produce a duplicate. The exact way clone works is very
specific to the type. It might create a completely separate type or
the two might still be linked. Do not worry at the moment as this
will become evident as you learn Rust.

Just keep in mind that for non-copyable types or types in which you
do not want a copy you can create a smart-pointer to manage them:

let pointer = Rc::new(myothervar);

let secondhome = pointer.clone();

myfunction(secondhome);

Also to note you will find the smart-pointer clunky and you will be
confused as how to write libraries or make a good API for your
application. I would like to leave you with one more concept. You
will find passin Rc<MyType> around cumbersome. To remedy this you
can learn the pattern of making MyType wrap the Rc so the Rc is
internal to it. So your API will pass around MyType instead.

Okay, sorry for such a long mail. I just hope this little tips and
things can help you instead of making you quit leaving a bitter
taste for Rust!

On Sun, Jan 11, 2015 at 7:17 AM, Mayuresh Kathe <[hidden email]>

wrote:
hello matthieu,

thanks for responding.

you mentioned that "rust" supports some object-oriented concepts.
may i know which?

also, deviating a bit off-topic, would a decent grasp of functional
programming be a pre-requisite to learning "rust"?

thanks,

~mayuresh

On 2015-01-11 17:21, Matthieu Monrocq wrote:
Hello Mayuresh,

The problem with your question is dual:

 - OO itself is a fairly overloaded term, and it is unclear what
definition you use for it: Alan Kay's original? The presence of
inheritance? ...
 - Just because a language supports OO concepts does not mean that
it
ONLY supports OO concepts, many languages are multi-paradigms and
can
be used for procedural programming, object-oriented programming (in
a
loose sense given the loose definition in practice), generic
programming, functional programming, ...

Rust happens to be a multi-paradigms language. It supports some,
but
not all, object-oriented concepts, but also thrives with free
functions and generic functions and supports functional programming
expressiveness (but not purity concepts).

I would also note that I have C striving to achieve some OO
concepts
(opaque pointers for encapsulation, virtual-dispatch through
manually
written virtual-tables, ...), some even in C you cannot necessarily
avoid the OO paradigm, depending on the libraries you use.

Is Rust a good language for you? Maybe!

The only way for you to know is to give it a spin.

Have a nice day.

-- Matthieu

On Sun, Jan 11, 2015 at 2:59 AM, Mayuresh Kathe <[hidden email]>
wrote:

hello,

i am an absolute newbie to rust.

is rust an object-oriented programming language?

i ask because i detest 'oo', and am looking for something better
than
"c".

thanks,

~mayuresh

 _______________________________________________
 Rust-dev mailing list
 [hidden email]
 https://mail.mozilla.org/listinfo/rust-dev [1]



Links:
------
[1] https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev


_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev