Well, since comments are disabled in the blog, I will analyze the points
made in the article.

** Ownership **

int *dangling(void)
{
    int i = 1234;
    return &i;
}

First, the way it is written. Please!
This is not C++ ! (Well, it is C, therefore it is also C++, OK)
I think it is written so in this way, maliciously, on purpose.
If someone who doesn't know C++ see this, I think she runs in terror.
Why not write it as any C++ programmer would do it?

int& dangling()
{
    int i = 1234;
    return i;
}

We still have the problem of dangling references.

Any decent compiler can deal with this problem, and according to the
Standard the implementations are encouraged to issue a warning in such a
case.
I don't know implementations that don't do it.

GCC:
    In function 'int& dangling()':
    warning: reference to local variable 'i' returned [-Wreturn-local-addr]
        int i = 1234;
            ^
Clang
    warning: reference to stack memory associated with local variable 'i'
returned [-Wreturn-stack-address]
        return i;
               ^

The same happens with MSVC.

Do you think that the Warning is not much?
Well, you can use a compiler option

    -Werror
Or in this case....
    -Werror-return-stack-address

...and... voilà, the problem is over, we now have errors instead of
warnings.
What is the advantage of Rust now? I think it's insignificant.


** Unique Pointers **

// C++
int *i = new int;
*i = 1234;

Again, unnecessarily verbose C++ code.

Compare it with:

int* i = new int{1234};

Compare it with:

auto i = make_unique<int>(1234);

And of course ...

int i = 1234;



So, now, what is the difference between...

// rust
let i = ~1234;

and

// C++
auto i = make_unique<int>(1234);

?

The Rust code is shorter, but perhaps, more illegible. I think it is matter
of taste.

But now, the real advantage is not as great as before, or not?
I think there is a bad intension of the author of the article to enlarge
the advantage.


Question, How to write the following in Rust using the operator ~ ?

auto e = make_unique<Employee>("Peter");

...and, what about shared-ownership?


If the author informs all this, I would think that there is no bad
intention, but he doesn't, and he uses the ugliest C++ code possible.
So it makes me think that the article is malicious and it is pure marketing
stuff.


Regards,
Fernando.


On Mon, Mar 3, 2014 at 1:34 AM, Fernando Pelliccioni <[email protected]
> wrote:

> This is a misleading propaganda against C++. I think it's pure marketing.
> I hope this code ugly C++ was not on purpose.
>
> I think it would be fair that you enable comments on the website so I can
> show how to code in real C++. Do you dare to discuss seriously?
>
> If the feedback is in a different place (mailing list), the reader of the
> article does not have a chance to really compare the two languages.
>
> Regards,
> Fernando Pelliccioni,
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to