News for hackers. Stuff that matters.
Re:Rust web framework, Iron by pjmlp on Monday August 17, 2015 @01:43AM (#10071522)
I can write web services in Haskell, OCaml, .NET, Java, Ada, Delphi, D, Go.

All compile to native code and I don't have to fight with the borrow checker.

Rust needs a good story to be sold as alternative for web development.

We don't need system programming features in a web application. Unless maybe when offering a web interface to an embedded device, instead of coding it in C.

EDIT: Before the downvotes continue, I am not attacking Rust and feel it is good that it also gets web frameworks.

The point being that for web development there are already better alternatives and unless one needs Rust special language features, there isn't a compelling reason to use it instead of the more mature alternatives which also make use of native code.

Re:Rust web framework, Iron by pcwalton on Monday August 17, 2015 @04:01AM (#10071765)
The borrow checker also eliminates data races (and a variety of other bugs), something that most of the other languages on your list do not. While avoiding GC is probably the most prominent reason for the borrow check's existence, it is not the only one. You shouldn't have to fight with it.

(Haskell in particular has a much more restrictive borrow checker than that of Rust: purity.)

Re:Rust web framework, Iron by tinco on Monday August 17, 2015 @06:03AM (#10072122)
As a Haskell programmer I feel this isn't exactly true. Haskell's garbage collector and referential transparency make immutability not really an issue. Impure code is simply of a different type, so it's easy to avoid. What makes dealing with the borrow check hard is that it triggers on code that intuitively is correct, it can be hard to envision why it's not. I feel Haskell does a better job at diverting you from incorrect code.

That said, dealing the borrow checker is just a skill. You take out a few hours to learn to deal with it, and then you just can. As you said it's super powerful and definitely your ally, so saying its a downside of Rust is silliness.

Re:Rust web framework, Iron by pcwalton on Monday August 17, 2015 @01:36PM (#10074709)
> What makes dealing with the borrow check hard is that it triggers on code that intuitively is correct, it can be hard to envision why it's not.

Because it's more expressive than just forbidding mutability. You could program in Rust the same way you program in Haskell, by encapsulating mutability in functions with different types (&mut). Then the flow sensitivity and other issues would never bother you.

Rust's flow-based control of mutability is strictly more expressive than the monad system of Haskell. If you don't like that expressivity, don't use it.

Re:Rust web framework, Iron by Jweb_Guru on Monday August 17, 2015 @12:57PM (#10074392)
I disagree. I find immutably with GC much easier than mutability with the borrow checker for most tasks. The tradeoff is that you have to trust the compiler a lot to perform well, and that trust is not always warranted.
Re:Rust web framework, Iron by pcwalton on Monday August 17, 2015 @01:32PM (#10074675)
You can use immutability in Rust and the borrow checker will never bother you. The borrow checker allows you to take all the immutable references you want. What I think you are talking about is the lifetime system, which is not something that pjmlp mentioned.
Re:Rust web framework, Iron by pjmlp on Monday August 17, 2015 @05:05AM (#10071943)
I think you overestimate how willing most developers are to fight with the borrow checker instead of using actor libraries or task libraries (TPL, TBB, PPL, Fork-Join, Akka) instead.

So far the Rust tricks with unsafe for certain data structures (e.g. double linked lists/DAGs) seem like fighting with the borrow checker. Or the issues to be solved with upcoming 1.3 changes for pattern matching.

Re:Rust web framework, Iron by pcwalton on Monday August 17, 2015 @01:40PM (#10074735)
> I think you overestimate how willing most developers are to fight with the borrow checker instead of using actor libraries or task libraries (TPL, TBB, PPL, Fork-Join, Akka) instead.

That seems like a non-sequitur. What does the borrow checker have to do with actor libraries?

Are you implying that these actor libraries give you the data race freedom guarantees that Rust's mutability rules give you? If so, that's trivially false. Those libraries guide you toward patterns that eliminate data races in simple cases if you follow them, but nothing enforces the rules. Moreover, being forced into actors or message passing for concurrency severely restricts the expressiveness of your program. Rust's approach lets you use shared memory if you like, or message passing if you like, or a combination of the two, with enforcement of the rules no matter which you pick.

> So far the Rust tricks with unsafe for certain data structures (e.g. double linked lists/DAGs) seem like fighting with the borrow checker. Or the issues to be solved with upcoming 1.3 changes for pattern matching.

Yes, they're tough. This is a downside of manual memory management (though one that can be improved in future iterations). But doubly linked lists/tree-like data structures are hard in Haskell too. "Tying the knot" is not exactly easy or intuitive.

Re:Rust web framework, Iron by pjmlp on Monday August 17, 2015 @03:45PM (#10075595)
> Are you implying that these actor libraries give you the data race freedom guarantees that Rust's mutability rules give you? If so, that's trivially false.

No they don't give the freedom, but they give them comfort for the average developers.

I deal a lot with 9-5 enterprise developers that don't even know that HN and Reddit exist, or whatever languages exist out there besides what they use on the job.

Yet they do write multi-threaded code with help of such libraries, happy that someone gives them training wheels.

> But doubly linked lists/tree-like data structures are hard in Haskell too.

True, but laziness helps. However Haskell is hardly a mainstream language.

Re:Rust web framework, Iron by pcwalton on Monday August 17, 2015 @04:22PM (#10075847)
> Yet they do write multi-threaded code with help of such libraries, happy that someone gives them training wheels.

And they create a lot of bugs in the process. Empirically, a message passing framework does not eliminate data races as a very common class of bug.

> However Haskell is hardly a mainstream language.

Well, you brought up Haskell earlier. I agree of course that both Rust and Haskell make it hard to write doubly-linked lists and trees, and that Haskell is not a common industry language.

Re:Rust web framework, Iron by pjmlp on Monday August 17, 2015 @05:22PM (#10076221)
Haskell was just one of the languages on my list. I was basically referring to all languages with available compilers and better web frameworks than what Rust currently offers. And I did miss a few ones.

As for data races elimination, I don't see people really moving away from those libraries, but I might be wrong.

Re:Rust web framework, Iron by tinco on Monday August 17, 2015 @06:18AM (#10072157)
> Rust needs a good story to be sold as alternative for web development.

I don't think anyone is advocating Rust as an alternative for web development. At least not if any of the managed languages are viable alternatives. Of course you should pick C# if it's viable for you, working in it is 10 times more comfortable than working in Rust.

Re:Rust web framework, Iron by threeseed on Monday August 17, 2015 @04:06AM (#10071772)
Rust is faster than most of the languages you listed and has some nice language semantics e.g. generics.

Why should we use Go when more mature alternatives exist ?

Re:Rust web framework, Iron by pjmlp on Monday August 17, 2015 @05:01AM (#10071939)
Except for Go, all the languages I listed have support for generics.

I doubt Rust is faster than the languages I listed. Assuming a comparison with all available compilers, not just open source ones.

I only had Go in the list, because it also compiles to native code and has support for web on its standard library. And it is a good alternative to C for anything that touches the network.

Re:Rust web framework, Iron by pcwalton on Monday August 17, 2015 @02:05PM (#10074907)
Why do you think other languages will optimize as well as Rust? Specifically, how do you propose to get the same level of memory alias analysis with unrestricted aliasing and mutation? How do you propose to deal with escape analysis for higher-order functions without a region/lifetime system?
Re:Rust web framework, Iron by pjmlp on Monday August 17, 2015 @03:36PM (#10075530)
Years of effort put into their compiler optimizers.

For example, without any benchmarks I wonder how Rust current code generation relates to optimizing Ada compilers, specially the commercial ones like Atego.

It is hard to believe a language with an 8 year old compiler already generates better code than a 20 year old compiler battle tested in many production systems, even with the help of LLVM as backend.

Re:Rust web framework, Iron by vitalyd on Monday August 17, 2015 @08:16PM (#10076928)
Perhaps you're discounting the importance of LLVM and at the same time overestimating performance of some of the languages you mentioned.

.NET: type system has some performance oriented features, but JIT compiler isn't all that great (currently).

Java: java has terrible performance model but JVM does heavy lifting to recover a good amount. However, there are still problems once your perf targets get tighter and tighter (ergonomics also degrade the more you push performance).

Re:Rust web framework, Iron by pjmlp on Tuesday August 18, 2015 @01:36AM (#10077733)
I am not overestimating the othe languages, because unlike many HNers I differentiate between languages and implementations.

Just to pick on your example, for Java there is OpenJDK, Oracle's commercial JDK, IBM J9, Excelsior JET, HP-UX JDK and many many other compilers.

The new .NET compiler makes use of the Visual C++ backend, as another example.

Ada compilers have around 20 years history of production code.

Same goes for some of the other languages.

So when one bluntly states that Rust 1.2 compiler already generates faster code than any of the compilers for the other languages, including commercial ones, it is a bit hard to believe.

Of course Rust's compiler will improve code generation.

Re:Rust web framework, Iron by vitalyd on Tuesday August 18, 2015 @08:33AM (#10078817)
Language vs implementation is Sufficiently Smart Compiler phrased differently. The main difference between Rust (and say C++) and .NET/Java is the former has a stronger performance model baked into the language which makes it easier to make an implementation fast.
Re:Rust web framework, Iron by pjmlp on Tuesday August 18, 2015 @09:39AM (#10079110)
However not all implementations are made alike.

For example, when one speaks about Java, are you aware that IBM's J9 compiler supports value types via the packed objects extension?

Or that Mono cannot compete with Visual C++'s backend for .NET native code generation?

Or that any commercial Common Lisp runs circles around the open source offerings?

So speaking of language X, always matters to refer to implementations.

Re:Rust web framework, Iron by vitalyd on Tuesday August 18, 2015 @10:05AM (#10079230)
I'm aware of PackedObjects. Note it's not a value type in the sense it doesn't get allocated on the stack (if used as a local), it's a flattened object graph on heap with a shared header.

More to the point, implementations are interesting to compare when they're for the same language, but not so much across languages as languages have different semantics and features that dictate how amenable they are to optimization with today's compilation techniques.

Re:Rust web framework, Iron by pjmlp on Tuesday August 18, 2015 @10:50AM (#10079485)
I disagree.

There is a good reason why we don't use e.g. Tiny C to discuss C performance vs other languages.

Re:Rust web framework, Iron by vitalyd on Tuesday August 18, 2015 @11:59AM (#10079893)
Maybe I didn't make myself clear. If you want to compare speed cross lang, take fastest impl of each and compare that; so long as we're talking about real compilers existing today.

Also, fundamentally C# and java aren't designed on zero-cost abstractions as core principle, which is fine in and of itself. Implementations try to recover performance but it's an uphill battle as compilers will always be limited by various constraints.

Re:Rust web framework, Iron by pjmlp on Tuesday August 18, 2015 @12:45PM (#10080278)
> Maybe I didn't make myself clear. If you want to compare speed cross lang, take fastest impl of each and compare that; so long as we're talking about real compilers existing today.

I agree.

> Also, fundamentally C# and java aren't designed on zero-cost abstractions as core principle,....

Sure, but then again Ada, Delphi and D are also on my language list.

Re:Rust web framework, Iron by steveklabnik on Tuesday August 18, 2015 @10:32AM (#10079372)
Rust uses LLVM for codegen, which has had a _lot_ of time and resources poured into it.
Re:Rust web framework, Iron by pjmlp on Tuesday August 18, 2015 @12:48PM (#10080306)
True, but having a good motor is not enough for having a good car.

For example, apparently SIMD is only getting done on 1.3.

Again, my whole argument goes against someone stating that Rust 1.2 compiler already generates better code than all the existing compilers for my language list, some of them with 20 years of production code.

It is quite clear to me that Rust compiler will improve and take better advantage of LLVM. I just don't believe that 1.2 is already there.

Re:Rust web framework, Iron by pcwalton on Monday August 17, 2015 @04:53PM (#10076039)
I think there's no way we're going to know either way in terms of the current state of the art. I do think, however, that Rust has language advantages that will enable better optimization going forward than languages with unrestricted (or less restricted) aliasing and mutation.
Re:Rust web framework, Iron by pjmlp on Monday August 17, 2015 @05:16PM (#10076186)
I agree Rust will get better, but the comment I has replying to was about code quality today.
Re:Rust web framework, Iron by baq on Monday August 17, 2015 @05:17AM (#10071977)
if you're "fighting the borrow checker", you're doing it wrong. borrow checker is there to help you.
Re:Rust web framework, Iron by steveklabnik on Monday August 17, 2015 @10:12AM (#10073053)
People often use the phrase to indicate their initial difficulty when learning Rust, not deliberately attempting to subvert it once they understand it.
Re:Rust web framework, Iron by pjmlp on Monday August 17, 2015 @05:31AM (#10072028)
Not when implementing graphs and double linked lists apparently, without using unsafe.
Re:Rust web framework, Iron by pcwalton on Monday August 17, 2015 @02:12PM (#10074967)
Implementing a doubly-linked list using RefCell is no worse in difficulty as implementing a doubly-linked list in Haskell.
Re:Rust web framework, Iron by pjmlp on Monday August 17, 2015 @03:47PM (#10075612)
How many average joe developer do you see adopting Haskell in the industry?