Live data from Hacker News

Things Rust shipped without

graydon2.dreamwidth.org

161–170 of 330 posts

Re: Things Rust shipped without

#161
post #147
post #12

What about things that Rust shipped without that should have been included?

Non-lexical lifetimes/borrows. This is a dealbreaker IMO.

Dealbreaker? This just means you need to play with let bindings a little bit until they improve it at some point. (Same goes for SEME regions.)

Re: Things Rust shipped without

#162

Earlier quoted context omitted.

I know it is just an example to illustrate the point but this seems to have a bug in it: resource2 won't be initialized if the function fail to allocate resource1 so resource2 will be null when the code enters the deallocation condition. A way to fix it would be to return different failures for every allocation and to use a switch without a break to clean up, something like: switch (ret) { case EXIT_SUCCESS: free(res…

Passing a null pointer to free() is perfectly safe, and in this case simplifies the cleanup code. Although the concern of a memory leak is valid. I would have expected the resources to be free'd regardless of the result.

Of course, you are right. I seem to have carried the belief that freeing a null pointer was as bad as freeing one twice. And now I know.

Seems to be a common misconception [1], thanks for pointing out, that makes the GGP code correct in all counts and my switch redundant.

[1] https://news.ycombinator.com/item?id=8844031

Re: Things Rust shipped without

#163
post #139
post #101

Rust also shipped without reflection, which was available in the beginning. I was a bit disappointed as it was something I would have made use of for serialization.

How do you imagine that reflection would be useful for serialization in Rust?

In the way I asked here, http://stackoverflow.com/questions/29109967/why-dont-many-co...

I am not very familiar with rust, is what I was describing currently possible?

Re: Things Rust shipped without

#164

Earlier quoted context omitted.

> The ability to provide a default implementation of a function in a trait that can be inherited and used by "classes" that extend that trait. Rust provides this. E.g., the "talk" method in the "Animal" trait below: [0] trait Animal { // Static method signature; `Self` refers to the implementor type fn new(name: &'static str) -> Self; // Instance methods, only signatures fn name(&self) -> &'static str; fn noise(&self…

Man. The documentation did not make that clear at all. Was this added in 1.0? A question (In C++ syntax, as I'm not a Rust programmer): How would one call Animal::talk inside Dog::talk? The obvious thing (commenting out the println and adding Animal::talk(self) ) causes infinite recursion. The other vaguely obvious thing ( Animal.talk(self); ) is a syntax error, which makes sense. Edit: I'm referring to the code at t…

`Animal::talk(self)` is shorthand for `::talk(self)` - i.e. it calls the overridden method. If you want to reuse the supertrait method, you have to implement it as a generic method outside of the trait, and call it from the default implementation:

    pub fn super_talk(this: &T) {
        println!("{} says {}", this.name(), this.noise());
    }
    trait Animal {
        //...
        fn talk(&self) {
          super_talk(self)
        }
    }

Re: Things Rust shipped without

#165
post #55

Earlier quoted context omitted.

Implicit returns encourage functional style; foo.map(|x| x + 1) is so much nicer than foo.map(|x| { return x + 1; }). Once you have implicit returns in closures, you might as well have them everywhere for consistency.

I think that the "expression-style" return looks good for short and "expression-like" function. Good fn inc(a: u32) -> u32 { a + 1 } fn foo(a: u32, b: u32) -> u32 { let x = a + b; a * x } Bad fn bar(...) -> bool { let mut success = false; let conn = getConnection(); ... if x > y { return false; } else if z It looks especially bad when the function has multiple early returns, and then the final return looks different.

This could easily be added as a lint to the codebase.

Re: Things Rust shipped without

#166
post #155

Earlier quoted context omitted.

The feature was added way before 1.0, if you're talking about the documentation, then I have no idea. There is no way to call the overwritten `Animal::talk`.

I thought you could do this: Animal::talk(self);

There is no such thing as `Animal::talk`. It does not exist. `Animal::talk` is purely shorthand for `::talk`, meaning that it is a specific type’s implementation of the `talk` method. In the case of `Animal::talk(dog)` where `dog` is of type `&Dog`, the `_` can be inferred to be `Dog`, and so `Animal::talk(dog)` is equivalent to `Dog::talk(dog)` and `::talk(dog)`.

The default implementation, if overridden, does not exist for the given type.

Re: Things Rust shipped without

#167
post #143
post #6

> goto (not even as a reserved word) I haven't done this for a while, but once upon a graduate program I wrote a compiler from a made-up-language (MUP) to C. MUP had some strange control structures, and if C did not have "goto", it would have been a lot more difficult to implement those structures. Since then, I have always thought languages should have a "goto" statement that human-written code is not allowed to use…

I've always defended goto and gotten a lot of flak for it. As soon as I say, "I wish I had X-language had gotos", I see jaws drop. Response: "Wow, haven't you heard the news?! GOTOs are considered harmful!" I think goto should be in almost every language. It's one of the most primitive instructions, why shouldn't it be available when needed? Yes, it can be misused, just like any other feature in the language , but it…

> It's one of the most primitive instructions, why shouldn't it be available when needed?

I see what you're saying, though I don't find this a compelling argument. By this logic, why not allow direct register access in all languages?

Just because something is a primitive operation doesn't mean you want to include it, especially not if it's more difficult to enforce guarantees your language would like to make about valid programs.

Re: Things Rust shipped without

#169

I would add Ropes: https://github.com/rust-lang/rfcs/issues/653 Given the frequency of manipulating large bodies of text in contemporary programming I do not agree it is best left to a library implementation. Without ropes as core std average rust developers will do what they did in java, c++, objC and simply use and abuse std::strings in all cases including those where it will perform poorly. https://en.wikipedia.or…

I think some progress will be seen in libraries first, namely things like tendril.

https://github.com/servo/tendril

Re: Things Rust shipped without

#170
post #101

Rust also shipped without reflection, which was available in the beginning. I was a bit disappointed as it was something I would have made use of for serialization.

Wouldn't it be better to create serialization functionality at compile-time? In the Java space some libraries are moving to compile-time code generation instead of relying on reflection. It is a huge win, since a lot more can be checked beforehand. Dagger 2 is a good example how it can be beneficial. It provides dependency injection at compile-time, which will in turn check whether all dependencies are satisfied. I h…

I was referencing at compile time, yes. How does Dagger generate the code? Does it run an executable first?

Yes, in C++ there is a similar library called ROOT which generates c++ files called "dictionaries" storing class information by running an executable over the files. I don't see (or understand) the downsides in providing the functionality for performing those steps at compile time though. The developers of ROOT are currently pushing for it to be included in C++17 (or beyond).

Post reply on HN