News for hackers. Stuff that matters.
Re:Introducing Rust Language Server by kibwen on Tuesday October 18, 2016 @11:12PM (#12740743)
I agree that it depends on where you approach it from (my very first question for tutoring any new Rust user is "what languages have you used previously?"), but I'm afraid that saying "it's really not that hard" glosses over the experience of a large number of potential users. I don't consider Rust to be a particularly complex language--I put it on par with Python--but unlike Python the learning curve for Rust is remarkably steep, which is enough for me to classify Rust as a hard language to learn.

A foreknowledge of pointers helps, but for anyone for whom Rust is their first systems language, it's going to be Rust's task to teach them e.g. the stack/heap distinction, or what "aliasing" means, or why there are two string types (let's hope they're already versed in Unicode...), or how to design a system in the absence of pure OO.

Re:Introducing Rust Language Server by iopq on Wednesday October 19, 2016 @06:05AM (#12742470)
> I don't consider Rust to be a particularly complex language > I put it on par with Python

Python doesn't have complicated lifetime errors, confusing trait not being satisfied errors. Python function declarations don't need three lines of code.

I mean wtf is this?

    fn accumulate<'a, T: Monoid>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> Option<T>
        where T: From<&'a str>
there's about ten language features in these lines of code that Python doesn't have
Re:Introducing Rust Language Server by kibwen on Wednesday October 19, 2016 @01:13PM (#12745616)
I consider "complexity" to refer to both the quantity of language features and the number of significant or surprising interactions that exist between every language feature. Rust and Python are both medium-complexity languages, but the difference is that in Python you can totally ignore e.g. generators or decorators or (oh god) metaclasses and still get work done. In Rust you really can't get work done until you understand references and move semantics. The total height of each learning curve is the same, but Rust's is more like a cliff than a gentle slope, which is why it's crucial that we put so much focus on documentation.
Re:Introducing Rust Language Server by iopq on Thursday October 20, 2016 @02:32AM (#12750130)
I ran into higher rank lifetimes while trying to use a library in my program. You can totally pass closures around in a dynamic language like JavaScript without any issues (you just pay for it in performance). In Rust `-> impl Trait` is a new feature so it's still not at all polished.

I would argue that Rust has a higher learning curve overall than any dynamic language because of its type system.

Re:Introducing Rust Language Server by fredsir on Wednesday October 19, 2016 @08:00AM (#12742992)
I only have very little Rust experience, and would like to hear from a Rust veteran - as much as one can be - if that is considered good Rust, or if it's just an example of how bad Rust can be if you don't know what you're doing, or are trying to showcase bad Rust.

I would think it's the latter, but I don't know, to be honest.

Re:Introducing Rust Language Server by fiedzia on Wednesday October 19, 2016 @02:52PM (#12746588)
Its non-trivial and it could be written simpler (the tuples part could get its own type alias, making it more readable and shorter), but its not particularly bad or good.

You will find examples of this mostly in libraries, but rarely its something a beginner would write. You can actually do a lot without ever using lifetimes. Eventually you'll need to learn to read this though, and its just a matter of getting used to it. I'd say none of those is any harder to understand then let say nested list comprehension in python.

Re:Introducing Rust Language Server by Manishearth on Wednesday October 19, 2016 @09:12AM (#12743420)
It's basically an example of what happens when you try to use Haskell concepts in Rust; the type parameters explode quickly. Most rust functions are not like that. Some are. It's not exactly bad rust to have functions like that, but such functions should probably be uncommon in your codebase.
Re:Introducing Rust Language Server by iopq on Wednesday October 19, 2016 @09:27AM (#12743548)
Note that Monoid here is ONLY for the reason that Cow<str> doesn't satisfy Add. In fact, String doesn't satisfy it either. So I need to have a trait that allows me to call a function that concatenates my types. I already wrote how to concatenate Strings and Cow<str>s in my Monoid crate so I'm just re-using that.

It could be T: Concatenable for all I care, but the rest of the function needs to look this way, more or less.

I only have one type parameter, that's very common. I'm abstracting over String and Cow<str> because I want to bench the performance of both. (Cow<str> is always faster)

Re:Introducing Rust Language Server by Manishearth on Wednesday October 19, 2016 @09:56AM (#12743757)
I'm not just talking about Monoid, I'm talking about the overall signature -- with the Fn and the abstractions it's very Haskelly. Such functions are not common in Rust. You find them (all the iterator adaptors, for one), and they can be "good Rust", but they're not common. Which is okay.

(I don't disagree that Rust is more complicated than Python, just addressing GP's comment whether or not this is "good" rust.)

Re:Introducing Rust Language Server by iopq on Thursday October 20, 2016 @12:21AM (#12749713)
It's actually very common to pass around hashmaps of functions in dynamic languages. If anything, since you don't even have to know how they're implemented it's easier. I realize that my function incurs a run time cost because I'm making an array of trait objects. When I'm writing JavaScript I don't know and I don't care.
Re:Introducing Rust Language Server by iopq on Wednesday October 19, 2016 @08:38AM (#12743187)
You could write <'a, T: Monoid + From<&'a str>> and omit the where clause, but that seems even less readable to me. The rest basically has to be there for the function to do what it does.
Re:Introducing Rust Language Server by pcwalton on Wednesday October 19, 2016 @12:17PM (#12745128)
I don't agree with kibwen about Rust being just as simple as Python, but I also think it's a bit of a pointless comparison, given that Python is dynamically typed and Rust is statically typed. Any type system feature is something that Python trivially doesn't have.
Re:Introducing Rust Language Server by pjmlp on Wednesday October 19, 2016 @05:31AM (#12742348)
Regarding pointers, I think a good way would be to teach them both visually and without many C style tricks.

C style pointer tricks are better left for level two, so to speak.

Probably a good approach teach Rust's OO way is to introduce traits as kind of extensible modules that can be composed and go from there.

It is not 100% correct, but I guess it is easier to teach than going full theory with traits being a kind of type classes and do on.