News for hackers. Stuff that matters.
Re:The struggle with Rust by gnuvince on Tuesday January 24, 2017 @07:49AM (#13470881)
When I first learned OCaml (knowing only Python), I swore a lot at the type checker for refusing to compile code that I knew would work at run-time (e.g., a variable having multiple types, but on strictly disjoint execution paths). It seemed insane to me that people would want to subject themselves to this kind of bondage and discipline. And yet, many years later now, I have learned and internalized how type systems work, I have learned not to try and simply replicate Python patterns in OCaml, and as a result I use OCaml to write code quickly and without any headaches; and not only is the type checker no longer an obstacle, it's now a valuable assistant.

I believe that we are seeing the same kind of phenomenon in Rust: we are trying to replicate C or C++ code directly in Rust, and we get frustrated when our efforts are foiled by the borrow checker. It's going to take some time and some efforts before we learn and internalize how borrowing works in Rust and how to change the way we write programs so that it is no longer an obstacle. The Rust team looks very receptive to comments about taking away some pain points (e.g., non-lexical lifetimes), but we also need to accept that, for a little while, we are going to feel like we did when we were new programmers and were trying to make sense of these new constraints.

Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @09:06AM (#13471346)
This is a different issue. The problem that the author is observing is that Rust operates on the hypothesis that the ownership relation is mostly left-unique and acyclic and that you run into problems when this hypothesis doesn't hold. And this affects not only explicit data structures, but also the implicit structures that involve stack frames (local variables, closures, etc.).

While Rust has mechanisms to deal with this (copying, Rc<T>, etc.), all these mechanisms add pain points, and for problems that are not just theoretical. It affects a number of design patterns, closures that survive the scope they were created in, functional-style programming, functional data structures, any data structure that naturally involves a DAG or cycles.

The difference compared to a (good) static type system is that a good [1] static type system does not measurably reduce expressiveness; Rust's ownership model does.

This is not to say that there isn't a point to Rust's model. Rust directly competes with garbage collection as the main alternative model to achieve memory safety and is an obvious choice in cases where garbage collection is not a realistic option. But where garbage collection is an option, the tradeoffs that Rust makes become much less attractive.

[1] Obviously, primitive static type systems (example: Java up to version 1.4) do pose a problem.

Re:The struggle with Rust by humanrebar on Tuesday January 24, 2017 @09:20AM (#13471463)
First, the expressiveness is all there. You just need to explicitly say you are responsible by using unsafe blocks. So risky pointer and allocation logic becomes the programmer's job, not the borrow checker.

Second, this article only considers the costs of a stricter borrow checker, not the benefits. It will be more work for the coder to have to think about how allocation and ownership is communicates. But I've been through much bigger headaches in production code at inconvenient times (for the business plan) due to dangling pointers, multi-writer concurrency bugs, and ill-defined memory models in software designs.

Even if Rust is much harder than alternatives instead of just different, and even if that's inherent in borrow checking, it's not clear that it's still not worth it in the long run.

Re:The struggle with Rust by Bartweiss on Tuesday January 24, 2017 @10:01AM (#13471793)
> Even if Rust is much harder than alternatives instead of just different, and even if that's inherent in borrow checking, it's not clear that it's still not worth it in the long run.

One obvious argument is that Rust frontloads its difficulty. It's a terrible tool for most 30 line tasks, simply because the majority of your work will go into arguing with the compiler. But that's true of a great many tools - if there's an adequate payoff in safety and comprehensibility at scale, they can still be worthwhile.

That doesn't solve the learning-and-usage problem, though. Most of us are aware that the explosion of dangerous-at-scale tools like Javascript is largely because no one adopts a language that's unfriendly until you reach enterprise sizes. Even if Rust is "worth it", it's unlikely to catch on while the learning experience feels like pulling teeth.

Re:The struggle with Rust by bluejekyll on Tuesday January 24, 2017 @10:42AM (#13472200)
> It's a terrible tool for most 30 line tasks, simply because the majority of your work will go into arguing with the compiler.

This arguing with the compiler is really only while you are learning Rust and it's nuances. For me the first two weeks were this way, then I started thinking more in Rust terms. Now I rarely deal with the borrow checker at all, but I do end up in some complex type situations.

You're spot on with the frontloads difficulty. Honestly though, I can't think of any language that I've learned that in under a few weeks I knew how to properly do things in the language.

Python was this way for me. My code looked like C when I started with it, and then I learned after a few weeks about 'with' and 'yield' and started writing real code.

Rust is worth the initial investment, but the first two weeks will require some perseverance.

Re:The struggle with Rust by spullara on Tuesday January 24, 2017 @11:17AM (#13472574)
I think the difference is that while you are coding Python in a C style the code is working. The front loaded nature of Rust means that you are in a constant fight to get something to run.
Re:The struggle with Rust by bluejekyll on Tuesday January 24, 2017 @11:30AM (#13472757)
Yes, and I understand how frustrating it can be, I had to learn it, too. My only point is that after you spend the time with it, the cognitive load becomes a lot less and you've learned some new things about programming at the same time.
Re:The struggle with Rust by spullara on Tuesday January 24, 2017 @12:47PM (#13473613)
I believe this. However, my concern is that the number of people willing to make it through that learning curve is small and will limit the adoption of Rust.
Re:The struggle with Rust by bluejekyll on Tuesday January 24, 2017 @02:25PM (#13474609)
I'm hoping that things like the Rust Language Server and it's integration into some of the IDE's out there will help with the initial learning curve; already the rustc error output is a million times better than when I started with it.

I definitely share your concern; for me, Rust was like putting on a glove perfectly shaped for my hand. It works and prevents every basic pattern that it took 10 years to learn and start applying to all my code thereafter. If I had Rust all those years ago, it would have saved me a ton of time... but I probably would have turned my nose up at it, b/c I wouldn't have had the experience to understand what it was saving me from.

So yes, I want the learning curve to be lower, but not at the expense of losing all of the safety it brings to developing fast and reliable software.

Re:The struggle with Rust by spullara on Tuesday January 24, 2017 @08:48PM (#13477711)
Have they thought about allowing code to work by warning and elevating the scope so you can quickly get the procedural work done and then attack the memory usage?
Re:The struggle with Rust by bluejekyll on Wednesday January 25, 2017 @12:13AM (#13478748)
I've been thinking about a good answer to this, but I don't know what it would look like. Code looks so different when you need to be concerned about mutable vs. immutable borrows. For example you might want to iterate over a list perform an action and then delete items after doing work. This needs to be broken into two blocks, one that does the iteration and then a second block to remove any elements that no longer belong.

That's an example of just two blocks, but if it's deeper structures then ignoring this until the end could cause you to go back and restructure significant sections of code to make it abide by the mutability rules.

The process I use to stay productive, is to write small blocks of code, write a unit test for it, compile, and then move on. That way I don't build up a ton of compiler debt...

Re:The struggle with Rust by mmstick on Wednesday January 25, 2017 @05:38PM (#13486944)
I've been writing Rust solutions for two years now, and I do not feel like I am in a 'constant fight' to get something to run. That only happened for the first two or so weeks as I was learning Rust.
Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @11:21AM (#13472640)
> This arguing with the compiler is really only while you are learning Rust and it's nuances. For me the first two weeks were this way, then I started thinking more in Rust terms. Now I rarely deal with the borrow checker at all, but I do end up in some complex type situations.

It just means you've learned to head off problems before they occur, that does not mean the problems you're heading off should be there.

Re:The struggle with Rust by nickpsecurity on Tuesday January 24, 2017 @11:43AM (#13472931)
"One obvious argument is that Rust frontloads its difficulty. It's a terrible tool for most 30 line tasks, simply because the majority of your work will go into arguing with the compiler. "

It does. Ada did too with people saying same stuff. Once they got used to it, they swore by Ada since their stuff usually worked after they got it past compiler. I also add that the alternative to Rust for GC-free safety of heap code is essentially separation (VCC) or matching logic (KCC). That's probably much harder for average programmer to work with than structuring stuff to get through borrow checker easily. Cyclone and then Rust were huge steps up on dynamic, memory safety given they're accessible to people who don't know formal verification.

That's the comparison people keep leaving off griping about borrow checker. I think Rust looks a lot better when one adds it. Still a headache but good in relative way.

Re:The struggle with Rust by allengeorge on Tuesday January 24, 2017 @11:13AM (#13472529)
My observation is that that's not quite true. It's fine for smaller tasks, but that mushy middle where you're discovering the parameters and outlines of a problem can be painful. Looser (note that I explicitly don't say "better" or "worse") languages give you more leeway to play around and discover how the problem is structured.
Re:The struggle with Rust by mmstick on Wednesday January 25, 2017 @05:36PM (#13486934)
I can easily slap out a 30-line program and have it compile and work on the first try with Rust, guaranteed. No competent Rust developer has issues writing solutions in Rust. Nobody but newcomers are 'arguing with the compiler'.
Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @10:37AM (#13472162)
> First, the expressiveness is all there. You just need to explicitly say you are responsible by using unsafe blocks. So risky pointer and allocation logic becomes the programmer's job, not the borrow checker.

No, unsafe would be overkill and if you needed unsafe, it would put Rust at a massive disadvantage vis-à-vis garbage-collected languages.

Simply put, Rust doesn't handle multiple ownership well. It results in syntactic bloat and/or runtime overhead. But multiple ownership occurs naturally in a number of real-world programs.

> Second, this article only considers the costs of a stricter borrow checker, not the benefits.

This is why I very specifically mentioned that it's a tradeoff.

Re:The struggle with Rust by bluejekyll on Tuesday January 24, 2017 @11:24AM (#13472686)
I think you're implication here is that other languages do handle multiple ownership well. What I think you find in Rust, is that the guarantees you need to make when using unsafe in these limited situations, are the exact same guarantees you need to make in a language like C or C++.

Destroying a circular list takes some thought to make sure you don't double free, same as Rust. Rust just makes those sections of code very explicit and calls your attention to it, while in C you may end up with a segfault, or worse a program that only shows odd bugs during runtime. At least Rust is telling you that you need to put some extra thought in this section.

Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @12:21PM (#13473355)
Your assumption seems to be that I'm talking about languages with manual memory management. I'm not; I'm talking about garbage-collected languages, where you get memory safety automatically, regardless of ownership rules. In fact, C++ has some of the same problems that Rust has when it comes to multiple ownership.
Re:The struggle with Rust by kaoD on Tuesday January 24, 2017 @12:38PM (#13473525)
Then use https://github.com/Manishearth/rust-gc if you're willing to pay the price of a GC (still experimental). Or better, stick to a GC'ed language.

If you don't need manual memory management, it's obviously going to be a burden. There are still use cases for manual memory management though, and that's where Rust comes in.

Use the right tool for the job.

Re:The struggle with Rust by Manishearth on Tuesday January 24, 2017 @12:56PM (#13473722)
(Please don't use rust-gc, it's more of a proof of concept. I mean, it works, and some folks do use it, but Rc + Weak are probably better options)
Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @12:49PM (#13473634)
> If you don't need manual memory management, it's obviously going to be a burden. There are still use cases for manual memory management though, and that's where Rust comes in.

That's exactly the point that I made in my original comment?

Re:The struggle with Rust by kaoD on Tuesday January 24, 2017 @12:57PM (#13473734)
Sorry, HN isn't great at keeping track who's who on a comment tree.
Re:The struggle with Rust by galangalalgol on Wednesday January 25, 2017 @07:10PM (#13487482)
Does GC imply memory safety? Use after free and dangling references probably can't happen, but I have never heard of a GC supplying cross thread memory safety. The borrow checker does.
Re:The struggle with Rust by rbehrends on Thursday January 26, 2017 @01:14PM (#13493727)
Memory safety in multi-threaded programs is not a hard problem once you have GC. Eiffel solved it decades ago. The JVM also has a weak form of memory safety; it does not preclude data races, but the VM cannot crash as the result of a data race.
Re:The struggle with Rust by humanrebar on Tuesday January 24, 2017 @10:54AM (#13472326)
> No, unsafe would be overkill

I don't see an issue with 'unsafe' if it's an implementation detail and well-tested. Obviously it would be better to avoid it if possible. 'unsafe' is overkill sometimes and worth it other times.

Re:The struggle with Rust by bluejekyll on Tuesday January 24, 2017 @11:18AM (#13472601)
Instead of unsafe, as much as possible should be looking at interior mutability, Cell and RefCell allow for this, with no unsafe, and they guarantee for you at runtime that what you believe is accurate.

unsafe should be IMO, reserved for only those cases where strictly needed, e.g. FFI is the clearest example.

Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @11:19AM (#13472606)
> if it's an implementation detail and well-tested

The same can be said of C and C++, at which point, why does it matter if you use Rust?

Re:The struggle with Rust by humanrebar on Tuesday January 24, 2017 @02:40PM (#13474745)
Rust has opt-out safety with 'unsafe' blocks. C++ doesn't even have opt-in safety. You can get fairly close with smart pointers and some other techniques, but 'fairly close' doesn't cut it when you're talking about memory corruption issues.
Re:The struggle with Rust by AstralStorm on Tuesday January 24, 2017 @03:24PM (#13475111)
You can enforce safety by using the strict type system combined with polymorphic memory allocators in C++17, and get quite close to that with C++11.

The only thing you cannot exactly prevent is "cast_dammit_cast".

Re:The struggle with Rust by dbaupp on Tuesday January 24, 2017 @03:39PM (#13475249)
Could you be specific about how the type system and polymorphic memory allocators defend against things like dangling references, iterator invalidation and use-after-free/move? I can't imagine an allocator affecting these unless it's one that just has a no-op free (which only use-after-free, anyway), nor is the type system strong enough by itself.
Re:The struggle with Rust by AstralStorm on Wednesday January 25, 2017 @02:45AM (#13479543)
1) If you cannot get a plain reference you cannot get dangling references. 2) Use data structures that keep iterators valid and modern reference counted internals. (so that when you have an iterator, you have the object) Alternatively copy on write semantics. 3) Use after move is relatively tricky if you want more. However, your allocator or data structure can catch it with specific implementation of move operators. Use after free can be reduced to use after move or caught with right delete/new operators. 4) Instead, you may have an API where you have your own high level reference-like type. There is a cost to it, same as in Rust. 5) What you cannot do is enforce people to use it always.
Re:The struggle with Rust by dbaupp on Wednesday January 25, 2017 @02:22PM (#13484976)
> There is a cost to it, same as in Rust

All of these things have a larger cost than Rust: you're forced to use pervasive reference counting and very defensive data structures. Rust allows you to get away with pointers deep into other things, as well as aggressive data structures, all in safe code.

Rust also has reliable use-after-move defense for arbitrary resources (not just vague dynamic protections for only the memory resource), and defends against data races. That is, Rust has true safety in a way that can give higher performance than approximate safety in C++.

Re:The struggle with Rust by pjmlp on Tuesday January 24, 2017 @11:31PM (#13478538)
Kind of, you cannot enforce your team mates, consultants and third party libraries that are part of the whole product to use them.

Static analysers and code reviews are not always possible, depending on the target OS and compiler being used, or how the whole project across teams is organized.

Re:The struggle with Rust by jackmott on Tuesday January 24, 2017 @09:25AM (#13471502)
It might be worth it over C++, but assuming the task at hand is not hindered by garbage collection, is it ever worth it over an ML style language?

It certainly takes a lot more typing to get things done.

Re:The struggle with Rust by pmoriarty on Tuesday January 24, 2017 @12:52PM (#13473674)
I think it's always worth it to learn new paradigms. They expand your view of what's possible, and give you a richer understanding of the other languages you already know, understanding some of the tradeoffs they made, and give you other conceptual and practical tools in your toolbox.

It's much like visiting other, radically different countries than the ones you've been brought up in. Even if you don't wind up moving there permanently, you'll be richer for the experience.

Re:The struggle with Rust by rntz on Tuesday January 24, 2017 @10:45AM (#13472229)
> The difference compared to a (good) static type system is that a good [1] static type system does not measurably reduce expressiveness

This is pseudo-jargon. What counts as a "measurable" reduction? Do you have any substantive evidence that "good" typesystems don't reduce it? And why are only type systems which satisfy this property "good"? You talk cogently about tradeoffs later on, but this sentence taken literally suggests only a type system which doesn't make this particular tradeoff can be "good". Why?

My go-to languages for the past few years have been Haskell and Racket. There have definitely been times I picked Racket because I knew Haskell's type system would interfere with my expressiveness. Certainly Haskell is less restrictive than Rust with regards to ownership, but all type systems restrict you. I think GP is spot-on in pointing out that you just get used to it over time as you learn to think and code in ways that avoid pushing against the type-system's weak spots.

> But where garbage collection is an option, the tradeoffs that Rust makes become much less attractive.

Yes, precisely. It's not a fundamentally different issue from getting used to other static type-systems; it's just a different tradeoff.

Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @11:10AM (#13472489)
> This is pseudo-jargon. How do you measure expressiveness?

Actually, not jargon. I had Matthias Felleisen's characterization of expressiveness [1] in mind (incidentally, he's also one of Racket's authors).

> Do you have any substantive evidence that "good" typesystems don't reduce it?

If we want to be precise, there is a continuum from statically to dynamically typed language. A dynamically typed language is, after all, the same as a static language with just a single polymorphic type. This means that we can trivially translate a dynamically typed program into a statically typed program, though obviously we don't gain anything by that at this point (this is essentially an argument that Bob Harper has advanced before) and we pay for it in additional verbosity. However, in practice we know that we don't need all that flexibility and can constrain types more, allowing us to get better type guarantees; static types then also allow us to do things that we can't do in a dynamic language (such as compile-time overloading).

[1] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.51.4...

Re:The struggle with Rust by rntz on Tuesday January 24, 2017 @12:54PM (#13473697)
EDIT: I've been chewing over the following:

> This means that we can trivially translate a dynamically typed program into a statically typed program, though obviously we don't gain anything by that at this point (this is essentially an argument that Bob Harper has advanced before) and we pay for it in additional verbosity.

This is exactly the opposite of the argument I advance below; you're claiming that there is a "local" translation from dynamic to static. And on reflection, you might be right, but I'm not entirely sure. It hinges on exactly what counts as "local". Translating away exceptions, for example, requires inserting case-analyses which propagate an exception if one has been thrown literally everywhere in your program. It's "global" in the sense that it touches every node in the program; it's "local" in the sense that the transformations performed don't involve any global knowledge or analysis. I'm rereading Felleisen's paper now to see how precisely he defines things.

ORIGINAL:

> I had Matthias Felleisen's characterization of expressiveness [1] in mind (incidentally, he's also one of Racket's authors).

Great! I believe, by that definition, your assertion that "good" typesystems don't reduce expressiveness is false, at least for common type systems such as Haskell's, Java's, ML's, etc. There are plenty of programs which require non-local rewriting ("a global reorganization of the entire program") in order to appease the typechecker.

A simple example can be adapted from the expression problem: suppose I'm writing an compiler for a simple language, so I have an AST datatype and some functions on it. Then I add a pass to my compiler that removes a certain feature from the language I'm implementing - a certain branch of the AST. Now I wish to simplify my backend by removing the case which handles this branch of the AST. I cannot do that without either dynamically failing in that case (which a type system might even prevent me from doing) or introducing an entirely new AST type which does not have that branch - but this could require duplicating or else considerably generalizing existing code that operates on the AST (a global reorganization). Of course, a sufficiently powerful typesystem might let me do that, but for any typesystem you name, I suspect a similar example can be procured.

To get more precise, the "feature" we're considering adding is "ignoring the typechecker and running anyway". For example, GHC's -fdefer-type-errors. The question is "can any legitimate program written with -fdefer-type-errors be locally translated into an equivalent program that typechecks without -fdefer-type-errors". Without reaching for an explicit escape hatch like unsafeCoerce (which is analogous to "unsafe" blocks in Rust), I think the answer is no.

Re:The struggle with Rust by dllthomas on Tuesday January 24, 2017 @07:43PM (#13477332)
First, let me say that I think you're right that expressiveness is reduced. In the best case, all of that reduction is of things we don't want to express because they are incorrect - but in practice (and probably in theory!) the boundary will always be fuzzy.

That said, with regard to your "kill a branch in your AST" example, you can kill a branch with Void:

    import Data.Void

    frobnicate :: Either a Void -> a
    frobnicate (Right x) = absurd x
    frobnicate (Left x) = x
Now you can rely on no-one accidentally handing you a Right expecting you to do something reasonable with it.
Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @01:58PM (#13474355)
> Great! I believe, by that definition, your assertion that "good" typesystems don't reduce expressiveness is false, at least for common type systems such as Haskell's, Java's, ML's, etc.

Haskell is not very good at extensible runtime polymorphism (one of its weaknesses). Try OCaml's polymorphic variants.

Re:The struggle with Rust by rntz on Tuesday January 24, 2017 @04:54PM (#13475973)
Okay, then I can pick another example: A dictionary where the type of the values depends on the key they're inserted under. (For example, a representation of the closure of a function in a typed language.) Of course, then I can go to a dependently typed language, but are you really going to tell me that only dependently typed languages count as "good" static type systems?
Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @08:24PM (#13477584)
I am not arguing completeness here; a type system is not a full-blown specification language and does not have to be. (I actually tend towards the point of view that trying to make them complete specification languages has limited practical value, but that's a different issue.)

The point here is that the type system does not restrict me from implementing a data structure that adheres to this constraint, even if it does not enforce it for me.

Re:The struggle with Rust by dllthomas on Wednesday January 25, 2017 @12:09AM (#13478724)
You can do this in GHC Haskell with existential quantification, or trade static checks for runtime with Data.Dynamic.

(Again, not arguing against your thesis here.)

Re:The struggle with Rust by codygman on Tuesday January 24, 2017 @02:26PM (#13474616)
After quickly scanning https://realworldocaml.org/v1/en/html/variants.html, isn't the same thing accomplished by GADTs?
Re:The struggle with Rust by rbehrends on Tuesday January 24, 2017 @02:39PM (#13474727)
The point of polymorphic variants is that the entire type doesn't have to be fully defined in one place; you can have partial definitions in a module and those definitions can even overlap. You can have (say) [ `Int of int | `String of string ] in one module and [ `String of string | `Char of char ] in another, and the typechecker will handle intersections and unions of these types.
Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @11:17AM (#13472585)
I agree, ayende is a C# person, he's well aware of statically typed languages.

I also agree about your other points, I think maybe one of these days the borrower will become more sophisticated, but these issues he's complaining about are the exact reason I put Rust down. It just felt too sophomoric, as if the language wasn't really ready.

Not all is bad, I really like the way errors are handled in Rust, but there are definitely some problems with the approach they take.

Re:The struggle with Rust by jnbiche on Tuesday January 24, 2017 @09:04AM (#13471332)
> I believe that we are seeing the same kind of phenomenon in Rust:

I don't know. I picked up OCaml fairly quickly, but I have consistently struggled with Rust, trying it for a while before abandoning it in frustration with lifetimes, 2 or 3 times. I can program in Rust, but it still seems like an ongoing struggle, as opposed to the smooth brain to text programming I've gotten used to in Python, JavaScript, OCaml, and Lua, and to a lesser extend C, Go and Elixir (just because I haven't used to latter 3 as much, at least recently).

I think Rust may be ideal for embedded software development, or low-level systems software, but for general application development, I think OCaml or perhaps Swift or Scala are more ideal, at least for me (or at least until I decide to try Rust again, perhaps it will stick this time).

Edit: Oh yeah, and I was even able to become productive enough in Scala to build a significant project (a programming language) in a relatively short period of time. Now, I'm not silly enough to think I've really mastered Scala in such a short period of time, but I was using it productively as a functional language as I would OCaml with little difficulty. On the other hand, I've started 3 (3!) programming languages in Rust but have yet to get beyond much beyond the parser/AST stage before I quit in frustration.

Re:The struggle with Rust by smt88 on Tuesday January 24, 2017 @09:21AM (#13471470)
> smooth brain to text programming

This isn't a good thing, in my opinion. Brains make mistakes. I don't want smooth, uninterrupted coding. I want the compiler to tell me when I'm making the mistake, even if it makes things choppier. It's a lot less painful to write code in fits and starts than to write a million tests or spend hours debugging.

Re:The struggle with Rust by sametmax on Tuesday January 24, 2017 @09:39AM (#13471601)
It depends a lot of what you code and your constraints. Believe it or not they are a huge crowd of people making a living out of code that is easy to write but crashes. And they are happy about it.

E.G: one of my friend has a streaming website. He make banks with ads despite the site having problems all the time. He doesn't care the least. He is not an expert coder and just want to be able to build the features he needs, even if it's not perfect. Types are way too much for him. It took 2 years to master git basics.

Another example: my current clients are geomaticians. They code in Python a lot. They produce only small codes, and don't want something complex. They are experts in maps, not code, and love Python to have the balance of cost / reward they want.

HN is a bubble of expert devs, but the world is full of PHP plumbers, data manglers, sys admin and other professional that have a legitimate needs for "smooth brain to text programming".

Re:The struggle with Rust by kibwen on Tuesday January 24, 2017 @12:27PM (#13473412)
And I think that's fine; Rust isn't trying to be the one language to rule them all. It's intended as a foundational language: your friend's streaming website survives despite his own code crashing often, but it won't survive if his off-the-shelf HTTP server crashes often (HTTP servers being the sort of thing one would write in Rust). Likewise, your mathematicians aren't going to be very productive if their Python interpreter crashes often (likewise, interpreters are the sort of thing one would also imagine writing in Rust).

Even in Rust's ideal future, very little of the code atop the stack is written in it. It's the code at the very bottom that underpins everything whose share it hopes to eat.

Re:The struggle with Rust by sh_tinh_hair on Tuesday January 24, 2017 @01:30PM (#13474074)
Dictatorial concepts in PL usually fail pretty badly. Rust may become the textbook example of a good idea too far. I'd certainly never use it or use anything written in it given a choice and/or time to rewrite in anything more accessible.
Re:The struggle with Rust by kibwen on Tuesday January 24, 2017 @03:24PM (#13475109)
> or use anything written in it

As I often say on HN, I must be missing the sarcasm here...

Re:The struggle with Rust by webmaven on Tuesday January 24, 2017 @04:08PM (#13475461)
I think "use" in this case is in the sense of a developer using code, rather than an end-user application.
Re:The struggle with Rust by sametmax on Wednesday January 25, 2017 @06:39AM (#13480582)
Oh yeah that's fine. Both languages are actually very nice used together.
Re:The struggle with Rust by jnbiche on Tuesday January 24, 2017 @09:35AM (#13471576)
> I want the compiler to tell me when I'm making the mistake, even if it makes things choppier.

You don't think the OCaml type system would do this? OCaml gives you just as much safety as Rust does, it just doesn't also give you no GC like Rust does. And the price Rust pays for the absence of GC is the lifetime concept, which adds a very significant layer of complexity to the language. Much like OCaml, Swift and Scala also provide very safe type systems.

Again, if you can't have a GC, then Rust is an excellent option, and the only really safe GC-less language unless you use C with FramaC or similar static analysis (and FramaC also requires lots of training and time to use, just like Rust).

Re:The struggle with Rust by pcwalton on Tuesday January 24, 2017 @11:25AM (#13472698)
Ownership and borrowing are also useful for avoiding data races. OCaml solves the problem by not having any shared state at all, which is obviously a huge limitation.
Re:The struggle with Rust by jnbiche on Tuesday January 24, 2017 @12:12PM (#13473264)
Current OCaml needn't worry about data races since no state is shared. Unfortunately, current OCaml also only exploits a single core, but it's so insanely fast that usually doesn't matter.

Upcoming OCaml multicore solves the shared state and data races problem with algebraic effects[0]. It is working, it's just not yet been released in mainline OCaml. Supposedly, that will happen this year, but we'll see.

0. http://kcsrk.info/ocaml/multicore/2015/05/20/effects-multico...

Re:The struggle with Rust by Bartweiss on Tuesday January 24, 2017 @10:05AM (#13471832)
OCaml seems like the argument against Rust's claim to trade usability for safety. It's not true for everything, I wouldn't write embedded OCaml, but it's an easy disproof-by-example for "Rust's difficulty is the inevitable price for trustworthy code!"

Which isn't to say OCaml is trivial, or Rust is useless (GC and threading both being limitations). It just makes me skeptical of claims that Rust's difficulty is irreducible.

Re:The struggle with Rust by kibwen on Tuesday January 24, 2017 @12:22PM (#13473361)
Rust's difficulty relative to OCaml might be irreducible if we consider the difficulty added by not providing a pervasive GC, which is part of Rust's design goal and not part of OCaml's.
Re:The struggle with Rust by Ar-Curunir on Tuesday January 24, 2017 @12:03PM (#13473140)
But OCaml isn't intended for the use cases Rust is intended for: a replacement for C and C++
Re:The struggle with Rust by pjmlp on Tuesday January 24, 2017 @12:54PM (#13473692)
It depends on the use cases you mean.

OCaml is actually used for many systems programming tasks that can live with a tracing GC.

Re:The struggle with Rust by GregBuchholz on Tuesday January 24, 2017 @12:19PM (#13473332)
>I wouldn't write embedded OCaml

But you can run OCaml on a microcontroller:

http://www.algo-prog.info/ocapic/web/index.php?id=ocapic

Re:The struggle with Rust by jackmott on Tuesday January 24, 2017 @09:36AM (#13471581)
I don't think they are any error classes that OCaml/F# will let you make that Rust won't.
Re:The struggle with Rust by stonemetal on Tuesday January 24, 2017 @09:57AM (#13471750)
Rust prevents data races, OCaml/F# don't provide such guaranties. Though it isn't so much of a problem in OCaml since it doesn't have concurrent threads.
Re:The struggle with Rust by jnbiche on Tuesday January 24, 2017 @12:16PM (#13473302)
OCaml has GIL, is normally single core, and shares no state, so current OCaml doesn't need to provide such guarantees.

Upcoming multicore OCaml will provide such guarantees through algebraic effects [0].

0. http://kcsrk.info/ocaml/multicore/2015/05/20/effects-multico...

Re:The struggle with Rust by AstralStorm on Tuesday January 24, 2017 @03:35PM (#13475213)
First, Rust does not prevent data races, just makes them pain to write.

Second, Rust also prevents legitimate sharing in a bunch of cases where concurrency is not involved. (and a simple scoped allocator succeeds)

This would be fixed if there was an easy way to have typed memory that can be shared but cannot be accessed concurrently. There is none. You get at most full unsafe.

Re:The struggle with Rust by steveklabnik on Tuesday January 24, 2017 @03:41PM (#13475260)
Rust does prevent data races, as long as you don't use unsafe. If not, it's a bug.

You can write arenas in Rust.

Re:The struggle with Rust by GolDDranks on Tuesday January 24, 2017 @04:05PM (#13475435)
Just to be clear about the terminology (since I'm not sure if the grandparent knows about the difference): Rust prevents data races but not race conditions (although it makes it easier to avoid them). Here's an explanation about the differences: http://blog.regehr.org/archives/490
Re:The struggle with Rust by AstralStorm on Wednesday January 25, 2017 @02:49AM (#13479560)
You can, but it is an extreme pain to do it, especially for any nontrivial data structure. That is because even if the arena is safe enough, say with copy on write semantics, you cannot specify that for the borrow checker easily (or at all)

You cannot implement many data structures in a decent performance way without unsafe, so Rust guarantee is weak.

Re:The struggle with Rust by dbaupp on Wednesday January 25, 2017 @02:27PM (#13485033)
> You can, but it is an extreme pain to do it,

It is not extreme, and it isn't even necessary: just reuse one of the many arenas others have already written, e.g. https://crates.io/crates/typed-arena .

Copy-on-write is fairly ease to write in Rust, e.g. the even core Rc and Arc types have a get_mut function that does copy-on-write.

> You cannot implement many data structures in a decent performance way without unsafe, so Rust guarantee is weak.

You can't implement anything in C or C++ without unsafe: Rust's main strength is the ability to write high performance code with a safe interface, so that only one library has to muddle through the `unsafe` problems (if they have to touch `unsafe` at all). Most code one writes is not implementing data structures.

As a demonstration of this strength, even very low-level projects like operating systems can get away with not using `unsafe` everywhere by packaging it up into safe interfaces, e.g. http://os.phil-opp.com/modifying-page-tables.html

Re:The struggle with Rust by pcwalton on Tuesday January 24, 2017 @11:25AM (#13472703)
Data races.
Re:The struggle with Rust by sametmax on Tuesday January 24, 2017 @09:34AM (#13471564)
Give it time. Rust is brand new and has changed considerably during the last year. The rust team listen closely to the community and will smooth things up. But they can't do it all at once.
Re:The struggle with Rust by Bartweiss on Tuesday January 24, 2017 @10:07AM (#13471851)
This is worth remembering. I'm technically on my "second attempt" to learn Rust, but the first one wasn't abandoned because Rust is fundamentally flawed. It was just new enough that the thing I wanted to build was drowning me in nightly builds and hypothetical features. After giving it ~1 year, things are already looking much more welcoming.
Re:The struggle with Rust by Recurecur on Tuesday January 24, 2017 @11:43AM (#13472919)
> I think Rust may be ideal for embedded software development, or low-level systems software, but for general application development, I think OCaml or perhaps Swift or Scala are more ideal, at least for me (or at least until I decide to try Rust again, perhaps it will stick this time).

If you're not aware of it, scala-native looks very interesting... It looks to be active project.

https://github.com/scala-native/scala-native

FWIW, I've also enjoyed Swift development quite a bit. I think Swift will go deep into the C++ sweet spot.

Re:The struggle with Rust by pjmlp on Tuesday January 24, 2017 @02:13PM (#13474499)
A benefit that Swift has over Rust in regards to market adoption, is that an OS vendor has the power to say "My way or the highway" to developers that want to target their platform.

However Rust is already picking up steam in Firefox modules, hobby OS development, university CS degrees and GNOME modules, so there might be a path there.

Re:The struggle with Rust by fjrieiekd on Wednesday January 25, 2017 @08:20AM (#13481162)
The tooling for Swift is certainly miles better on iOS, but I do like Rust as a language. On Android the most comprehensive solution I've seen is Xamarin, but last time I tried it (which was years ago), I wasn't a fan of the GUI and the perf was worse than Dalvik. Hopefully that has improved now.
Re:The struggle with Rust by fjrieiekd on Wednesday January 25, 2017 @08:23AM (#13481175)
Rust seems really great as infrastructure level code, but the tooling still has a lot of rough dyes when it comes to mobile development.

I think Swift could play a decent role here if it ever gets good android support as it already enjoys first-class support on iOS. I also agree in that Swift feels very nice. :)

Re:The struggle with Rust by aomix on Tuesday January 24, 2017 @09:24AM (#13471495)
To me it seems like Rust has an additional wrinkle with safe and unsafe code. A new Rust user needs to figure out both "How do I do this" and "Is this possible in safe code". The limits of safe code seems to be something people are figuring out at all levels. Rust projects seem to start out with a relatively high amount of unsafe code. Then as the project matures the unsafe sections are reduced or eliminated.
Re:The struggle with Rust by maffydub on Tuesday January 24, 2017 @10:18AM (#13471966)
I think whether you feel you need unsafe when you first come to Rust depends on the angle from which you're coming.

Coming from C/C++, I know that there are structs in memory and can visualize what they look like - surely I can just go and tweak them? (No I can't because either it wasn't safe to do that anyway, or I need to explain to the Rust compiler why it is safe, and that can be quite difficult.)

Coming from something like Java, I (probably) don't think too much about what the underlying structure in memory is, so I'm less likely to try to do this.

Either way, it feels like part of the learning curve is learning the "Rustic" way to do something - in general, you probably shouldn't be reaching for "unsafe" until you know what you're doing! ;)

Re:The struggle with Rust by drbawb on Tuesday January 24, 2017 @10:59AM (#13472377)
>Either way, it feels like part of the learning curve is learning the "Rustic" way to do something - in general, you probably shouldn't be reaching for "unsafe" until you know what you're doing! ;)

I tend to agree with this sentiment. The moment I saw that OP was doing pointer arithmetic: I knew they were in for a bad time. It's not that you can't do it -- it's moreso that Rust's raison d'etre is to highlight the flaws inherent in that approach.

I hadn't thought about it, but I think you're right, my background in managed languages is probably why I didn't run into these sorts of issues until after I was already comfortable with Rust. I wasn't trying to make maximally storage-efficient collections right out of the gate, instead I was building application-level stuff on top of `std::collections`.

Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @11:27AM (#13472727)
In other words, you weren't using it as the systems language it's billed as. Which is fine, but it's claimed to be a systems level language, and if it's really that painful to do systems level things, then there's a problem somewhere.

Which is what's being discussed.

Re:The struggle with Rust by drbawb on Tuesday January 24, 2017 @12:07PM (#13473186)
>and if it's really that painful to do systems level things, then there's a problem somewhere.

To me it's not a problem at all, Rust is working exactly as designed. When you start writing code in the style that Ayende has: its memory layout becomes entirely non-obvious. The structure definition no longer lines up with how that memory is actually being used. You'll need documentation of the sentinels & invariants, you'll want diagrams of the memory layout (since it won't line up with the structure definition), and a careful understanding of every line of code packing the bytes -- that's just to get a basic understanding of what's actually going on.

This is fine, and you absolutely need to be able to do it, which is exactly why Rust provides `unsafe {}` (along with `std::ptr` and `std::mem`.) Sometimes you need that control you want a memory-efficient data structure, other times that's because you're reading registers directly off the hardware. In either case Rust is going to make you use `unsafe {}` which is a signal to say: "to understand how this is really laid out in memory you need to understand every single line in this block."

I would much rather be able to grep for `unsafe {}` and audit parts of a trie-map for memory safety, as opposed to auditing my entire program for memory safety violations. That's not a failing of Rust, it's functioning exactly as intended. Trying to squeeze every last byte out of a struct is neither obvious nor safe, it requires careful thought.

Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @02:42PM (#13474763)
> I would much rather be able to grep for `unsafe {}` and audit parts of a trie-map for memory safety, as opposed to auditing my entire program for memory safety violations.

you mean auditing the entire implementation of the trie data structure, not the entire program.

Guess what?

In rust, if you use unsafe, you also have to audit the implementation of the entire trie datastructure.

And if you think you don't, then I submit you don't understand Rust safety that well.

Re:The struggle with Rust by Manishearth on Tuesday January 24, 2017 @01:46PM (#13474237)
Rust contests the claim that you actually need to do pointer arithmetic and stuff often in systems languages. You need to do it a bit to implement your abstractions, maybe, but it is not the first tool you should need to reach for.

The code in the blog post looks very much like C-translated-to-rust. Right now, systems programming mostly does look like C/C++ because those are the only two mainstream languages that work here (D, too, but D is like C++. There are also other languages). But systems programming doesn't have to look the same or use the same primitives.

Do you really need to use malloc to allocate memory in a systems language? Do you really need to use pointer arithmetic to deal with things in a systems language? Sometimes, but not necessarily often. Even the Rust operating systems have managed to minimize the amount of unsafe/C-like code.

Rust does expose this functionality, but if it's not something it expects you to use often it makes sense that it might not always be straightforward to use.

Re:The struggle with Rust by pjmlp on Tuesday January 24, 2017 @02:18PM (#13474545)
> Do you really need to use malloc to allocate memory in a systems language? Do you really need to use pointer arithmetic to deal with things in a systems language?

To add to this point, my answer would be a big NO, if one would look to the C alternatives that sadly became niches.

Sadly the adoption of C has lead to younger generations thinking that those are the only valid paths in system languages.

Thankfully new languages, including Rust, are changing that.

Re:The struggle with Rust by AstralStorm on Tuesday January 24, 2017 @03:42PM (#13475274)
However, typed and separate memory areas with various allowed kinds of concurrent access are needed. Even simple RAM has multiple modes, plain, atomic of multiple kinds, barriers... On top of that, you get devices that handle access only with delay inbetween, can never be accessed concurrently (volatile), have alignment requirements and more. Rust memory model is too weak to enforce safety in such cases while not sacrificing performance.

It is written from "I have one CPU" side. Even C is far beyond that with things like OpenCL...

Re:The struggle with Rust by dbaupp on Tuesday January 24, 2017 @06:05PM (#13476641)
Rust gets all your favourite kinds of atomics and barriers, exactly like C. Other things are indeed hard to get safe, which is why Rust has `unsafe`: it is possible to use them, marking out the dangerous regions precisely, rather than the whole program being `unsafe` just because a few places need niche features.

In any case, Rust is definitely not written with "I have one CPU" in mind. A slogan that is sometimes used for Rust is "safe. fast. concurrent.", and it's one of the headline features on the front page: http://rust-lang.org/ . Rust's abstractions allows writing extremely high performance libraries like rayon, which, had better performance than even highly optimised C libraries like Cilk, in one benchmark I heard about. Building out that parallelism ecosystem takes time, so it does not seem particularly surprising that there are more (unsafe!) libraries for the 40-year-old language, than (safe!) libraries in the less-than-2-year-old one.

Re:The struggle with Rust by AstralStorm on Wednesday January 25, 2017 @03:20AM (#13479691)
No, by one CPU i meant not a single core. I meant not having to manage different memory models and available access patterns. Or different ways of handling race conditions and alignments.

You get to use unsafe almost exclusively in the internals of such access where it shouldn't be necessary if there are ways to specify more properties than just binary "safe" and "unsafe".

It is extremely hard to prove such code correct in Rust.

Re:The struggle with Rust by dbaupp on Wednesday January 25, 2017 @02:29PM (#13485069)
> I meant not having to manage different memory models and available access patterns

The only way I can make this make sense, is having cross-platform abstraction around atomic orderings etc. (like the new C++11 std::atomics) that works on x86 and ARM and PowerPC etc.

Rust has such a cross-platform abstraction, almost identical to C++11: https://doc.rust-lang.org/std/sync/atomic/index.html

Please be more specific about what exactly you mean if I am wrong.

Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @02:46PM (#13474791)
> Do you really need to use malloc to allocate memory in a systems language? Do you really need to use pointer arithmetic to deal with things in a systems language? Sometimes, but not necessarily often. Even the Rust operating systems have managed to minimize the amount of unsafe/C-like code.

If you're adding performance considerations I think the answer is going to be yes.

Re:The struggle with Rust by bryanlarsen on Tuesday January 24, 2017 @03:13PM (#13475024)
I'm not an expert, but I believe that Rust's performance will be better if you avoid unsafe pointers. Rust's abstractions are generally cost-free, but if you use unsafe pointers the compiler will have to avoid optimizations that could be broken by potential pointer aliasing.
Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @03:35PM (#13475222)
the idea of cost-free came from C++ where the belief is that you don't pay for what you don't use. The underlying meaning there is that you don't pay the cost of virtualized function calls if you're not using polymorphism (this is a big reason why C++ doesn't feature virtualized function calls by default).

polymorphism is of course an abstraction, the idea of cost-free is that you only pay for the abstractions you actually use.

This is not the same as maximizing performance.

The real question is whether or not you can do these things without giving the developer the control to maximize performance, and I think the answer is going to be no. The response will be that it's "good enough", but that's not actionable as we don't know what "good enough" means for any particular project.

Re:The struggle with Rust by Manishearth on Tuesday January 24, 2017 @04:03PM (#13475415)
> If you're adding performance considerations I think the answer is going to be yes.

You can build (or use, from the stdlib) safe abstractions over malloc that have the same performance. This should cover 99% of the use cases of malloc. For the few quirky cases where you still need malloc, you can still use it, but that means that the language doesn't need to make malloc-based memory management easy.

Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @05:36PM (#13476420)
I find that unfair. C++ has new as well as other mechanisms such as perfect forwarding into smart objects, but no one seems to think C++ qualifies for the "you can do systems programming without malloc and pointers"?

You can't do systems programming without them, what you can do is minimize their use by building abstractions, which other languages, such as C++ and D, already do.

So this idea that people somehow think you have to use the actual malloc call throughout your code is a bit of a strawman.

Re:The struggle with Rust by Manishearth on Tuesday January 24, 2017 @07:12PM (#13477132)
I do think that C++ qualifies for that. I don't think there is widespread use of this yet -- I'm talking about the vast majority of "systems" code in C or C++ -- most of it is older and doesn't tend to use abstractions, or has been written from a "C with goodies" perspective.

So yeah, (modern) C++ also contests this claim too. Rust contests a stronger claim about safety as well.

------

You're the one who said that "it's claimed to be a systems level language, and if it's really that painful to do systems level things," -- my point is that in both Rust and C++, "systems level things" don't need to involve pointer arithmetic and other similar things. They should be niche tools you reach for when the abstractions fail you, and the abstractions should not fail you that often. This is already true for both languages, I feel. It's not "niche" in C++ because the ecosystem needs time to evolve to that point, but for new code it probably works out.

Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @07:32PM (#13477256)
like I said, that's a strawman. C++ has had new/new[]/auto_ptr since C++ 98, so almost 20 years. The ideas of smart pointers have been around for a really long time as well.

Then there's the C constructor convention through opaque void pointers idiom.

This stuff is not new, not even close to new, NO ONE, not even the kernel developers, would make the argument that you cannot build abstractions around malloc.

If that's really what you're arguing, well you're not saying anything that C developers don't already practice.

Re:The struggle with Rust by Manishearth on Tuesday January 24, 2017 @07:54PM (#13477408)
When I say "malloc", I'm including `new` -- programming patterns that use new/delete are the same with malloc/free. new/delete doesn't really change the programming pattern, it just has a slightly nicer API.

smart pointers have been around for a while too. I see some codebases using them. But many don't.

> NO ONE, not even the kernel developers, would make the argument that you cannot build abstractions around malloc.

I never said that kernel devs or whatever would make that argument.

----------------

Look, you seem to think I've said something different than what I did here.

You said "if it's really that painful to do systems level things, then there's a problem somewhere.". I'm saying that Rust contests the claim that malloc/new/whatever must be easy to use for systems level things. Easy-to-use abstractions around them work well too. It's not that C++ doesn't have these abstractions, it does, and has for a while. My statement isn't one against C++.

My point is that the difficulty of using programming paradigms designed around malloc/new should not be a dealbreaker for a systems language, provided that the same tasks can be accomplished without raw allocation using a suitably generic abstraction. C certainly promotes malloc-based-paradigms. C++ has good alternatives, but a lot of the lower-level stuff I find avoids them because ultimately malloc/new aren't hard in C++. Rust makes them harder to use, but provides sufficient abstractions/abstraction-building-power that this should not be an impedance to systems programming. And, again, I'm not saying C++ doesn't -- I'm just saying that C++ also makes it easy to use malloc/new-based patterns, so you will continue to see those in systems programs even if they aren't necessary.

Now, interestingly, an abstraction for a vec-with-header doesn't actually seem to exist in the crate ecosystem, probably because folks don't like unconditional allocation. But it's relatively easy to build, might do it over the weekend.

(You can fake it in safe code using DSTs but it's not so great)

Re:The struggle with Rust by braveo on Tuesday January 24, 2017 @09:10PM (#13477816)
new/new[], delete/delete[] are abstractions around *alloc/free. That's not really under discussion, that's what they are. So when you talk about the ability to build abstractions around malloc, you're also talking about these operators in C++.

You may not like that they tend to be very thin abstractions, but they are abstractions, and the point is that the idea of building abstractions around malloc isn't new and certainly isn't unique.

You said:

>> You can build (or use, from the stdlib) safe abstractions over malloc that have the same performance.

While in defense of the statement:

>> Rust contests the claim that you actually need to do pointer arithmetic and stuff often in systems languages. You need to do it a bit to implement your abstractions, maybe, but it is not the first tool you should need to reach for.

This is presented as something unique to rust, which isn't even close to the accurate. This is why I called it a strawman. No one, not even kernel developers using C, are incapable of building abstractions around malloc to make it easier/safer to use.

The rest of what you say is inconsequential in my opinion. This isn't about C++, this is about your implication that building abstractions around malloc is something new or novel about Rust. It isn't. Not even the idea of safety around malloc is new, new[]/delete[] are themselves abstractions intended to make it less error prone to create/destroy contiguous blocks of memory.

That doesn't even get into the smart objects and RAII which have been around for a very very long time in C++.

None of this is new to Rust, and I think it's a bit disingenuous to imply that it is.

Re:The struggle with Rust by Manishearth on Tuesday January 24, 2017 @11:26PM (#13478511)
> So when you talk about the ability to build abstractions around malloc, you're also talking about these operators in C++.

Right, I wasn't talking about just that, I was specifically referring to abstractions that make you change your programming patterns. C++ has those too (the move-based abstractions), but I don't consider new/delete to be them.

My point was sort of "being able to write code that looks like this is not necessary for systems programming". Being able to do the task at hand is, but it need not be done using code like that.

> This is presented as something unique to rust, which isn't even close to the accurate.

Fair. It's not. I didn't intend to mean that. I'm sorry.

I was a C++ programmer for a quite a while, some of which time I used modern C++, so I'm quite aware that these abstractions are not unique to Rust.

The reason I phrased it that way is that C++ doesn't really make it harder to use direct-malloc-based (or raw-pointers-with-new) programming, and most of the lower-level C++ code I've seen (this is anecdotal) still uses this. So C++ doesn't contest the claim the same way Rust does (it does contest the claim though), since Rust codebases doing the same thing (even the kernels in Rust) tend to move strongly in the direction of avoiding unsafe pointer twiddling as much as it can. This is a bit more nuanced (and based on anecdotal evidence on low level codebases I've seen) than I really wrote in my original comment, and I apologize for that.

Re:The struggle with Rust by readittwice on Tuesday January 24, 2017 @10:56AM (#13472340)
I am not so sure about this, at least for Java for one simple reason: it is so easy to have back-pointers/cycles in your object graphs. In Java you don't even have to think about that. This was quite hard for me to figure out when starting with Rust.
Re:The struggle with Rust by bluejekyll on Tuesday January 24, 2017 @10:52AM (#13472302)
This really isn't that big a deal. I have written 60k lines of code in my side project, it's required zero lines of unsafe Rust code. I have needed to extend some other OSS libraries I depend on and those have required unsafe code for bindings to C, but that makes sense. Even in Java it's unsafe to write JNI to C.
Re:The struggle with Rust by eternalban on Tuesday January 24, 2017 @09:26AM (#13471506)
You came from interpreted Python to compiled OCaml and I suspect that your initial encounter with a compiler is the underlying issue. (For example, being new to FP but very friendly with compilers -- C, C++, Java, C# -- I found the initial OCaml encounter surprisingly pleasant. Haskell was something else though :))

I looked at Rust specs 1.0 when they were released and immediately recognized that Rust is not a 'dating' language, but rather a very serious 'marriage' till death do us part sort of deal. (I would say the same for Haskell, & Scala.) And imho the initial promise of addressing the out of control complexity of C++ was not met.

I have no doubt that Rust is a thoughtful, and powerful, language. But you have to be prepared to exchange vows at the alter.

Re:The struggle with Rust by throwaway91111 on Tuesday January 24, 2017 @10:41AM (#13472197)
Of all the things I'd accuse rust of, complex is not one of them. Could you give an example of the complexity? I've not found a single pattern in rust I wouldn't already have to think about in c++, but I have to think about it less because the compiler thinks about it for me. I just can't postpone the confidence until later.
Re:The struggle with Rust by eternalban on Tuesday January 24, 2017 @11:08AM (#13472469)
It was an impression, but clearly it is not a 'simple' language at the syntactic or semantic levels.

(You should not read my OP as a negative critique. I'm merely pointing out that anyone expecting 'immediate gratification' with Rust is likely to be disappointed.)

> the compiler thinks about it for me.

Indeed. One valid approach to categorizing programming languages is by considering upfront vs amortized cognitive load.

Re:The struggle with Rust by gcp on Tuesday January 24, 2017 @10:09AM (#13471868)
And imho the initial promise of addressing the out of control complexity of C++ was not met.

I'm not sure. Type traits seem to be much more manageable than how the same thing is handled in C++ template code, no?

Also, if we can bring in ecosystem effects such as cargo...

Re:The struggle with Rust by eternalban on Tuesday January 24, 2017 @11:09AM (#13472476)
I guess I should have added that I last touched C++ in '96 and never (ever) have had an urge to look back. :)
Re:The struggle with Rust by gcp on Wednesday January 25, 2017 @03:22AM (#13479706)
I've you've never seen template programming, but just C with classes, then yes, I can see how you arrive at this conclusion. C++ in 2017 is very different from what it was in 1996.
Re:The struggle with Rust by eternalban on Wednesday January 25, 2017 @05:55PM (#13487065)
I was using STL and RTTI. I know the language has substantially improved. These days I've actually rediscovered the joy of plain C.
Re:The struggle with Rust by tejinderss on Tuesday January 24, 2017 @07:56AM (#13470916)
Not related to the topic but how do you find ocaml as compared to python or rust? Do you think its worth learning today as opposed to rust for high level general purpose programming?
Re:The struggle with Rust by krat0sprakhar on Tuesday January 24, 2017 @09:15AM (#13471414)
Absolutely! If you're looking for fast, GC'd, native functional language I'd say OCaml is a great option. There's actually a very comprehensive set of blog posts migrating an open-source python based project to OCaml, that I'd recommend reading if you're looking for a more thorough comparison - http://roscidus.com/blog/blog/2014/06/06/python-to-ocaml-ret...

Personally, I used OCaml while at university to write a programming language (http://jsjs-lang.org) and totally loved it. Real world OCaml is a great resource and I'd definitely recommend giving OCaml a try. My only regret is that I don't get to write OCaml as much as I want to due to the kind of projects I work on, but given that Bucklescript[0] and Reason[1] are moving ahead in full steam, that might change shortly too :)

[0]- https://bloomberg.github.io/bucklescript/

[1] - https://facebook.github.io/reason/

Re:The struggle with Rust by njs12345 on Tuesday January 24, 2017 @08:04AM (#13470970)
It occupies a slightly different niche to Rust as it has a GC. If you can live with that, it's probably going to be more productive than Rust for you.

It's definitely worth playing around with a language from that family. OCaml is maybe slightly more practical than Haskell and it has some nice resources available - in particular Real World OCaml looks really good: https://realworldocaml.org/

Re:The struggle with Rust by lmm on Tuesday January 24, 2017 @09:05AM (#13471338)
It is well worth learning an ML-family language. In addition to Rust, OCaml or Haskell as njs12345 mentioned, F# or Scala might be options. OCaml is probably more mature than Rust, has more libraries available, and has automatic memory management which takes some of the load off you (especially if you're writing a GUI application, IME). But it's not got Rust's "hot right now" factor, it doesn't have Rust's ease of embedding in other languages, and it doesn't have quite the same focus on high-quality documentation.

If you already know Rust I wouldn't bother learning both - they're very similar languages.

Re:The struggle with Rust by nickpsecurity on Tuesday January 24, 2017 @12:04PM (#13473156)
I'll also add to their recommendations that GC'd languages can be used for OS's or system code. You can do that with a number of strategies:

1. Go unsafe on lowest-level operations that simply can't be GC'd. Quite a few of these can be expressed as finite, state machines which can be model-checked for correctness. Static analyzers are also really good these days in whatever code you can avoid dynamic allocation in. The rest of the code is GC'd. That's what the Oberon operating systems do.

2. Use a real-time, low-latency, concurrent GC that basically knocks low single or two digit performance out of the system. Lots of products in embedded Java have special GC's for that. Buy a faster CPU. Trade dollars or performance for productivity and safety.

3. Use a mix of GC's in the system where each one is tuned for the job at hand. You might use a real-time, concurrent one in the kernel. Maybe just reference counting in one more about performance. Maybe a straight-forward one for stuff that's not performance-critical. Could even use one that's mathematically verified for correctness in that situation. JX Operating System is an example of OS that mixes up GC strategies.

That's for software. Your options open up a bit if you can also deploy custom hardware. At the least, a modified soft-core on an FPGA. The LISP machines & maybe a Java CPU of the past often included hardware acceleration for garbage collection. One built the GC right into memory subsystem/interface of the processor where neither the processor nor applications had to be aware of its existence. It just did its thing in parallel to execution of the app. A concurrent, low-latency one integrated with virtual, memory hardware shouldn't take much hardware resources to pull off.

Re:The struggle with Rust by jackmott on Tuesday January 24, 2017 @09:23AM (#13471493)
It is worth looking at F# as well, which is basically OCaml on the .NET platform. With the advantages of having the entire .NET ecosystem of libraries available for use, being able to use more than one core of your cpu, a solid IDE, and some other features like type providers. There are some disadvantages as well, such as not being able to compile to a native executable.

Anyway the syntax is so similar you can learn one and switch to the other with very little pain.

Re:The struggle with Rust by pmoriarty on Tuesday January 24, 2017 @12:30PM (#13473452)
I never got past the pain-in-the-ass stage of dealing with the OCaml compiler. I hated wrestling with it for something simple. It really slowed me down to no end.

I remember asking on freenode's #ocaml for help with a convoluted error message, and when I was told what it meant and how to fix it, I asked how the person who helped me knew what it meant. He told me he'd taken two semesters of type theory courses at uni. Having to spend a year taking university-level courses in order to effectively program in OCaml seemed like way too much pain for too little gain when there were so many other less painful languages to program in.

Later I discovered Lisp and then Scheme. Both were a sheer joy to use compared to OCaml. I didn't have to wrestle with the type checker, my programs were quick and easy to write and understand, and in their own way the languages were just as powerful as OCaml was. Sure, OCaml had them beat at safety (at least if you were comparing ordinary Lisps and Schemes, not statically typed versions or extensions with more safety features) but it way, way more painful and slow to program in, for me. I recognize that if you need the safety, then the pain might be worth it. But even then it might be worthwhile to program in a dynamic language like Lisp/Scheme and then once the program matures, rewrite it in a safe language like OCaml. But even then, I think I'd just rather dial up the safety features of Lisp/Scheme or use one of the static versions.

That's just me. I know some people love OCaml. And I'm sure I'm missing some of its wonders that are only apparent when you dive deep enough in to the language. But from what I did learn of it, it just wasn't for me.

Re:The struggle with Rust by sfilargi on Tuesday January 24, 2017 @02:57PM (#13474886)
What helped me when starting with OCaml is always declaring the types in the function's arguments. The compiler errors started making a lot more sense.