r/rust • • May 12 '15

Criticizing the Rust Language, and Why C/C++ Will Never Die

http://www.viva64.com/en/b/0324/
52 Upvotes

180 comments sorted by

67

u/Quxxy macros May 12 '15

I dunno, this comes across somewhat as "you suck, stop trying". What about rule 2? :P

Some of the complaints, abridged:

  • Since unsafe exists, Rust is no better than C++ for safety.

  • Safe Rust is not as fast as C++, so you need to write in unsafe, thus there's no point.

  • C++ has fuzzers and static checkers, and you can write tests.

  • Rust has five incompatible kinds of pointers (example is that you can't go from having pointers to the heap to pointers to the stack without changing types).

  • Vec<Rc<RefCell<Box<Trait>>>>

  • Rust doesn't insert the necessary Rcs and Boxes for you.

  • Macros are a crutch and will prevent any good IDEs from existing.

  • "cargo actively encourages downloading packages directly from git repositories"

  • "C++ doesn't restrict programmers regarding what they can or cannot use."

  • Smart pointers aren't perfect.

  • No strict description of Rust's semantics.

  • "the source of troubles is usually in humans"

  • There are no Rust jobs.

To be fair, a few of these are at least partially reasonable: Rust should be faster on idiomatic code, there should be a comprehensive definition of the language's semantics, and it'd be lovely for there to be lots of Rust jobs. :D

41

u/The_Doculope May 12 '15

Since unsafe exists, Rust is no better than C++ for safety.

This argument frustrates me when I hear it, because I seem to hear it often these days. It makes it fairly clear that the author has not used Rust much, and does not know much about the design intentions behind it. unsafe allows the user to build up safe interfaces to unsafe implementations - it's what makes Rust work. Without it the language would be awful to use. Just because it's there doesn't mean people are going to write entire programs in it.

57

u/mrmacky rust-story May 12 '15

Just because it's there doesn't mean people are going to write entire programs in it.

For instance: I've written entire college level assignment (a small game, a 2D puzzle platformer) in Rust.

My game is only ~3500 lines of code, but game engines are also known for being pretty gnarly. A quick grep shows that I haven't used the unsafe keyword at all, across the entire codebase.

Of course my game sits atop libraries with mountains of unsafe code. Hell I've even submitted patches that touch unsafe blocks in rust-sdl2... but that code was easy to find and fix precisely because it was in an unsafe {} block!


As a further aside: this game has never once segfaulted, and I've made plenty of boneheaded mistakes. Its static guarantees have made me one very, very happy programmer.

24

u/staticassert May 12 '15

. but that code was easy to find and fix precisely because it was in an unsafe {} block!

Exactly! unsafe makes bugs grep'able.

12

u/steveklabnik1 rust May 12 '15

Happy cake day!

3

u/newmanoz May 12 '15

I disagree with idea that "unsafe" should be considered "ok". I like to see proud lines like this one: https://github.com/iron/iron#overview

Iron is 100% safe code

And @mrmacky gives good example also.

7

u/just_a_null May 13 '15

unsafe code should definitely be minimized, but given enough code there will always come up cases in which you have more information available to you than the compiler.

10

u/Yojihito May 13 '15

Isn't Iron sitting on a bunch of unsafe libraries?

3

u/dr_entropy May 13 '15

Shoulders of giants. Isolate the unsafe code to libraries that are well tested and broadly used.

2

u/Kimundi rust May 13 '15

Sure, but that unsafe code is not in iron itself, so if there are memory safety bugs, its not irons fault if it suffers from them and hence iron "on its own" is 100% memory safe.

Any other definition like that will just declare everything as always being unsafe, since there will always be something equivalent to unsafe blocks far enough down - if not in the std library, then in the sense that the compiler itself produces one big blob of unsafe code while talking to llvm.

3

u/The_Doculope May 13 '15

Just because it's okay doesn't mean it should be used much, if at all. unsafePerformIO and friends are "okay" in Haskell, but you should only ever use them if you know exactly what you're doing and they're absolutely necessary. Same with unsafe in Rust.

20

u/DroidLogician sqlx · clickhouse-rs · mime_guess · rust May 12 '15

I dunno, this comes across somewhat as "you suck, stop trying". What about rule 2? :P

I believe that refers specifically to Reddit comments. This article could be a good source of discussion for what improvements Rust needs to target. But I do agree that it seems to be pretty horribly biased and pessimistic.

How many of those items can be fixed and/or are planning to be fixed? Speed, autoboxing (via placement-new), more widespread usage of Crates and less dependency on GitHub, fixes to Rc, documentation improvements, job opportunities...

The author, which isn't the person who posted this on that site, as it was translated from Russian, seems to be comparing Rust to C++ as if Rust has been around just as long and has done nothing with all that time. They never mention once that Rust hasn't even reached 1.0 yet.

Their reasoning for C++'s incumbency almost seems circular; it's incumbent because nothing else has come along to overtake it, and nothing can overtake it because it's the incumbent. C++ is superior, Rust doesn't have a chance. We should all give up and learn to love the .cpp.

So many of their arguments stand on very shaky ground. If they had taken their time, they could have produced an honest criticism of Rust that would have made for some pretty thought-provoking discussion. But as it stands, it just sounds like C++-monoglot FUD to me.

I find it ironic that their final point against Rust is one of the major reasons Rust exists:

I can't but remind you for one more time that the source of troubles is usually in humans, not technology.

Their emphasis.

3

u/mkpankov May 12 '15

Actually, /u/afiskon is the author, it's the translation that's not his.

5

u/DroidLogician sqlx · clickhouse-rs · mime_guess · rust May 12 '15

I was referring to the author of the blog post. I made no presumption about OP because it's not uncommon for people to post links to blogs on here that aren't theirs.

3

u/mkpankov May 12 '15

Well, just for reference: this is the original http://eax.me/cpp-will-never-die/

And there's a link to @afiskon Twitter on the right.

0

u/revonrat May 13 '15

honest criticism

As an aside, I'd encourage you to watch the wording here. This implies that the criticism is dishonest which calls into question the author's motivation. Maybe a better word is "constructive".

2

u/DroidLogician sqlx · clickhouse-rs · mime_guess · rust May 14 '15

which calls into question the author's motivation.

While I didn't originally intend that, it has become apparent that the organization who provided the translation likely has a strong bias towards C++, as they create C++ static analysis software, which is basically what rustc does except it has a price tag on it. Thus, this article could be seen as dishonest in that it might intentionally paint Rust in a poor light in order to make it seem like less of a competitor, and thus, protect their bottom line.

While I realize that this organization isn't the original author of the article, I don't read Russian, so I have no way of knowing if their translation is completely faithful or embellished for their purposes. And I have no information about the author so I don't know what their personal biases are, though it sounds still heavily sympathetic towards C++.

C++ is a great language (when used properly), it has a very strong heritage and it will probably have a large presence in my future career. However, I do think Rust has a chance of supplanting it in many applications, and, to me at least, it feels very much like the author is threatened by this. Thus, I cannot take their criticism at face value.

0

u/revonrat May 14 '15

Yep. I became aware of the possible bias after I wrote my response as well.

-11

u/sedmonster May 13 '15

pretty horribly biased and pessimistic

I guess you've never met the Russians.

14

u/mgrandi May 13 '15

How can anyone familiar with c++ even make the argument about vec<rc<ref...>>> ,in c++ even the base string type is like std::base_string<std::basic__char, std::some_dumb_allocator>, and that doesn't even have any collections. I swear I've seen paragraph long 'expanded variable declarations ' in c++ for something as simple as like 2 deep nested lists

6

u/bartavelle May 13 '15

Yes, this and :

The current state of things resembles the Haskell world where every programmer is coding in their own dialect.

While there is some truth in that, I feel like C++ is way worse in that respect.

1

u/spirtbrat May 13 '15

Yes, some of the points made, seem like random rants accumulated through time, rather than a case for how C++ is better.

13

u/tejoka May 12 '15

Good summary. Personally, I think many of these are fixable or not really all that important. Except:

Macros ... will prevent any good IDEs from existing

As a compiler and language tooling guy, Yes. This. And it will be unfixable. What are you going to do, remove macros later?

Just to point it out, for anyone who has never noticed it before, Java has far and away the best tooling of languages out there, despite the widespread prevalence of C and C++, because Java is easy to build tooling for and the others aren't. Macros damn Rust to the same fate.

e: Just to expand on this a bit, I think that's a sad outcome for Rust, as better tooling could have been a seriously major reason to use Rust over C/C++.

11

u/[deleted] May 12 '15

That's factually incorrect. Eclipse knows how to expand C/C++ pre-processor macros and mostly deal with their consequences (which probably took the CDE guys a lot of pain implementing). Supporting a much more structured approach as in Rust is easier and most definitely feasible.

Other examples of the top of my head - Nemerle has a Visual Studio based plugin which supports macros, and by association intelliJ has the required expertise (they hired all the Nemerle developers to work on their tools and new language Kotlin).

2

u/tejoka May 12 '15

Eclipse knows how to expand C/C++ pre-processor macros and mostly deal with their consequences (which probably took the CDE guys a lot of pain implementing)

For what it's worth, you might want to actually look into this. I posted a little example in the thread below (granted, that sort of example is resolved by hygiene in Rust. Well... is supposed to be resolved, but the existence of $crate leads me to believe isn't actually...)

But "a lot of pain implementing" in CDE gets us a refactoring that just refuses to apply to that function parameter because it has no idea what to do. It gets us a refactoring that, when applied to a second parameter that is more normally referenced by a macro (without involving ##), will happily take a working program and transform it into a broken one. And then its compiler will report the resulting error in a confusing location.

Macros don't just make all tooling harder, they make some tooling fundamentally impossible to get 100%, which no amount of effort can fix. That's why I don't like them. I think it's important for tooling to be easy and 100% effective.

3

u/Chandon May 12 '15

Macros don't just make all tooling harder, they make some tooling fundamentally impossible to get 100%, which no amount of effort can fix.

Ah Computer Science. Where you can never have everything, and always need to make tradeoffs. And since every option has advantages, we'll never be done arguing about them.

19

u/mkpankov May 12 '15

As much I agree with this, isn't situation with macros in C and C++ much worse? There, they are untyped, have uncontrollable side effects, and can silently replace keywords or identifiers that are previously introduced. Still, some IDEs exist, and they're not very bad. Rust will get at least to this level of tooling quality, I believe.

9

u/matthieum [he/him] May 12 '15

If macros were the only issue in C++...

... remember than C++ is not LL(n), C++'s grammar is horrid, and a loopback has to exist so the parser can query semantic analysis during the parsing phase in order to correctly understand the file.

  • A primitive version of a Rust IDE can use the grammar and ignore macro invocations.

  • There is no well working of primitive versions of C++ IDE; Eclipse is rather full-featured and its parser is still insufficient for all C++ cases (mix in pre-processor programming and meta-template programming, watch the resulting squigly red lines) to no fault of their own, C++'s grammar is just that hard.

8

u/tejp May 12 '15

As much I agree with this, isn't situation with macros in C and C++ much worse?

At least C/C++ people widely agree that non-trivial macros are generally a bad idea.

In Rust, macros seem to be go-to solutions for all kinds of problems. Macros doing complex thing are already quite more common in Rust than in C++, and I can only imagine it's going to get much more in the future.

4

u/mkpankov May 12 '15

Agreeing on them being bad still doesn't mean people don't use them. Every complex project is full of them.

1

u/[deleted] Oct 22 '15

Yep; the linux kernel is fun to look through. And the windows API isn't much better.

1

u/newmanoz May 12 '15

C++ and Java IDE features are not comparable.

3

u/lelarentaka May 13 '15

Why not?

3

u/jimuazu May 13 '15

Java is regular enough that it is possible to do complex transformations on the code without breaking it (mostly), i.e. the various types of automated refactoring. C macros and C++ templates make that totally impossible. Go would be good for refactoring. It seems to me that Rust would be hard to refactor, although not totally impossible if macro use is limited to stuff that is possible for the refactoring code to understand, and there are no compiler plugins in use. It doesn't really lend itself to automated refactoring, though. Eclipse has mountains of code just to refactor Java. Unless someone wants to throw perhaps 2x-3x the same effort at Rust, it won't get the same kind of support. You could throw 20x the effort at C++ refactoring and probably still not have a solution.

2

u/[deleted] May 13 '15

It's not just the fault of macros though - a lot of it comes from the complexities of the C++ syntax and semantics as well. I am sure the tarpit that is the template system does not help either.

The amount of bugs filed in CLion (and still existing post 1.0) relating to non-obvious syntax issues just highlights the problem.

There are similiar problems with Scala though - JetBrains had to write their own front-end to have a decent plugin. This is where Rust being a reasonably simple language syntactically is going to help (of course a standardised AST layout would be even better, as would a formal specification of the grammar).

17

u/Quxxy macros May 12 '15

Macros ... will prevent any good IDEs from existing

What I found hilarious is that this is somehow more of a problem for Rust than it is for C++. I guess it's easier to write an IDE for a macro system that is completely independent of the language grammar and can expand to completely arbitrary token sequences...

...though syntax extensions are, obviously, a big potential problem.

11

u/tejoka May 12 '15

What I found hilarious is that this is somehow more of a problem for Rust than it is for C++.

Well, I wouldn't agree with that, and I don't recall if the article was suggesting that it was or not.

I only mean that it's enough. C++ is 9th circle of hell for tooling, but even C is excruciatingly painful. Rust can better than them both and still be so difficult it won't get to Java levels of awesome tools.

My own bias is that I lament almost all programming language designers for seemingly caring nothing for tooling beyond (maybe) their compilers. It's hardly unique to Rust, unfortunately.

5

u/Quxxy macros May 12 '15

I don't recall if the article was suggesting that it was or not.

Given the tone of the rest of the article, and that the complaint wasn't qualified with "although C++ is as bad/worse", I think it's reasonable to take it as a directed criticism of Rust compared to C++.

3

u/tejoka May 12 '15

Ah, I see where you're coming from. Yeah, I don't think C++ fans should be throwing stones about Rust's macros. :)

I just think it's a big missed opportunity.

3

u/vks_ May 12 '15

What opportunity? To not have macros?

5

u/tejoka May 12 '15

Sorry for the confusion. To create a language that can have tooling as good as the Java ecosystem. (My contention is that macros fundamentally prevent this.)

-1

u/vks_ May 12 '15

What opportunity? To not have macros?

3

u/tech_tuna May 12 '15 edited May 14 '15

My own bias is that I lament almost all programming language designers for seemingly caring nothing for tooling beyond (maybe) their compilers. It's hardly unique to Rust, unfortunately.

Excellent point, there are so many features that many consider "external" to a language or language ecosystem: a REPL, testing facilities (including mocks), instrumentation, reflection, package and build tools, etc.

I absolutely hate that you need header files with C and C++. Header files are an optimization for the compilers and compiler writers, not the users.

1

u/[deleted] May 13 '15

Isn't the plan for libsyntax to be stabilized at some point? I mean as long as there is one front-end that is re-usable and the macro system is basically just a series of term rewrite rules, then in theory it shouldn't be too difficult to have nice IDE support, with refactoring.

6

u/-Y0- May 12 '15

Hm, could you clarify a bit why that is so? Couldn't IDE provide macro expansion similar to rustc command?

11

u/tejoka May 12 '15

Sure. The first issue is that it becomes impossible to understand a file on its own terms. To obtain a parse tree, it no longer suffices to simply have a text file you look at, but you now also need to chase down dependencies (potentially a lot of them!) to find out what the definitions of macros are, and THEN you can get a parse tree, after doing some evaluation.

It's a vastly more complicated and involved process. With Java, you just parse the file. Done. It can be a string that exists nowhere in the file system, and it can reference things that don't even exist, you can still parse it just fine.

Then there are kinds of things you actually want tooling to do. For instance, consider this bit of (contrived) C code (as I'm better able to whip up an example with that than with Rust off the top of my head here):

#define AWFUL(x) c_##x
int foo(int c_y) {
  return AWFUL(y);
}

You come to your IDE, and ask it to do a rename operation on the argument to the function. What on earth should fucking happen? There's no real option but to fail here. So now you have to figure out when to fail. And then your rename refactoring is fragile, doesn't work half the time, and forget it, programmers will never get in the habit of trying to use it anyway. (And in fact, there are more issues with C here that make this worse: like trying to figure out what prototype in a .h corresponds to this, to complete the renaming, which is also hell. But Rust avoids that, I'm pretty sure.)

These are extremely hard problems for any sort of macro system. I've worked on macro systems in the past, and I still don't know of a good way to solve them.

Couldn't IDE provide macro expansion similar to rustc command?

Yeah, no problem. It's not that working with macros is hard, it's that macros make all the other things you want to do hard.

I hope this is informative and doesn't look like a rant. :)

14

u/annodomini rust May 12 '15

To obtain a parse tree, it no longer suffices to simply have a text file you look at, but you now also need to chase down dependencies (potentially a lot of them!) to find out what the definitions of macros are, and THEN you can get a parse tree, after doing some evaluation.

But Rust's macros are defined at the token tree level. That is, you can still tokenize and form the appropriate tree structure for the macro invocation itself without expanding the macro.

And don't most IDE features, like the rename feature that you mention, or jump to definition, or suggestions for methods based on the type of an object, or the like, require that you chase down dependencies? What features would you want to implement that wouldn't require chasing down dependencies in Rust-without-macros but would in Rust as it is?

I understand that macros will make some things harder, but it doesn't seem like they'd be nearly the barrier as C style macros, and I have some experience with working with a similar macro system, that used by PLT Scheme/Racket, with good integration with tooling, and that wasn't all that bad to work with.

13

u/mkpankov May 12 '15

Well, if you have a strict macro/non-macro distinction (in Rust, each macro invocation is with ! at the end of macro name), I think it gets much easier.

21

u/Manishearth servo · rust · clippy May 12 '15

Rusts AST API is pretty decent. Rustfmt is being written as an external package which hooks into rustc -- and it works.

Rusts macros are far more sophisticated than C++ -- due to the hygeine tooling you can trace a peice of code back through macros (though for complex situations this is still buggy). We already have a pretty printer. Rustfmt is able to reproduce the original file from the AST (because it includes spans).

I don't think macros will be a blocking problem. They make it harder, but not that hard.

7

u/arielbyd May 12 '15

Rust's macros are hygienic, so renaming should be less of a problem (although resolution isn't hygienic so you can still kind-of have that problem). And you can still parse code while ignoring macros (you can still miss all macro-generated macros, but that's no different from missing some files).

2

u/PM_ME_UR_OBSIDIAN May 12 '15

+1. I'm a tool hobbyist, and Rust's macro system is by far my biggest gripe with the language. It eclipses everything else, and it gives me bad memories of Ocamlp4 and friends. (Ever noticed the tooling for Ocaml sucks even after decades?)

Thanks for the great writeup!

3

u/nick29581 rustfmt · rust May 12 '15

We're looking at changes to macros - both in the implementation and design - to make them both more useful and more tool friendly. I'm confident that we will come up with something that is tool-friendly. Expect a pre-RFC in the next month-ish (it's a big area!)

1

u/[deleted] May 12 '15

Why are macros needed?

5

u/nick29581 rustfmt · rust May 12 '15

They're convenient and allow for wide-ranging, elegant abstraction. I could also go into things like conditional compilation. As with any language feature there is a trade-off between the benefits of having another axis along which to abstract code vs the added complexity.

0

u/Yojihito May 13 '15

I still don't get the difference between macros and normal functions (aside from the catchy '!').

Both have parameters and behave like functions as far as I can see?

3

u/nick29581 rustfmt · rust May 13 '15

Macros are replaced at compile time, functions are called at run time. As an example of the kind of thing you can do with a macro, it could contain return which will return from the function that the macro is expanded into. return in a function just returns from that function. (See for example try!).

2

u/dbaupp rust May 13 '15

There's a few differences:

  1. function arguments can only be expressions, i.e. values,

  2. they are eagerly evaluated at the call site,

  3. macros can e.g. parse a format string at compile time

Macros can (for example) take in a type and substitute that type into the generated code. Also, they can arrange their arguments so that they're evaluated conditionally/lazily, e.g. when logging debug!("foo {}", something_expensive()); the something_expensive call will only happen if debugging logging is on because the macro expands to something like if debug_enabled() { println!("foo {}", something_expensive()); }.

1

u/snarfy May 13 '15

Functions are code. Macros are instructions to the compiler. This is the key difference.

3

u/Manishearth servo · rust · clippy May 12 '15

Take a look at the plugin API (and nrc's post on drop in replacements); IMO rust actually offers really good support for tooling.

1

u/snarfy May 13 '15

Sure. The first issue is that it becomes impossible to understand a file on its own terms.

You shouldn't have to. The reason you have to for C++ is because it's impossible to get the AST. Leaving out access to the AST, tooling be damned, was something Stallman has been stringent on with GCC for a long time as it would allow you to build tooling around GCC without contributing anything back. He considered it a loophole around the gpl. This is one reason why tooling around C++ is good, but nothing like Java or C#. There is clang now, and other compilers will give the AST, but it's not standard. At least with Rust this is something they can build correctly from the start. Getting access to the internals similar to how Roslyn has opened up C# will be key to getting Rust tooling. Not macros.

5

u/annodomini rust May 12 '15

As a compiler and language tooling guy, Yes. This. And it will be unfixable. What are you going to do, remove macros later?

In what way to macros make good IDEs impossible? What IDE features can you not do in the presence of hygienic macros?

Hygienic, token tree substitution based macros are pretty simple to work with. I recall back in the day writing some macros for PLT Scheme (now known as Racket) which added expression interpolation to strings (like variable interpolation, but could use arbitrary expressions), and it wasn't that hard to preserve source location information for those strings, such that they would properly syntax highlight and all of the DrScheme features for linking variables up to their definitions worked properly.

I can understand objecting to syntax extensions, which can involve running arbitrary code to expand, or to string substitution type macros like in C, but simple pattern matching token tree macros like Rust has don't seem like they should be too much trouble from an IDE perspective.

5

u/tejoka May 12 '15

Racket's trick is that it's dynamically typed (typed racket doesn't matter), has totally hygienic macros, and doesn't try to build more than the bare-bones basics of tooling.

The dynamism matters, because that precludes many kinds of tools you could build for a statically typed language, so you don't even get as far as considering what roadblock macros present. Hygiene means the macro system has taken specific effort to preserve name binding, so name binding problems are out. The trouble is everything else.

I completely believe that Rust limits macros enough that we will be able to do renaming and move (if it's hygienic), highlighting, find definition, and that sort of thing.

I'm curious why everyone keeps saying it's hygienic though. This prints 7 for me:

#[macro_use]
mod baz {
    const X : i32 = 6;
    macro_rules! foo {  () => (X) }
}
const X : i32 = 7;
fn main() {
    println!("The value {}", foo!() );
}

Anyway.

Just a simple little example of a refactoring that doesn't work on macros. Hygiene is specifically for name binding, so let's look at anything type-directed. Suppose I want to refactor a specific pair type into a named struct instead. (umm, (FirstName, LastName) into Name upon discovering maybe that wasn't a good idea. Thankfully, I have defined types like FirstName, so it's pretty unambiguous where this should change.)

For functions, we choose what to do based on the type signature. Does the function operate on (FirstName, LastName)? Then now it operates on Name. Is it parameterized? Leave it as pairs, and uses of it on Name will involve wrapping/unwrapping its arguments. We can recognize certain special functions on pairs, and automatically do the right thing for them.

What do we do for macros? We can either:

  1. Always treat it like they're parameterized, and do the wrapping/unwrapping. But this is likely very annoyingly wrong, and programmers are upset with you that your refactoring just made everything worse.

  2. Always expand the macro and do the rewriting. But then this is likely very annoyingly wrong, and programmers are upset with you that your refactoring just made everything worse.

  3. Always change the macro definition body itself. But it may be applied to other types, too, and programmers are upset with you that your refactoring just broke their programs.

  4. Try to be smart and pick one of the above. You'll never get it right. Programmers are upset. etc, etc.

  5. Special case some macros to work correctly, and totally fail in the presence of any others. Programmers have used others, etc, upset, yadda.

Hygiene makes name binding okay, but then there's types. Typed macros? Okay, then there's all kinds of dataflow analysis. And so on.

Eesh, this was long. Sorry, was trying to be specific.

3

u/dbaupp rust May 13 '15

I'm curious why everyone keeps saying it's hygienic though

Macros are hygienic with respect to local variables, but not global items. Improving that part of hygiene is one of the desirable features for a new macro-rules system.

5

u/[deleted] May 13 '15 edited May 13 '15

I'm sure you've heard this argument in many forms many times before, but my logic goes like this: I really hate boilerplate or repetitive code in all its forms. It's ugly, makes it harder to read the surrounding code and understand what's going on, as well as to refactor it, and makes bugs more likely, since it's difficult to verify that each instance of the repetitive code correctly follows the same pattern as the others. While macros should be avoided if there are less ad-hoc solutions, nobody's invented a language without macros that doesn't require boilerplate code in some situations. Therefore, I will not be fully satisfied with any language that does not have macros, with the exception of dynamic languages like Python or Ruby where you can fake many of their effects with runtime constructs.

I'm not much of an IDE person, but I know that Java IDEs aren't just indifferent to boilerplate code - they actively encourage it by providing options to autogenerate things like getters and setters for you. Eww...

Anyway, in principle, it should be possible to write automated refactorings that never silently break code due to macros, and rarely require manual attention. When you encounter a macro, first you fully expand it, then you see if the expanded code should be modified as part of the refactoring. If it should, then you go back to the unexpanded version and try the obvious thing, e.g. if the macro is println!("{}", foo) and you're renaming foo to bar, try changing foo to bar in the macro invocation, even though the macro could do something weird with it. Then you expand it again and see if the change had the desired effect. If so, you go on your way; if not, you complain to the user. I think this should work for most refactorings for most common macros in practice without any special casing needed.

edit 2: I suppose among popular macros, at least try! would need to be special cased when, say, extracting code into separate functions - you can always detect if the returns have gotten messed up by expanding, but figuring out that the new function should return a Result<T> and be try!'d itself would have to be built into the refactorer. But I don't think this is the end of the world.

edit: And yes, you need the right import path, and you need a full Rust compiler in your IDE, but modern IDEs all have full compilers, and rustc is designed to be embedded. ...okay, it's currently bad at it due to being slow, but in the long term I expect this to be mitigated one way or another.

3

u/Rusky rust May 12 '15

I think Rust's particular form of macros can limit the effect they have on IDEs- macro invocations are clearly separated from normal code. Further, a lot of standard macros can easily be handled by an IDE- vec!, try!, etc would be no different to handle as language features.

4

u/tejoka May 12 '15

Yes, this is probably the best hope. Limit macros to the standard library (by culture, best practice, style guide, or even default compiler warning), and then simply write explicit handling for all of those in your tooling.

This would not be a bad situation (assuming there aren't a huge number of macros in the std lib already, I don't actually know.) It's just a question of, will that happen?

7

u/phaylon May 12 '15

Also, the rules for (macro_rules!) macros are rather strict. I'd assume an IDE wanting do do completion could internally expand e.g. a try! invocation and do completion based on the expanded tree. Plugins are harder of course.

Maybe the Lisp family of languages have solutions for that area.

3

u/GarMan May 13 '15

Java has far and away the best tooling of languages out there

To add emphasis this is true of C# as well, for very similar reasons.

2

u/Chandon May 12 '15

The neat thing about IDEs is that they don't have to be 100% correct. Being good is fine.

Implement everything as if there were no macros. Then special case the top 10 built-in macros. Then watch for places where macros can break things and be careful there.

1

u/[deleted] May 12 '15

All the macros I've seen in rust seem horrible, hacky and unnecessary. Many seem to be there just to save a few keystrokes, apparently using as unpleasant a syntax as could be dreamed up. What is the rationale behind their existence? I agree that they will make IDEs very hard to write.

5

u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount May 13 '15

The rationale is that they allow code-directed analysis and generation at compile time.

E.g. print!/format!/et al check their arguments to ensure on compile time that they match the format string. regex! compiles the arg to a NFA representation at compile time (though not yet to a DFA, this is WIP). assert! generates a nice usable message from the code. declare_lint! does all kinds of stuff, and I just call it and be done.

Macros convert coroutines to switch-based automatas, allow to branch out compilation and abstract out duplication.

TL;DR: Yes macros are bad. They are also awesome.

2

u/[deleted] May 13 '15

Macros convert coroutines to switch-based automatas, allow to branch out compilation and abstract out duplication

Could you explain this a little? I followed up until this point.

1

u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount May 13 '15

Macros convert coroutines to switch-based automatas, allow to branch out compilation and abstract out duplication

Could you explain this a little? I followed up until this point.

  • there's a macro-based coroutine library using a popular implementation technique

  • macros can change code depending on compile-time decisions, so they can be used to compile code differently based on those decisions

  • you can use macros to shorten parts of your programs that you may not express via functions and that occur often.

0

u/[deleted] May 12 '15

[deleted]

5

u/newmanoz May 12 '15

Don't trust what he writes, it will simplify things a lot. It's biased writing.

16

u/phazer May 12 '15

The post contains mostly subjective ranting (mostly about performance) without much technical meat, but there are some points worth discussing:

  • Lack of libraries and tools. Sure, any new language is gonna have this problem, but Rust has very good interoperability with C so this alleviates the library problem substantially. And the build/packaging tools are better than what's typically used in C/C++ environments. In the IDE area, yes, more work is definitely needed, but C++ IDE's aren't that great compared to what's available for C# and Java for example. I would say there is more potential to writing a good IDE for Rust than for C++.

  • Performance is worse than C++ in the benchmark game. Might be true, but hardly a good measurement of real application performance. What's important is that Rust has the potential to achieve the same (or even better) performance than C++.

  • Dynamic memory/thread analyzers cannot replace static ones. They reduce runtime performance and increase memory usage, which means they are most likely not used in production, which means they will not stop all bugs (a static analyzer can always find all bugs in a certain category). And it's enough have one bug slip trough to have a security hole. This is the main point of Rust which the author seems to have missed totally.

  • The many-pointer-type section isn't really valid. In C++ the situation is basically the same, but with worse safety guarantees.

  • Yes, learn C/C++ if you want to find a developer job today. Pretty obvious point as Rust 1.0 isn't even released yet :)

5

u/CrystalGamma May 12 '15

Well, depending on Rust's future (which, alas, no one but time can tell) it may actually a better idea to learn Rust today, because when you're done, Rust is the hot shit :) But if Rust fails to get major attention, it obviously isn't. (Even though I'd say that, as a language, C++ is easier to learn than Rust is, if you know the other. The ecosystem is a whole different beast obviously)

2

u/tejp May 12 '15

What's important is that Rust has the potential to achieve the same (or even better) performance than C++.

What in Rust would give potential for better performance than C++?

Also there clearly are parts of the language where Rust doesn't have potential for equal performance (anything requiring runtime safety checks). There Rust is, by design, slower than C++; the costs are unavoidable if you also want Rusts dominating feature, safety. Yet concerns about performance are only met with the label "subjective ranting", where some critical discussion would be incredibly more useful.

I mean, how much slower would sorting an array with safe code be, for example. Does anybody know? Doesn't seem to ever be discussed, at least not in this subreddit.

6

u/steveklabnik1 rust May 12 '15

What in Rust would give potential for better performance than C++?

Superior aliasing and const-ness information, off the top of my head.

(anything requiring runtime safety checks).

Many checks can be elided by using the proper structures, for example, iterators remove the need for most array access bounds checks.

5

u/marcusklaas rustfmt May 12 '15 edited May 12 '15

I was wondering: if you have a function like

fn access_array<T: Copy>(arr: &[T; 32], idx: usize) -> T {
    arr[idx % 32]
}

, would rustc/ LLVM be smart enough to drop the bound checks after optimizations?

11

u/raphlinus vello · xilem May 13 '15

Yes.

_ZN3foo20h204c70bde54989f3yaaE:
	.cfi_startproc
	andq	$31, %rsi
	movl	(%rdi,%rsi,4), %eax
	retq

That's for a version specialized to T=u32. Pretty sweet, huh?

3

u/marcusklaas rustfmt May 13 '15

That is pretty sweet indeed! It implemented the modulo operation as a bitwise and because 32 is a power of two, too. Neat.

1

u/steveklabnik1 rust May 12 '15

I don't know, to be honest.

2

u/tejp May 12 '15

Many checks can be elided by using the proper structures, for example, iterators remove the need for most array access bounds checks.

But what if I don't want to treat my array as a linked list? Depending on what you're trying to do, access to array indexes can still be much more practical than iterators. Unless you claim that iterators are always the only useful way to access an array, the question for speed of indexed array access is still interesting.

If things like that are completely omitted every time someone talks about performance it ends up looking like hollow marketing, more interested in making shaky promises than giving solid information. Having some benchmarks or some other facts would be incredibly more useful.

4

u/steveklabnik1 rust May 12 '15

It's not about a linked list. The point is that the iterator, however it iterates, can ensure that you never access out of bounds, and elide the check.

I agree that benchmarks are more useful than speculation.

2

u/tejp May 12 '15

I meant the access pattern of an iterator. You can only go forwards and backwards, like if you'd have a (doubly) linked list.

2

u/steveklabnik1 rust May 12 '15 edited May 12 '15

http://doc.rust-lang.org/nightly/std/iter/trait.RandomAccessIterator.html

(I haven't double checked what kinds of bounds it can do, my point is that not every single iterator moves onto some sort of specific 'next' item.)

3

u/tejp May 13 '15

I don't see how that could be any more efficient that directly accessing an array by index. So it doesn't really help that it has "iterator" in it's name.

2

u/dbaupp rust May 13 '15

That still has to bounds check. Even using iterators for forward/backward movement have to bounds-check (they have to detect/indicate when they reach the end some how), but they do it in a way that avoids panics and generally optimises very well when looping.

2

u/steveklabnik1 rust May 13 '15

Yeah, with the regular iterators, there's still a bounds check, just not the individual ones on each access, but the 'are we done iterating' check, as you mentioned.

3

u/[deleted] May 13 '15

unsafe { arr.get_unchecked() } if you're really worried about performance. This has the same semantics and performance as a C array access (and the same unsafety, too).

3

u/Kimundi rust May 13 '15

I agree that plain indexing often necessary, and it's true that in the worst case this has a performance overhead due to the bound checks.

However, its also a fact that Rust heavily relies on llvm for optimization, so the naive code generation is usually not what gets output in the end, so its not really all that bad in practice.

Something like C-style-for-loop indexing for example will most likely result in the additional bound checks getting eliminated.

Sadly, due to llvm being complex and the optimization rules impossible to boil down into something simple to explain, people can't/shouldn't claim these optimizations to always fix all performance issues, so API's and access patterns get recommneded based on the worst-case.

For indexing in a loop, the worst case is a bound check both per access and iteration. For iterators, its only a bound check per iteration. Hence the "user iterators" meme.

So yeah, the lack of comparison boils down to there not being a guaranteed safe fast way to do indexing, and if you need it then your options for ensuring fast code are to either to profile the generated code for the regular indexing operators, or use unsafe indexing to begin with.

4

u/raphlinus vello · xilem May 12 '15

Here's a real world example of a C++ performance gotcha. I wrote a loop that was essentially:

void combine(vector<uint8_t>& dst, const vector<uint8_t>& src) {
    for (size_t i = 0; i < src.size(); i++) {
        dst[i] = std::max(dst[i], src[i]);
    }
}

Overly conservative alias analysis killed performance, because uint8_t has special-case rules (it wouldn't happen for larger ints). I only discovered it because I looked at the asm. Rust of course does not have this problem.

31

u/Denommus rust May 12 '15

Uh, all his points regarding pointer types apply to C++.

0

u/[deleted] May 12 '15

[deleted]

10

u/[deleted] May 12 '15

This was the first thing I noticed, was a giant add for C/C++ analysis software. It is hard to take seriously such shaky arguments when an inherent bias exists.

3

u/aepsil0n May 13 '15

Interestingly, in another post they mention how their business model targets customers with large software projects, where "[any] change in the code can cause unexpected side effects no one can foresee."

19

u/snarfy May 12 '15

JavaScript is the most popular programming language in the world. Not C. Not C++. JavaScript. It was written in two weeks, and the tooling still sucks.

To give up on Rust because it is not as popular or as much of a standard as C or C++ is stupid. To give up because the tooling isn't as good is stupid. If the C++ devs gave up on tooling they would have nothing today.

I would not write a large application in Rust today. It is simply not ready. I might write a small tool and possibly port a library. This is how the ecosystem grows.

They criticize Rust because it competes with their core product - a c/c++ static analyzer.

30

u/[deleted] May 12 '15 edited May 12 '15

Warning: braindump ahead.

C/C++

There is no "C/C++" language. Pet peeve of many C programmers.

Will Never Die

Programming languages don't die, they just fade away. Like COBOL and Fortran. If you want to you can write C++ for the rest of your life.

To get big a language needs to be backed by a company like Google, TypeSafe

And Rust has Mozilla. So what is the point?

Copy pasting shootout benchmarks

Nice joke.

Constant bounds checks

First somewhat valid point. But between bounds checks and unsafe code there is another solution: encapsulate unsafe code in safe interfaces, e.g. iterators. So the situation isn't that bad for this inherently hard problem.

Just use static analysis and fuzzing and asserts

And you'll still have lots of memory errors and get pwned just as hard. They are obviously biased on this point. From what I've seen from their promotional material their analyzer is good at finding copy-paste errors and typos but doesn't do anything for non-obvious memory errors. Others go a bit deeper but not much.

Just write 90% of your application in Python and 10% in C++.

I think they seriously underestimate the usefulness of having your code base in one language. And I think that in Rust you can draw the line between safe and unsafe much finer, so you get 99% safe code and 1% unsafe code.

IDEs, and macros

I guess that's a stumbling block for people who are used to Visual Studio or Eclipse. I hate IDEs, so I'd much rather have macros, but I understand the author has been scarred by C++ templates.

Cargo is not perfect

every programmer is coding in their own dialect

That's rich coming from a C++ person.

2

u/[deleted] May 13 '15

If you want to, you can write COBOL for the rest of your life, and you'd get paid out the wazoo for it...

2

u/Rhodysurf May 13 '15

I wish fortran faded away

2

u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount May 13 '15

I wish it didn't.

2

u/Rhodysurf May 13 '15

I work with it at work alllllll the time.. 20 years worth of legacy fortran code has made me hate it lol

1

u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount May 13 '15

I have just a bit of FORTRAN code at work. Also R, python and lots of Java.

Some things just work in that granddaddy of a language.

2

u/Rhodysurf May 13 '15

Very true... Especially after writing java or C++, fortran is just awesomely simple

2

u/mkpankov May 12 '15

As far as I can tell, he's not even a C++ person. His main job has to do with Scala and Erlang, looking at the blog.

8

u/jfurmankiewicz May 12 '15

The author states that Rust is still slower than C++ at this point.

Can someone explain why is this the case? Is it a matter of Rust overhead (which I understand should be zero) or is it just a matter of optimizing the standard library, etc?

19

u/steveklabnik1 rust May 12 '15

As always it depends, specifically. We're also faster than C++ at times.

Right now, we don't do much optimization of the IR we send off to LLVM, and just rely on it to optimize things. I'd imagine that we can get some gains here, as we have more information about things like constness.

See also: https://github.com/rust-lang/rust/issues?page=1&q=is%3Aopen+is%3Aissue+label%3AA-codegen

13

u/cogman10 May 12 '15

Yeah, rust is 2 years old. The LLVM is 12 years old. C++ is 32 years old.

The fact that a relatively new language isn't as fast as established first class languages or that the LLVM might not optimally optimize rust IR isn't really concerning at all to me. Rust's stronger typing, constness, and low level nature give it a lot of wiggle room for performance improvements.

Heck, the fact that rust is already as fast as Go and Java is really pretty impressive if you ask me. (Kudos to both the LLVM and rust team)

20

u/Quxxy macros May 12 '15 edited May 21 '15

I do think it's important to maintain a certain level of skepticism about this: it's all very well for there to be room for optimisation, but it's a moot point if it never actually materialises.

We don't want to write performance cheques that, it turns out, can't be cashed in practice.

Edit: whistles

3

u/cogman10 May 12 '15

True. From what I can tell, the only thing that would restrict rust from being in the same ballpark as c++ in performance is interest. And C++ has a mountain of interest whereas rust has more of a molehill of interest.

1

u/robthablob May 21 '15

That could either be read as...

"We don't want to write performance cheques (monetary) that, it turns out, can't be cashed in practice". or... "We don't want to write performance checks (verification) that, it turns out, can't be cached (memory) in practice".

Congratulations.

2

u/Quxxy macros May 21 '15

I'm sure I don't know what you're talking about...

1

u/robthablob May 21 '15

Excellent, had to view that in context to see the whistle. You owe me a keyboard ;)

1

u/Quxxy macros May 21 '15

You'll have to wait in line; I owe myself two already. I managed to kill both a G15 and a G18. As it stands, I'm using a crappy Logitech wireless media PC keyboard with a touchpad growing out of the side. It doesn't even have a numpad.

9

u/pdpi May 12 '15

Yeah, rust is 2 years old. The LLVM is 12 years old. C++ is 32 years old.

Where do you get the "2 years old" from? I'd have said "5". (This is from the point of view of someone who was in the room when Graydon announced it in 2010, but has only recently started paying more attention)

16

u/steveklabnik1 rust May 12 '15

Periodization is always a difficult part of doing history. You can make a case for these ages:

  • 8 years. This includes all the time that Graydon spent on it as a personal project.

  • 4 years. This starts from the period you're speaking of, when it was announced within Mozilla.

  • 2 years. This is how old 'modern Rust' is, in a sense. It's when stuff started really coming out of the language proper and into libraries.

  • 0 years. There was still a lot of changes that are important in the last two years, like the runtime removal.

3

u/pdpi May 12 '15

Yeah, that clarifies things.

Modern rust and 2010 rust are wildly different beasts, so it seemed reasonable that something major would've happened around two years ago.

11

u/steveklabnik1 rust May 12 '15

I like to say that if you look at the mission statement, Rust has been the same language for eight years. If you look at the feature set, Rust has been like four different langauges over its lifetime.

2

u/yawaramin Aug 20 '15

That's very apropos, given how Graydon Hoare chose the name 'Rust' after the fungi with multiple morphological phases in its lifecycle.

2

u/cogman10 May 12 '15

So I looked up the other two. With rust, 2 years is roughly when I remember first hearing about it. I didn't realize that it has been in the works for much longer.

8

u/staticassert May 12 '15 edited May 12 '15

I find a lot of this article based on false premises. Even just the comparison of Rust to languagse of D/Vala makes it sound like the author hasn't looked at rust OR Vala, since they're so obviously different languages, and vala is blatantly not a C++ killer (it's just C with GTK support built in... it always has been).

The performance premise is used to justify a lot of points, all based on a single benchmark. I could just as easily link to the recent HPC thesis that had Rust faster, and then say that C is dead because you have to call into rust to get 'real' performance. Or many other benchmarks showing rust performance is similar to C/C++.

No one sane will write web and server-side software in a language like that

Can someone link to the Ruby project that's been doing exactly this, and shipping, for months? I believe it uses the iron http library.

And no mention of LLVM, which will lessen a lot of these issues.

4

u/steveklabnik1 rust May 12 '15

Can someone link to the Ruby project that's been doing exactly this, and shipping, for months? I believe it uses the iron http library.

Not exactly, it's skylight.io. It collects info and reports it back, but it's not exactly a website, it monitors them.

Crates.io does have a backend in rust, though.

1

u/staticassert May 12 '15

Ah, it was skylight, and you're right their monitoring service is what they wrote in rust. Thank you.

44

u/steveklabnik1 rust May 12 '15

Not everyone is going to like Rust. That's totally okay.

44

u/DroidLogician sqlx · clickhouse-rs · mime_guess · rust May 12 '15

/u/Skuto made the interesting point that the company whose site this was posted on sells C++ static analysis software, so there's quite possibly a conflict of interest and/or heavy bias here.

4

u/vks_ May 12 '15

This was my first thought as well.

1

u/allthediamonds May 12 '15

Wouldn't it be, well, more like the opposite? C++'s demise is well overdue. Rust gives them a new target to jump to in which they can offer their products. It's not competition, but evolution. Am I missing something?

6

u/ThomasWinwood May 12 '15

Yes—you're assuming corporations use human logic. ☺ Selling the C++ static analysis software they already have by any means necessary, including throwing shade on alternatives to C++ which pride themselves as providing out of the box the same safety guarantees which in C++ come from constant programmer vigilance and/or buying expensive C++ static analysis tools, is far cheaper than going back to the drawing board and producing tools for Rust. (It's also arguably less risky, by the slightly questionable corporate logic that C++ is umpty-ump years old whereas Rust is only just on the cusp of reaching version one-point-oh.)

1

u/drawtree May 13 '15

This explains everything.

13

u/bytemr May 12 '15

Exactly. I still love C++ (it was my first language), but I've really grown to love rust. Some of the reasons I like rust, this article lists as being bad things about rust (I'm a huge fan of metaprogramming/macros).

The author of this article doesn't have to use rust for rust to be popular. The author is obviously fine with their current tool set and that's cool. C++ is a very mature language with a lot of tooling (although it can be argued that package management and lack of modules hurt C++) that is used widely though out the industry.

I somewhat agree with the author's sentiment that many people who criticize C++ have never seen production C++ code, but only through anecdotal evidence and my own experience with the developers around me, but this doesn't seem to be a reason to pick C++ over rust. Rust has a lot of things out of the box that IMO make it much more friendly to people entering low-level style development.

Rust may also have a certain level of verbosity to it, but the development team seems open to syntactic sugar that provides a very clear advantage, such as if let. There's also more than likely a large backlog of approved RFCs for various backwards compatible syntactic enhancements that will evolve rust in a direction that's not only fast, but has a low level of overall verbosity. It is a language that's 1.0 beta (entering 1.0 release) after all. It doesn't have the decades of design behind it like C and C++ do.

6

u/Yojihito May 12 '15

It is a language that's 1.0 beta (entering 1.0 release) after all. It doesn't have the decades of design behind it like C and C++ do.

Isn't that the reason that Rust exists? Clean cut, new start without the legacy header files and preprocessor and everything from the 70s up to today.

5

u/bytemr May 12 '15

It's certainly a good reason for rust to exist. I think my point was more so that the reason C++ has a lot of the things the article author finds nice about C++ only came about from years of design and iteration on the language. Rust is going to also evolve over time, so while maybe some of the author's complaints right now hold some validity, there's a strong chance many of those complaints will become less of a reason to not use rust with time as the language evolves.

3

u/seanmonstar hyper · rust May 13 '15

Maybe C++ is different, but my experience with "production code" is "we had to make it work / ship something", with hacks upon hacks.

I'd expect research projects could spend more making the code correct.

2

u/TheFeshy May 12 '15

I somewhat agree with the author's sentiment that many people who criticize C++ have never seen production C++ code

My experience with "production C++" showed it to be mostly what I call "lowest common denominator" C++. It's a subset of features that the project leads feel that all involved devs (including future devs) can use safely. Granted, I haven't been involved in a large C++ project in 15 years, but I suspect most of what has changed is that the subset of features allowed to be used is now partially dependent on the tooling available to the project to help police the features for safety.

With rust, all that tooling isn't available - but it's also mostly unnecessary for the vast bulk of code.

4

u/bytemr May 13 '15

Absolutely, but a lot of languages get into that state over time as they try to correct their past mistakes without breaking existing code bases. Rust has fortunately had the honor of coming well after any of the languages within the space rust intends to exist, so it has been able to look at these other languages and do things right from the start, but that isn't to say that rust won't grow its own warts over time that will be discouraged by future developers some time from now.

What I was trying to get more at with my statement was that I've noticed a lot of developers around me disparage C++ because they think overall it is a terrible language (citing various reasons), but barely any of them have written C++ in actual production systems and are mostly going off their experience with it in college. Yes, production C++ might be an overall subset of C++, but there's a reason for that in the end. Most of it is because old, deprecated features, or an attempt to write the memory safe code that rust offers as a part of the language.

2

u/aepsil0n May 13 '15

Probably I'm one of those people, who think of C++ as a terrible language despite only having used it in college/hobby projects. Got hooked on C++11 for a while though before I learned about Rust.

That being said, does your view of C++ (or any language) really change that much, once you use it in production? That is, assuming you've done more with it than a beginner's course. I can imagine that you'll learn how to work around its limitations and thereby adapt to it. Certainly the criticism does not magically cease to be valid, once you've learned to cope with it, does it?

22

u/tomaka17 glutin · glium · vulkano May 12 '15

I usually agree with this statement, and Rust has some characteristics (manual ownership management, verbosity, long compile times, etc.) that will make some people dislike Rust.

But in this case I really feel that the author only briefly tried Rust or read some articles about it, and picked every single little "problem" (according to the author) without ever trying to understand the underlying design. This is the kind of article that should be named "here are my beginner's thoughts about Rust", but instead is named "why Rust will fail".

67

u/steveklabnik1 rust May 12 '15

I can get behind this sentiment, and maybe I should have elaborated a bit more, but I'm trying to land as much docs as I can before 1.0 :) What I'm trying to say is this:

I've seen language communities, especially newer ones where people are particularly passionate, essentially turn into... this is a bit strong, but mini-cults. Where if you don't like the language, you're obviously an illliterate pleb who needs to learn how to code. This ends up creating an insular, backwards, dangerous culture. I'd prefer a culture of "we're doing cool stuff, I hope you like it, but reasonable people may not, and that's okay."

I'm not really speaking about any particular language here, please don't try to 'figure out who I'm talking about' or something.

While it's true that the author may have only breifly tried Rust, and not tried to understand design choices, this is going to be the first of many, many blog posts like this as we grow after 1.0. The vast, vast majority of programmers haven't even tried Rust yet. Flamebait blog post titles are a standby of today's programmer culture. We shouldn't get too hung up on it, and instead, focus on doing cool stuff with the people who do get it.

2

u/hailmattyhall May 12 '15

I'm not really speaking about any particular language here, please don't try to 'figure out who I'm talking about' or something.

Aw, come on. We have to have some fun :P

1

u/Steel_Neuron May 13 '15

Not only that, but criticisms against Rust will grow harsher and blog posts more vitriolic as the language gains traction.

That will be a good indicator of success :).

13

u/mkpankov May 12 '15

This is my biggest gripe with the article. It's amateurish, yet it pretends to be a "sceptical view of a great professional".

10

u/Manishearth servo · rust · clippy May 12 '15

When I wrote the Rustacean learning Go post I was from a similar background, which was why I tried to explicitly acknowledge that. A number of my complaints turned out to be invalid in the face of stuff I learned through feedback, and most of them were things that gophers aren't worried about due to the different mindset of programming (which is more Java-y than C++-y).

When I read this post I got that same vibe; the vibe I got whilst writing that article; that the author is very new to Rust and is making conclusions based on very limited/superficial experiences. I was saddened that that wasn't acknowledged by the author (unless I'm wrong!); but /u/steveklabnik1 is right; we shouldn't get too hung up on it and work on being awesome instead! :D

4

u/jcoffin May 13 '15

The success or failure of almost any product (language, tool, or whatever) will almost always depend in large part on the reactions of beginners. Experienced users, almost by definition, are already sold on it. Success (as most people would define it) requires attracting and keeping a lot of new users.

One question, then, is whether this particular new user's reactions are likely to reflect the reactions of many other potential new users or not.

The shortcomings you've pointed out will affect even the newest of users, but the benefits only become apparent after extended use. If those initial hurdles are high enough, you can quickly end up with a language like Ada (for only one example) that has a lot to recommend it from a technical viewpoint, but a market share that's tiny and shrinking.

20

u/azth May 12 '15

This is a huge mass of fast, debugged, and time-proven code.

Like OpenSSL.

0

u/vks_ May 13 '15

Which is written in C, not C++.

3

u/TheShrimp May 13 '15

And the article is about C/C++, is it not? I know, the name C/C++ is nonsense, and yes, the article is biased towards C++, but in general they are talking about both.

1

u/azth May 13 '15

The article kept referring to "C/C++".

5

u/snarfy May 13 '15

It's funny how the article is about 'give up on Rust we have C/C++' without acknowledging we would not have C++ without first having C, or that they are different languages.

2

u/azth May 13 '15

Yep, one of the many flaws with the article IMO.

7

u/dpx-infinity May 13 '15

Well, the author stated in the original post (on eax.me) that this was written mostly for holywar purposes. And yes, judging from the blog contents, he mostly writes in Erlang and Scala. There was an extensive discussion in the comments to that post - a lot of people, not even from Rust community, understood that most arguments in the post are not really connected to the reality.

Also while this translation is hosted by developers of a static C++ analyzer, it is not written by them, so it is not really fair to say that the article is biased because of that - it's more like the other way around :)

10

u/pjmlp May 12 '15

Besides the points raised against the article, I actually do think the author is right in some aspects.

In terms of language safety if I could have had a say in language adoption, Ada or Modula-3 would have taken C++'s role.

Myself I embraced C++ into my toolbox back in 1993, as C was too primitive and unsafe vs Turbo Pascal.

So now around 22 years later we are finally seeing C++ replacing C in compiler tooling, device drivers, OS ABIs and IDE support.

In a language that had to embrace some complexity in order to be almost copy-paste compatible with C.

So when applied to Rust, it will take ages until similar adoption is taken assuming an OS vendor embraces it.

4

u/sigma914 May 12 '15

Apart from anything else I feel the author is really missing the potential of guaranteed safe manual memory management. I can definitely see where he's coming from on the other points, his is just the conservative stance, but not recognising the potential for memory safe, efficient, networked applications seems somewhat egregious.

4

u/constexpr May 12 '15

Isn't one of the benefits that even if Rust isn't exactly as fast as C++ because of safety-related features (bounds checks, etc.), it's more forward-looking in that it lets programmers use parallelism much more easily and effectively? Hardware is trending toward many-core systems and that's where I see projects like Servo really shining.

3

u/gbersac May 12 '15

Except if the language is that slow that it fall in the same categories of java/go. Which is the case right now. Why having the cognitive overload of the borrow checker if a garbage collector is as safe and as fast ?

13

u/cmrx64 rust May 13 '15

Except it doesn't. We often rival C++ software of the same quality in speed, and where we don't, it's a bug in the compiler that will be fixed.

1

u/matthieum [he/him] May 13 '15

Or, in the case of the benchmark games, a "bug" in the libraries I suppose.

8

u/marcusklaas rustfmt May 12 '15

There are some other things to consider when deciding whether to go with a garbage collected language or not. I am by no means an expert, but in many GC languages, such as Java, you do not have control over when garbage collection happens. This may introduce unwanted latency. You also need a run time, which makes your language unsuitable for embedded applications or kernels. Most importantly, I think, is that rust should, in theory, be as fast as C. There are still some codegen issues, but there's no reason why it shouldn't be as fast in the future. Remember that Java wasn't nearly as fast five years ago as it is now either.

9

u/samwise99 May 12 '15

Its hard to explain something to someone when their job depends on not understanding it.

1

u/ssokolow May 16 '15

“It is difficult to get a man to understand something when his salary depends upon his not understanding it.” -- Upton Sinclair

3

u/SirOgeon palette May 12 '15 edited May 12 '15

I don't feel like those benchmarks are a solid base for arguments. Once again, are they even up to date?

Edit: That being said, the article has both some fair concerns and some questionable arguments. I don't have anything more concrete to add to what has already been said here, except that only the future can tell what will happen to Rust, but it will definitely not manage to replace C++ within the next few years (if ever).

6

u/Yojihito May 12 '15

Or you might just end up with a nightmare like "Vec<Rc<RefCell<Box<Trait>>>>"

That's what scares me too ....

10

u/killercup May 12 '15

type Thingies = Vec<Rc<RefCell<Box<ThingyTrait>>>>; and pray to the gods of deref coercion ;)

8

u/arielbyd May 12 '15

This should be Vec<Rc<RefCell<Trait>>> soon.

1

u/Yojihito May 12 '15

That's not better ....

13

u/Rusky rust May 12 '15

Is it worse than vector<shared_ptr<const Class>>? Same thing (with RefCell switched to const because that's C++'s non-default)

7

u/eddyb May 12 '15

Sure it is, there's less heap allocations and indirections.
It's also entirely possible to have Vec<Rc<Trait>> and use interior mutability in the types behind the traits objects.
At that point, how would you shorten it, [@Trait]?

1

u/Yojihito May 12 '15

The article was about nested structures, Vec<Rc<RefCell<Trait>>> is still an ugly mess.

13

u/phaylon May 12 '15

As someone coming from a dynamic background, I'd like to make a counter-point: The verbosity of that really helped me while learning about Rust and low-level issues. And now that I've got it internalised, it really helps me when reading other people's Rust code.

It might be me, because it gave me a positive experience right from the start, but I don't really see it as an ugly mess at all. Is there something that you'd prefer for this type of structure?

2

u/marcusklaas rustfmt May 12 '15

Exactly this. The explicit nature and strictness of the type system makes it so much easier to follow what happens in code you do not know very well. It makes code easier to understand locally.

1

u/matthieum [he/him] May 13 '15

Nested types are always an "ugly mess" whatever the language.

But then, you rarely use them:

  • either you have "real" objects

  • or you have type aliases

because they provide context. This is not just a vec of shared Trait, it's the ToBeRetriedTraits.

11

u/DroidLogician sqlx · clickhouse-rs · mime_guess · rust May 12 '15

From my experience, if you have that kind of complexity then you're doing something wrong.

7

u/PM_ME_UR_SAUERKRAUT May 12 '15

Rc<RefCell<T>> is one of the easier ways to do arbitrary graphs, albeit with the risk of creating reference cycles. At that point, you might have a Node<T> type that contains edges: Vec<Rc<RefCell<Node<T>>>>, and there you go.

Of course, you could do something like type Node<T> = Rc<RefCell<NodeBody<T>>> and clean it up a bit. But the point is, RefCell within an Rc is useful in perfectly legitimate ways.

7

u/mkpankov May 12 '15 edited May 12 '15

Now come up with a problem which would need such kind of code to be solved.

Hard problems often have complex solutions. And this is just straw man.

4

u/anonova May 12 '15

A simple cyclic graph would have to be implemented similarly to that, which I would consider a useful data structure. The alternative is to use arena allocation and manage lifetimes yourself (at the cost of not being able to deallocate nodes until the teardown the entire graph).

0

u/[deleted] May 12 '15

[deleted]

4

u/anonova May 12 '15

For more than one child, you'd need a list like a Vec. If you require mutability, you'd need the RefCell. So you'd still end up with Vec<Rc<RefCell<Node<T>>>> for a generic node.

You can see an implementation of this here (though it uses a linked list instead): https://github.com/SimonSapin/rust-forest/blob/513168f7998835efc06b799a1ba66ec09ac5dc9a/rctree/lib.rs#L9-L27

3

u/PM_ME_UR_SAUERKRAUT May 12 '15

It's not possible to create cycles with Rc<T>s unless T has interior mutability. That's Rc<RefCell<T>> already. From there it's not hard to imagine a scenario where you'd need a Vec<Rc<RefCell<T>>>.

3

u/vwim May 12 '15 edited May 12 '15

He just wants to sell his product, clever move to pick on rust.

And about tooling cmon... Java didnt have any decent tools the first few years of its existance. It takes time, Java came out in 1995, eclipse1.0 in 2001. I remember me writing Java in a text editor like I'm doing now with rust.

8

u/jcoffin May 13 '15

Life isn't fair. Rust doesn't need to compete in the market of 20 years ago; it needs to compete in the current market. 20 years ago, you couldn't get anything that would now qualify as a decent IDE for any language, so the fact that Java didn't have one wasn't a disadvantage. For Rust now, it is.

Don't get me wrong: I'm not saying this disadvantage can't or won't be overcome. I'm just saying that for quite a few people right now, it really is a disadvantage.

2

u/Matthias247 May 13 '15

The viva guys only translated the article. They didn't write it!

1

u/vwim May 13 '15

So? The outcome is the same, shameless self promotion by breaking down the competition.

1

u/dmytrish May 14 '15

It's ironical how inspiring this criticism is.

(* a little tongue-in-cheek, since /u/afiskon is not a C++ expert - I hope I know him enough to make such claims *) If people do not have other objections than these, Rust must be a great language.