r/programming • • May 12 '15

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

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

287 comments sorted by

26

u/hackerfoo May 12 '15

As an embedded software engineer, the memory required by a program is at least as important that the speed of execution. There are plenty of "fast as C" compilers if you have 385GB+ of RAM lying around.

6

u/Denommus May 12 '15

And Rust gives you as much control over memory as C.

18

u/hackerfoo May 12 '15

Obviously. I was pointing out that there are few safe languages that do, though.

In the article, the author claims there are already many fast safe languages, but none of those languages are suitable for embedded work because of their reliance on garbage collection.

13

u/dfgdfgvcv May 12 '15

You might take a look at Ada, actually. It's very safe (largely in a different way than Rust, which is mostly focused on memory safety as far as I can tell) and quite fast. It also gives very low level control and actually has some amazing features for really low level stuff.

In particular, one thing that stuck out to me from my own daliance with microcontrollers was that you can have record components that span specific bit ranges. This completely removes the whole shift and mask side of things which is kind of lovely.

2

u/sellibitze May 13 '15

Last time Ada was mentioned in this respect, I tried to figure out how it achieves memory safety. As far I can tell, you're very restricted in Ada if you want memory safety. Avoiding use-after-free implies disallowing users to free heap-allocated memory. And to deal with the lack of something like Rust's lifetime parameters there are probably other restrictions as well, for example, I don't think there is a safe equivalent of

fn max<'a, T: Ord>(x: &'a T, y: &'a T) -> &'a T {
    if *y < *x { return x; } else { return y; }
}

where x and y are pointers that may also refer to stack-allocated things. If you're familiar with Ada, I would appreciate it very much if you shed more light on what the restrictions in Ada are exactly w.r.t. memory safety.

1

u/dfgdfgvcv May 14 '15 edited May 14 '15

I'm not particularly well versed in Ada but I've been using it exclusively in my personal projects for a few months.

Ada doesn't do memory safety in the same way as Rust, and in many ways you could say it's more limited. The main thing is really just generally discouraging the use of the heap. It's not hard or annoying to do, but often it's not needed. When you do need the heap, you can define different storage pools that the memory will come from. When that storage pool falls out of scope, all of it's memory will be released. You can also do things like use an instrumented pool to track allocations and deallocations, which can prevent access to deallocated objects. But that's mostly just a way to help fix things after they've gone wrong, I suppose.

Pointers, called accesses, also have some additional checks called accessibility checks to try and prevent dangling pointers. Essentially a pointer in an outer scope can't refer to an object in an inner scope, although if you really need this you can use an Unchecked_Access.

You can also create an access subtype that cannot be null. This compels initialization and prevents deallocation using the subtyped variable. In practice I'm sure this can be circumvented, but would require a little bit of work (that I don't think would be done accidentally).

As for that specific example, I'm not well versed in Rust. Perhaps you can see an answer in what I've described already or you can explain a bit what it does?

Oh, one thing I forgot to mention. The standard allows for a GC, but in practice it's only really available if you are targeting the JVM or .NET.

2

u/Scroph May 12 '15

Where I live, embedded development is mostly done in C, C++ and assembly in some rare cases. I've also came across an ad that asked for proficiency in the JavaCard technology, but other than that, there's not much else going on.

I wonder if that's what the embedded industry looks like in other parts of the world.

4

u/hackerfoo May 12 '15

Same here, unless the definition of embedded includes non-realtime OSs.

2

u/Scroph May 12 '15

I'm an ECE student. How relevant is Rust in embedded development ? Will for example run on 8-bit MCUs ? I'm asking out of curiosity, not condescension.

7

u/hackerfoo May 13 '15

Zinc is a bare metal stack for Rust that runs on some ARM MCUs.

5

u/Denommus May 12 '15

Well, as of now Rust targets the LLVM, so the platforms it supports are limited for the LLVM targets. Although it is designed to be able to do that, there's still not a toolchain for that.

When the language is released it is more likely that it will begin to be ported to other places, provided that there are people interested.

3

u/ChainedProfessional May 12 '15

Would be cool to see it running on the Arduinos, where I believe they now use C with some extra macros and libraries. (Or maybe it's C++?)

6

u/Narishma May 12 '15

Arduino is C++, even if they don't use much of what it offers over C.

→ More replies (1)

109

u/Yehosua May 12 '15

Having sat in on enough static versus dynamic typing debates, I find it ironically amusing to hear a C++ guy argue that you don't need compile-time checks because your test suite will catch bugs.

(regarding his argument that Rust's compile-time checks aren't compelling because Google's runtime sanitizers can do the same for C++)

45

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

I find it ironically amusing to hear a C++ guy argue that you don't need compile-time checks because your test suite will catch bugs.

Indeed.

We should also consider the source of this article: The author of the translation has a vested interest in c++ staying relevant since his company sells c/c++ static analysis tools.

EDIT: clarified the article authorship

45

u/vytah May 12 '15

The author doesn't, this is only a translation.

10

u/Narishma May 12 '15

The translator/republisher then.

0

u/[deleted] May 13 '15

[deleted]

7

u/badsectoracula May 13 '15

Because they post interesting stuff?

Their analysis articles are among my favourite reads, if not for other reason than seeing what kind of common mistakes people do and trying to be more conscious about them while writing code.

7

u/dfgdfgvcv May 12 '15

That's because even though C++ has a static type system, it's about as weak as type systems get.

19

u/[deleted] May 12 '15

Huh? It's a much stronger type system than what we find in C or golang.

12

u/pjmlp May 12 '15

But less than Modula or ML line of languages.

3

u/[deleted] May 12 '15

What are some examples of things that make ML's type system stronger than C++'s? The language overall is safer than C++, but can one express something using ML's type system that can't reasonably be expressed in C++?

10

u/pjmlp May 12 '15

Modules and ADTs for example.

Bjarne has a proposal for adding ADTs to C++, but it requires lots of clever meta-programming and macros.

Languages like Idris and ATS are also part of ML family, and you cannot express dependent types nor affine types in C++.

Finally, C's compatibility means that any developer can just throw away whatever safety one might express in C++.

5

u/[deleted] May 13 '15

Bjarne has a proposal for adding ADTs to C++

... and yet another bolt added.

By now we have seen two serious proposals about a module system in C++. One from Apple and the other from MS. Both proposals suck because they won't deal with all the aspects of modules. Modula did this already in around 1980. It is a real shame.

Finally, C's compatibility means that any developer can just throw away whatever safety one might express in C++.

There you have it. Combine a build system that could look at the stars for deciding what kind of defines it includes, a macro systems that can say + = -, and operator overloading, the only way to be sure 1+1=2 is to look at the disassembly each time you compile it.

4

u/pjmlp May 13 '15

By now we have seen two serious proposals about a module system in C++. One from Apple and the other from MS. Both proposals suck because they won't deal with all the aspects of modules. Modula did this already in around 1980. It is a real shame.

I know. Actually CLU and Mesa did it in the 70's around the same time C was being brought into the world.

C++ suffered from the decision that it should rely on the C toolchain to be as easy as possible for C developers to transition into it.

It was probably a bad decision, or not. Maybe it wouldn't have been adopted by C compiler vendors if that wasn't the case.

I was happily using Turbo Pascal and C looked already primitive back then.

the only way to be sure 1+1=2 is to look at the disassembly each time you compile it.

Assert(Add (1, 2), 2)

Are you sure these functions do what they say? Does Add really add?

Maybe it is the influence abstract mathematics had on my CS degree, but I don't see a difference between symbolic and alphanumeric names.

While everyone bashes operator overloading in C++, almost all modern programing languages (with a few exceptions) allow for symbolic names.

→ More replies (7)
→ More replies (2)

19

u/smog_alado May 12 '15

The biggest thing ML has that C++ doesn't is algebraic data types (tagged unions). It helps a lot in making switch statements more type safe.

ML also doesn't have lots of the unsafe stuff that C++ has. There is no manual memory management so no use-after-free bugs, there are no pointers and arrays have bound checking so there are no buffer overflows, etc.

5

u/tending May 12 '15

C++ has those, see boost::variant, soon std::variant.

10

u/smog_alado May 12 '15

Variants are much less useful without pattern matching syntax though. Its much more annoying to use them if you need to use the visitor pattern.

4

u/tending May 13 '15

You can pattern match too: https://github.com/solodon4/Mach7

But only on type, not inner structure. There are better hacks possible now with C++11/14 too, you don't need a visitor, just a bunch of lambdas.

→ More replies (1)

2

u/aldo_reset May 12 '15

But you are trying to assess the relative strengths of the type systems by looking at a feature that only one language possesses. This doesn't make much sense.

You can say that ML has a richer type system than C++, sure, but "stronger" doesn't seem relevant here.

→ More replies (8)

-6

u/dfgdfgvcv May 12 '15

What? It's the C type system. With automatic copy/paste, I suppose.

4

u/Symaxion May 12 '15

A lot of unsafe conversions available in C are disallowed in C++. For example, you need to explicitly cast the return value from malloc to the correct type (C++ does not support automatic conversion from void pointer). Plus C++ introduces long-form casts, which disallow arbitrary conversions (except for reinterpret_cast, which is the equivalent of Haskell's unsafeCoerce).

2

u/dfgdfgvcv May 12 '15

Interesting. I did not know that. I don't think I've ever had a reason to use malloc in C++.

7

u/Denommus May 12 '15

It's far from the same type system of C. C doesn't have parametric polymorphism or higher kinded types, C++ does.

→ More replies (7)

2

u/SnowdensOfYesteryear May 12 '15

C's type system should be stronger than it is. Something like this compiles without warnings:

enum foo {
	FOO,
};

enum {
	BAR
} temp = FOO;

I'm not really sure why this shouldn't be considered a compile error, I'm guessing it's some legacy reason.

The latter code produces at least a warning on C++.

6

u/RedAlert2 May 12 '15

And if you are using c++11, you can use enum class, which will fail to compile if you try this.

2

u/[deleted] May 13 '15

... and yet another bolt added, instead of fixing it properly.

→ More replies (4)
→ More replies (4)

1

u/[deleted] May 12 '15

C's type system doesn't provide nearly the same static guarantees that C++'s type system does, in fact C++'s type system can encode guarantees that very few other languages, including Java, can.

For example RAII allows one to encode preconditions and post-conditions into the type system.

2

u/dfgdfgvcv May 12 '15

How would you use RAII to create pre- and post-conditions? Constructors and destructors just give you creation and destruction. I can see creation potentially being useful but I'm not sure about destruction. And I think to take advantage of that you'd need exceptions which itself causes some trouble...

→ More replies (4)

3

u/RedAlert2 May 12 '15

If you ban C-style casts and encourage the use of enum class over enum, C++ types are quite strong.

9

u/dfgdfgvcv May 12 '15

That's better but not really enough. C++ does a lot implicitly, and unless you want to wrap up everything inside of a class you're still left with a lot of raw things.

7

u/RedAlert2 May 12 '15

That's true, it's definitely not perfect. My least favorite thing that c++ does implicitly is allow integers and pointers in conditionals, even though the language has a bool type. In my opinion, anything in an if statement should have an explicit true/false value - it makes code easier to read and reduces bugs.

1

u/igor_sk May 13 '15

At work, we enabled an Msvc warning which catches such things. We found a couple bugs after this.

→ More replies (2)

1

u/cdglove May 13 '15

The point is that you can wrap everything in a class and effectively get close to other languages.

1

u/dfgdfgvcv May 14 '15

You can but it's an absolute ton of work, you have to be careful to avoid situations that let the compiler implicitly convert things, and it's all trivial to avoid if anybody is at all inclined to do so.

It's really just worse in all ways than something that is actually part of the language.

7

u/allthediamonds May 12 '15

Well, yes. Every language is type safe if you restrict the language to a type safe subset of it. That defeats the point of discussing type safety, though.

0

u/RedAlert2 May 12 '15

not really...not many languages make it totally impossible to write unsafe code. It's not hard to restrict a language to a specific subset using linters/static analysis tools.

-2

u/Peaker May 12 '15

C++'s type system is quite strong!

16

u/dfgdfgvcv May 12 '15

It isn't. At least not in the way people usually mean when they talk about strenght and type systems.

It's extensible. But it is very happy to do implicit conversions for you, and provides no nice mechanisms for adding constraints to a type (say, days in a week).

It's not that you can't do things in C++. You can. It just might be a huge pain and then easily subverted because it isn't part of the language. It's something you added in and require yourself/others to use.

2

u/Peaker May 12 '15

The word strong here is being used to indicate type checking strictness, and not expressivity?

If so, c++ has a weak subset and a strong subset (i.e no c casts and more).

Implicit conversions (e.g Scala, subtyping, and more) aren't usually considered weak typing (except when they're not sensible, such as string to int).

I guess the word strong/weak is simply too ill defined in type theory context.

5

u/dfgdfgvcv May 12 '15

There's always semantic issues, unfortunately.

The C++ system is technically potentially very expressive, but in practice that's not always feasible and it is always easily circumvented because the base, raw system cannot be hidden. I mean, it seems people have implemented dependent types with templates in C++, but that's a far cry from saying C++ is dependently typed.

2

u/neutronbob May 13 '15

If so, c++ has a weak subset and a strong subset

This is the most accurate assessment of the current state of affairs. The divergence in opinion forms right after this point: For most developers, the weak subset means that the language is not strongly typed. For C++ developers, and pretty much only for C++ developers, the strongly typed subset means the language is strongly typed.

-3

u/[deleted] May 12 '15

C++ type system is Turing-complete. You can even have dependent types with it.

19

u/Peaker May 12 '15

C++ can use templates over any-typed compile-time values, but template parameters cannot depend on runtime values, so it is not really dependently typed.

→ More replies (2)

3

u/dfgdfgvcv May 12 '15

Just because you can make them doesn't mean they're part of the language, even if you could implement them in a usable/useful manner.

74

u/Darkmoth May 12 '15 edited May 12 '15

It's interesting that the Rust/C++ comparisons are often presented as a zero-sum game. You rarely see articles like "Why Ruby will replace Python". In reality, Rust doesn't need to replace C++, it simply has to offer a compelling and useful development experience in it's own right.

I was a C programmer in the early 80's when C++ hit the scene. As I recall, there were many heated debates about which was "better", and whether C++ would replace C. 30 years later, both languages are still going strong.

38

u/[deleted] May 12 '15

[removed] — view removed comment

23

u/Darkmoth May 12 '15

I hear you. But language popularity is a much more complicated topic once you start partitioning by OS and application. How popular is Objective-C? Both ubiquitous (MacOS/IOS) and nonexistent (Windows).

→ More replies (23)

12

u/matthieum May 12 '15

A C++ programmer will hardly ever have any difficulties finding a job with a more than worthy salary and, if necessary, can quickly learn Rust.

Agreed (and maybe one of the few valid points).

6

u/ChainedProfessional May 12 '15

Rust hasn't been released yet, so I wouldn't expect to find any jobs that use it.

1

u/matthieum May 13 '15

Actually, there was 0 offer on StackOverflow last I checked :)

0

u/[deleted] May 13 '15

[deleted]

2

u/matthieum May 13 '15

This might be misleading though, just because exotic languages pay more does not mean:

  • that there are active job offers

  • in a location you'd like to live

  • for a company you'd like to work in

  • ...

Salary is far from being everything.

For example, while I know that COBOL pays well, I am not interested.

→ More replies (1)

9

u/mcguire May 12 '15

On very rare occasions, this problem [the chicken and egg ("a couple of tens of thousands of ready-made libraries")] does get resolved (relatively representative examples are Go and Scala) - mostly thanks to investments of time and money from some large company (Google, Typesafe) who for some reason finds it worthy to popularize a new language.

Typesafe is a large company?

4

u/vks_ May 13 '15

The author is apparently a Scala guy.

8

u/neutronbob May 13 '15

I normally just let go of the fact that C and C++ are lumped together as C/C++. But here, where the author is examining history and language features, the lumping is clearly wrong.

D and Rust might well be languages that are intended to be a better C++, but neither one was intended to be a better C.

15

u/Sapiogram May 12 '15

The author ignores one very important advantage that Rust has over D and other proposed C++ replacements, outside the properties of the actual languages: Rust has a fairly large company fully backing it. That matters a lot for marketing and just plain brand recognition, and the fact it is used for Servo guarantees it a minimum of tools and libraries from Mozilla. I'm not saying that Rust doesn't have a very tough road ahead, but hell, they have a dedicated guy just to write language docs and interact with the community. They're off to a good start.

6

u/[deleted] May 12 '15

the fact it is used for Servo guarantees it a minimum of tools and libraries from Mozilla

How will Servo make money for Mozilla?

18

u/Sapiogram May 12 '15

By continuing to improve their product to capture browser market share? The same way they're already making money, really.

8

u/Entropy May 13 '15

Samsung is interested in it for making html rendering faster on multicore.

1

u/jyper May 13 '15

It won't, mozilla has a complicated structure but it's basically a open source non profit. They sell default search bar privledges and default new tab bookmarks(to reputable search engines/companies) in Firefox to make money which they spend on hiring open source developers.

-9

u/username223 May 13 '15

they have a dedicated guy just to write language docs and interact with the community. They're off to a good start.

The Klabnik-bot? It generates a lot of output, but I'm unimpressed by the quality.

24

u/badsectoracula May 12 '15

The article is somewhat opinionated and badly written (being translated from Russian by Viva64 who themselves aren't exactly stellar in their English doesn't help there), but there are some valid points in there, like the "chicken and egg" problem and that tools matter a lot. Personally the reason i dropped D wasn't because of the language itself, but because i feel that Visual Studio (and Eclipse, if we ignore the debugger) provides a much nicer environment and i like Lazarus for GUI development not because of Free Pascal, but because of Lazarus' stellar GUI tools and framework.

For Rust, D, etc to have a chance at becoming popular they need to provide tools which are better than the current C/C++ tools (being just as good isn't enough, there is no point to go through the pains of switching if you're not getting something massively better).

10

u/bcash May 12 '15

But how much are those tools only necessary because of C++'s weirdnesses and/or other problems that Rust has fixed at its core.

Of course there's still room for tools to grow, like a debugger etc. Which should be possible due to the LLVM toolchain possibly.

25

u/matthieum May 12 '15

The "Click to definition" and auto-completion features of an IDE are always interesting, no matter the language.

7

u/immibis May 12 '15

Don't forget refactoring! Especially the basic stuff, like "rename method". Which is practically impossible to do reliably in C++.

2

u/thunabrain May 13 '15

Eclipse CDT does a fantastic job at that. I don't like the rest of it much, but the refactoring tools are so stellar that I'm compelled to keep using it. Simply put your cursor inside a variable/class/method name, press Alt+Shift+R and type the new name while you can see the code being updated in real-time. It can do global renames and even gives you warnings if the rename could cause conflicts/shadowing and lists potential hits if the variable name is referenced inside a comment.

The only time I've seen it fail is if a method is used inside a template, i.e.

template<typename T> void foo() { T bar; bar.baz(); }

in which case you could not rename baz (which is understandable, really).

1

u/matthieum May 13 '15

Eclipse chokes on std::string (and a number of typedef) on my laptop: anytime a method has such an argument, it fails to find any call site.

14

u/Gotebe May 12 '15

Of course there's still room for tools to grow, like a debugger etc.

That's not room to grow, that is a fucking massive void to fill, and quick!

No, hang on... no debugger at all?! No, that can't be, and indeed, there's gdb.

12

u/dangerbird2 May 12 '15

Rust works with GDB out of the box. There's no need for a specialized debugger.

2

u/badsectoracula May 12 '15

The only thing that i can think of being C/C++ weirdness specific that Rust might inherently make things easier with is a static analyzer. However i doubt Rust can avoid issues like code copy/paste mistakes (according to PVS Studio's articles from open source project analyses, one of the most common types of mistakes).

For other tools, like debuggers and profilers where a GUI helps tremendously (especially with profilers), the ability to jump to definitions, refactoring support (that goes beyond a public search and replace of words) or the ability to find references, support for pause/edit/continue, diff tools that understand the language and can provide semantic diffing instead of (or in addition to) text-based diffing, source code browsers, etc are not things that can be "fixed" via language design (some things, like pause/edit/continue in functional languages, can be easier to implement but still need someone to implement it).

3

u/viraptor May 13 '15

Actually it can prevent some silly copy/paste mistakes due to two ideas: moving values out of the function scope (so you can't use it twice by accident), being immutable by default (no accidental reassignments). Sure, there are still lots of ways to make a copy/paste mistake, but less than in c. These are examples I noticed while writing actual code BTW.

1

u/badsectoracula May 13 '15

Possibly, but it doesn't eliminate the problem. And from what i remember, most of the errors are on assignments and comparisons which would be the same story in Rust.

1

u/Mawich May 13 '15

Actually that's lessened in Rust, because comparisons can't accidentally mutate a value if the value is immutable, and assignments are much less because Rust runs on immutable data by default. Hopefully conventional Rust idioms will embrace that rather than just putting "mut" on everything.

Of course, because Rust can have mutable data you still have the potential, but the language features imply a particular default style which helps reduce a lot of this kind of thing if it's adhered to.

(You can of course write bad code in any language, my assessment is usually based on how many obstacles there are to writing better code).

2

u/badsectoracula May 13 '15

The comparisons i'm talking about are things like

bool xok = a.x < b.x && a.x != c.x;
bool yok = a.y < b.y && a.x != c.y;
bool zok = a.z < b.z && a.z != c.z;

Those don't mutate anything (well except the assignment but initial assignment isn't exactly mutation) and i'm sure you can do this mistake in almost every language out there.

→ More replies (3)

7

u/dangerbird2 May 12 '15

The difference between D and Rust is that Mozilla is backing Rust, and intending to use it to replace code in Firefox, one of the more visible C++ projects out there. Rust already has very good tooling (albeit on the command line), and has great compatibility with C APIs, making interfacing with other languages and using preexisting debugging tools very simple.

-5

u/doom_Oo7 May 12 '15

And Facebook is backing D.

18

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

It's really problematic when people claim Facebook is backing D despite the fact that Facebook has never made any such claim. Andrei Alexandrescu, one of the main contributors to D, works for Facebook as a research scientist. His work isn't even related to D but because he works there he sometimes likes to give people the misleading impression that Facebook supports D or is connected to D. Of course when he's asked directly whether his work on D is on behalf of Facebook or sponsored by Facebook he will fully admit that in fact it is not.

D lacks any real corporate sponsors so the next best thing it can do is basically drop the suggestion that Facebook is quasi-supporting it, backing it, or sponsoring it. It lets D leverage the popularity of Facebook to give it some credibility when really no such credibility exists.

It would be like if someone worked at Google and wrote their own programming language on the side and then tried to link their employment at Google as somehow being connected to their side-project to suggest in a subtle manner that there is a relationship between the two. But then when push comes to shove they back off from that claim and admit that in fact the two are independent.

3

u/doom_Oo7 May 12 '15

Today I committed the first 5112 lines of D code to Facebook's repository. The project is in heavy daily use at Facebook.

http://forum.dlang.org/thread/[email protected]

http://www.quora.com/How-is-the-D-programming-language-used-at-Facebook

https://github.com/facebook/warp

13

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

You are kind of reinforcing my point that a subtle attempt is being made to associate Facebook with D because Facebook has 5000 lines of code written in D.

However, I can go here:

https://github.com/facebook

And find more lines of code written in Lua, OCaml, Haskell, Python, Ruby, Objective-C and Bash script files than the 5112 lines of D code being paraded around as being indicative of corporating backing and sponsorship of a programming language.

Of course no one bothers to write an article boasting about how Facebook has adopted Lua because some programmers happen to be using it, nor do people jump to the conclusion that Facebook is backing Go (despite some programmers at Facebook who are using Go internally), it makes no sense to think that Facebook is now backing or sponsoring or associating itself with D.

7

u/cwzwarich May 13 '15

DConf 2014 was hosted by Facebook, which probably counts as sponsorship.

→ More replies (1)
→ More replies (1)

6

u/The_Doculope May 13 '15

For Rust, D, etc to have a chance at becoming popular they need to provide tools which are better than the current C/C++ tools (being just as good isn't enough, there is no point to go through the pains of switching if you're not getting something massively better).

I disagree here. There are plenty of reasons to use Rust over C/C++ even if the tools aren't better. Tooling is not all there is to a language,. If someone's already in a position to switch, I don't see why the tools should need to be better to make it worth it.

2

u/badsectoracula May 13 '15

Because if they are the same he still has to pay the price for the effort required to switch to Rust (learning it, gaining experience with it, taking advantage of it, converting some/all of the codebase, etc).

Tools aren't part of a language and when it comes to the language itself, they do not matter. But they do matter when it comes to using the language.

2

u/The_Doculope May 13 '15

Because if they are the same he still has to pay the price for the effort required to switch to Rust (learning it, gaining experience with it, taking advantage of it, converting some/all of the codebase, etc).

That's why I specified "if they're in a position to switch". At least for C, in many domain Rust would be a very easy transition since the interop is fantastic and has no performance penalty.

I don't understand why the ecosystem has to be better in every single way rather than equal or better. In a similar matter, having a single aspect of your ecosystem be excellent (like C++'s tooling) doesn't mean other language ecosystems are automatically not worth switching to.

2

u/badsectoracula May 13 '15

What exactly do you mean with "in a position to switch"? Because for me it means that one has the option, not that they do not care about the time they'll need to spend to switch. But regardless, that time is still there.

And the reason the ecosystem has to be better is that if things are equal, then you still have to pay the switching costs so it actually becomes worse for Rust (or D or whatever). The ecosystem has to be better to counterbalance the switching costs.

And keep in mind that i'm talking about the language becoming widely (mainstream) popular, not about few isolated cases of people switching because they think it is cool and they do not care about the extra effort they'll need to pay.

1

u/The_Doculope May 13 '15

By in a position, I mean they consider language switching a surmountable cost, and they're likely looking at other languages for a suitable alternative.

I understand why the ecosystem/language have to be better, just not why the tooling in particular has to be. But I would argue that Rust already has way better tooling in one area - the integrated builder/tester/package manager that is Servo. We already have GDB for debugging, but the IDE situation definitely needs some work.

2

u/badsectoracula May 13 '15

Because you work with the tools to develop stuff. Some people might be fine with a plain old text editor and a few command line tools, but the popularity of Visual Studio, Eclipse, NetBeans, IDEA, etc show that the majority of people prefer to have a full blown IDE and in fact they'll even pay for an IDE that provides just a little more convenience (as shown by how many people would prefer to buy IDEA/VS instead of using the free Eclipse/NetBeans).

→ More replies (4)

4

u/[deleted] May 12 '15

You may be aware of this, but there's a very nice plugin for D development in Visual Studio: http://www.dsource.org/projects/visuald

This is something I wish more new languages would put together.

4

u/badsectoracula May 12 '15

I tried that a while ago and i remember the functionality lacked considerably compared to Visual Studio's C++ support. But that was some time ago and i haven't tried it any time recently. I might try it again eventually since i actually like D as a language, it is the tools that drove me away.

1

u/Enamex Aug 08 '15

Compared to Intellisense functionality, it lacks a lot. Besides that, it has it all:

easy access to most options of the DMD compiler as check-boxes, usable with DMD/LDC/GDC with easy configuration, integrated debugger working nicely with var inspection, breakpoints and stepping,

nice syntax (but not semantic) highlighting with adequate, um, not sure what to call that but access to information on variables/funcs/types through tooltips, and lastly okayish auto-completion (again not comparable to, say, Visual Assist but really, you'd be asking for a lot from a newish open-source program to be).

1

u/badsectoracula Aug 08 '15

Well, I tried it one or two weeks ago before I formatted my PC to install Windows 10 and TBH it was almost as I remembered it. The syntax completion and those tooltips you mention only worked with the most basic classes, but IMO the biggest reason to use D over C++ is the more advanced stuff it has - like mixins - which trip up Visual D (and tbh in the case of plain mixins which work via compile time code generation, i'm not sure if there is much an IDE can do beyond running code at the background... it could be possible the compiler to run code in a VM in another thread - for safety reasons to avoid lock ups - but I can't see any IDE doing that any time soon).

3

u/[deleted] May 12 '15

My full-time experience with C++: code and debug from within Visual Studio, with completion. Point a variable, see its value. F12 jumps on definition.

My full-time experience with D: code and debug from within Visual Studio, with completion. Point a variable, see its value. F12 jumps on definition.

How do you improve on what works well?

9

u/badsectoracula May 12 '15

By doing something great? See my other comment for other kinds of tools.

Here is an example:

I just downloaded DMD and Visual D and decided to try and make a spinning triangle in OpenGL. Apparently while it does have support for the Windows API, it doesn't include the OpenGL bits (why do they write the interface by hand instead of parsing the header files? Digital Mars already has a C parser and header files aren't copyrightable, at least according to FSF, and even if they were, there are public domain headers they can use instead of Microsoft's).

From what i remember from the last time i tried, there is a project called Derelict that provides OpenGL headers, so after googling around for a bit i found this page. Apparently there isn't a nice SDK with an .exe installer i can download, run, next, next, be done with it and use it directly from within Visual Studio without thinking about it more than that, but anyway.

Sadly, Derelict seems to rely on DUB, a package manager that supposedly automates things (which is nice) that isn't supported by Visual D (which isn't that nice). The workaround i've found is to instruct DUB generate a project file for each of the Derelict sub-projects i want to use and put them in my solution. This means that i need to basically put extra unnecessary stuff in my project/solution just to use these libraries. Now some people might not mind, but personally i prefer to have in my solution only the stuff i wrote and put 3rd party libraries in some external place available system wide.

So what could improve here? Simple: add the ability to define, download (not per-project/solution) and install DUB things directly from inside the project/solution settings in Visual Studio and have them applied automatically.

Another example would be showing the comments above declarations in a popup, like Visual Studio does for C++, especially since in D those comments are often used to generate the actual documentation.

These are just two things i immediately noticed by using it for half an hour or so.

1

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

Sorry for the late reply, I think not all problems you noticed exist.

I just downloaded DMD and Visual D and decided to try and make a spinning triangle in OpenGL. Apparently while it does have support for the Windows API, it doesn't include the OpenGL bits (why do they write the interface by hand instead of parsing the header files? Digital Mars already has a C parser and header files aren't copyrightable, at least according to FSF, and even if they were, there are public domain headers they can use instead of Microsoft's).

This would be absolutely the same in C++. To use OpenGL you typically use a pointer-loading library since the right function pointers are only available while the program runs after one (two for Modern OpenGL) context creations. There is no way to statically link to OpenGL nowadays, you have to load function pointers. Hence GLEW in C++ and Derelict in D.

The workaround i've found is to instruct DUB generate a project file for each of the Derelict sub-projects i want to use and put them in my solution. This means that i need to basically put extra unnecessary stuff in my project/solution just to use these libraries.

No. You just have to type dub generate visuald and all projects get generated. Type dub generate --combined visuald if you prefer to compile everything at once rather than by projects. The only line you commit is the line about "dependencies" in dub.json. That is pretty much the least you could do in any language. In C++ you would use cmake which is much less nice or maintain project files manually which is hell and doesn't work in teams.

So what could improve here? Simple: add the ability to define, download (not per-project/solution) and install DUB things directly from inside the project/solution settings in Visual Studio and have them applied automatically.

Good point. I've open a bug recently to have VisualD directly support DUB as it would allow that indeed. The current situation is already better than in C++ which has no package manager culturally. fyi, Mono-D directly supports DUB.

Another example would be showing the comments above declarations in a popup, like Visual Studio does for C++, especially since in D those comments are often used to generate the actual documentation.

Pretty sure it does that, though not all the time. Maybe only for DDoc comments?

1

u/badsectoracula May 22 '15

This would be absolutely the same in C++. To use OpenGL you typically use a pointer-loading library since the right function pointers are only available while the program runs after one (two for Modern OpenGL) context creations. There is no way to statically link to OpenGL nowadays, you have to load function pointers. Hence GLEW in C++ and Derelict in D.

You don't need any library under Windows to draw a spinning triangle with OpenGL in C++, assuming the compiler has the OpenGL headers (and almost all of them do). You do need to load pointers manually if you want to use any feature above OpenGL 1.1 (or if your header files are incomplete, although the only compiler i know where that happens is the first Borland C++ Builder that misses the functions -only the functions, not the constants- for textures), but for a spinning triangle (and tbh, for a lot of things - you can make a full 2D game engine with just GL 1.1 functionality and it'll be blazingly fast even on 15 year old hardware) that is just enough.

Personally i only used GLEW once when i wanted to do some quick and dirty shader test once a few years ago and was too lazy to load the pointers myself. Otherwise in all my code i load the pointers in an as-needed basis (i prefer to avoid using something if i don't really need it).

No. You just have to...

You just said what you quoted with different words :-P.

I do not want to use DUB (or cmake if that was C++) as my build system. Visual D has its own build system that integrates with Visual Studio and i want to use that because the whole "integration" thing i why i wanted Visual D in the first place and didn't used a generic text editor. Problem is, Visual D doesn't support DUB and from what i gather from the author's page, it doesn't look like it will be supported any time soon. The only way to use whatever uses DUB as its main (or only) way to build stuff is to instruct DUB to generate a Visual D project and then import that project in Visual Studio in my solution - hence adding unnecessary stuff to my solution instead of just pointing Visual D to the proper place and have it pick it up automatically.

Keep in mind that my comment was about Visual D specifically, not D in general, so what i'm commenting on is Visual D's functionality not what you could in theory achieve with other tools made for D.

The current situation is already better than in C++ which has no package manager culturally

C++ might not have one but there are some common practices per platform. Under Linux, for example, C and C++ libraries are commonly provided by the native package manager and custom compiled libraries have a configure script that puts them in the /usr/local subtree. Under Windows, most people provide .lib/.h pairs for Visual Studio which you can put in the project settings (or put in a common directory). Alternatively Visual Studio has Nu-get which allows you to download libraries per-solution (although IMO that is annoying and ends up with duplicates). For MinGW/Cygwin you can also use the Linux approach.

Pretty sure it does that, though not all the time. Maybe only for DDoc comments?

Just checked again, it doesn't do it. The comment starts with /** which i suspect is a DDoc comment.

1

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

You don't need any library under Windows to draw a spinning triangle with OpenGL in C++, assuming the compiler has the OpenGL headers (and almost all of them do).

Didn't know that. I've been an OpenGL developer in the past and only ever used pointer loading. But yeah I have a fair share of 1.1 code that still runs like a charm, to my surprise.

The only way to use whatever uses DUB as its main (or only) way to build stuff is to instruct DUB to generate a Visual D project and then import that project in Visual Studio in my solution - hence adding unnecessary stuff to my solution instead of just pointing Visual D to the proper place and have it pick it up automatically.

What I would do before DUB is adding filters and file manually to a solution. None of this automatic in C++ either. This doesn't change fundamentally with D libraries, pathes might be deeper but DUB is never required AFAIK. I'm happy just generating those project files nowadays instead of this.

Under Windows, most people provide .lib/.h pairs for Visual Studio which you can put in the project settings (or put in a common directory). [platform-specific things]

It's precisely different for each platform.

And maintaining projects files is not fun, at my last job we had 150+ projects, 8 configurations and I made a static analyzer to check .vcxproj and .sln file as nothing was ever in sync (think: is NDEBUG always defined in release configurations?). In the end someone made a build tool to generate all these projects and the transition will take years. To me it's pretty clear maintaining projects manually does not scale and DUB avoids all that.

→ More replies (1)

1

u/[deleted] May 23 '15

Just checked again, it doesn't do it. The comment starts with /** which i suspect is a DDoc comment.

For what it's worth, it does here. But at this point noone is reading us anyway :)

2

u/the_gnarts May 13 '15

For Rust, D, etc to have a chance at becoming popular they need to provide tools which are better than the current C/C++ tools

rustc’s error messages are doing it for me.

24

u/komollo May 12 '15

The best argument for why c/c++ will never die is that COBOL is still alive.

Also, there's the fact that for practically every single integrated chip, the c compiler is the first one tweaked to run on the chip. Literally almost every platform can run c, making it one of the only true cross platform languages. Then, there's the fact that c has a huge number of libraries and tools because it has been around for so long. Rust is going to take a long time to pick up enough steam to pass c as a systems language, if it ever does. If the c guys actually get their stuff figured out and they release an official upgrade to the language and fix some of the major complaints, it will pretty much end any chance other languages have of significantly displacing c in the next five years.

30

u/jeandem May 12 '15

Also, there's the fact that for practically every single integrated chip, the c compiler is the first one tweaked to run on the chip. Literally almost every platform can run c, making it one of the only true cross platform languages. Then, there's the fact that c has a huge number of libraries and tools because it has been around for so long.

Good thing that calling C from Rust and vice versa is zero-cost, then. Man, it's almost like the devs behind Rust had interoperability with C in mind, including leveraging existing C libraries. Instead of hoping to rewrite everything in Rust.

12

u/ancientGouda May 12 '15

Yeah, the author of the blog post completely missed this point. He worded it as if you eg. would have to rewrite the entirety of libvorbis in Rust in order to be able to use it.

3

u/komollo May 13 '15

Yeah, rust is well suited to work for c, and you can write new stuff in rust and continue to use old c libraries, but rust isn't trying to kill off c. Rust is ultimately trying to be a better systems programming language, but the fact that they've stressed c comparability means they don't have any illusions of killing c off any time soon. Levering existing libraries isn't going to help kill c. I like rust, and I'm looking forward to using it when it becomes more stable, but c/c++ is going to be around for a long long long time, and nothing short of the apocalypse is going to change that. (Relevant xkcd link goes here)

4

u/Nishruu May 12 '15 edited May 12 '15

Ohhh do you have any experience with that? Honest question.

I wanted to create a really simple Rust library that would (at least initially) expose just one function to C. That function would take an array of structures as a parameter, I'd initialize them, do some stuff and then filled array could be used in C. I honestly couldn't get it to work, the answer here doesn't work with Rust beta because (apparently) it's using unstable API.

So technically I'd have to somehow convert (Element *arr, int length) into (probably) mut array : &[Element]...

3

u/phaylon May 12 '15

I just tried the solution you linked to, and it works fine for me. Do you get unstable errors about the libc crate? If so, try adding a libc crates.io dependency to your Cargo.toml file. The libc that ships with Rust is not stable, the version on crates.io however is. (Newer rustc versions include this fact in the error message)

0

u/[deleted] May 12 '15

[deleted]

4

u/Nishruu May 12 '15 edited May 13 '15

Huh, thanks!

Unfortunately, when I compile your example (on Windows) I get:

error: linking with gcc failed: exit code: 1 note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-Wl,--large-address-aware" "-shared-libgcc" "-L" "C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib" "-o" "C:\Projects\Personal\ALR\target\debug\ALR.dll" "C:\Projects\Personal\ALR\target\debug\ALR.o" "C:\Projects\Personal\ALR\target\debug\ALR.metadata.o" "C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\libstd-4e7c5e5c.rlib" "C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\libcollections-4e7c5e5c.rlib" "C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\libunicode-4e7c5e5c.rlib" "C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\librand-4e7c5e5c.rlib" "C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\liballoc-4e7c5e5c.rlib" "C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\liblibc-4e7c5e5c.rlib" "C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\libcore-4e7c5e5c.rlib" "-L" "C:\Projects\Personal\ALR\target\debug" "-L" "C:\Projects\Personal\ALR\target\debug\deps" "-L" "C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib" "-L" "C:\Projects\Personal\ALR\src.rust\bin\i686-pc-windows-gnu" "-L" "C:\Projects\Personal\ALR\src\bin\i686-pc-windows-gnu" "-Wl,--whole-archive" "-Wl,-Bstatic" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-lws2_32" "-luserenv" "-shared" "-lcompiler-rt" note: C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\libcore-4e7c5e5c.rlib(core-4e7c5e5c.o):(.text+0x3ab4): undefined reference to rust_begin_unwind' C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\libcore-4e7c5e5c.rlib(core-4e7c5e5c.o):(.eh_frame+0x5c7f): undefined reference torust_eh_personality' ld: C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\libcore-4e7c5e5c.rlib(core-4e7c5e5c.o): bad reloc address 0x5c7f in section `.eh_frame'

I have to add at least a println!("") inside the loop. But even then, when I try to use it (in a 3rd party platform) I get stack overflow in ... DLL, oh well...

Anyway, I'll keep my eye out and thanks for pointing me in the right direction.

9

u/The_Doculope May 13 '15

It might be worth filing an issue over on the Rust issue tracker. Windows is definitely the platform with the worst support, so all bug reports are appreciated.

3

u/kibwen May 13 '15

Rust on Windows is still hairy sometimes, we're working on better integration with the native Windows toolchain as we speak:

https://github.com/rust-lang/rust/pull/25350

0

u/[deleted] May 12 '15

[deleted]

4

u/ChainedProfessional May 12 '15

Really? I thought most C++ programmers today were taught C++ in school and never really used assembly, like I did?

1

u/jyper May 13 '15

My school(Portland State) taught mostly c flavoured c++ for introductory courses but a tiny bit of assembly was taught in the 2nd year c courses along with details like the stack, int/float layout. We were only given a few tiny c hw problems. Also a tiny bit of assembly in the 3rd year hardware/OS class . And a tiny bit of disassembling assembly into a few java like language in the 3rd year compiler course.

5

u/[deleted] May 12 '15

I wonder what the COBOL programmers make of this. Hmmmmm...

16

u/bidibi-bodibi-bu-2 May 12 '15

LOL, anything pretending to be a safer replacement to C++ MUST BE faster than Ada at the very least.

21

u/kinghajj May 12 '15

Rust is faster than C++ in some benchmarks and slower in others. There's no obvious reason why it should be much slower; safe code has some extra checks, like bounds, but those in particular are usually avoidable with iterators, and others with unsafe blocks. The compiler just isn't mature yet, but it should get there. After 1.0 lands I imagine that will quickly become a focal point.

3

u/orthoxerox May 13 '15

Shouldn't Rust be able to verify that access is guaranteed to be safe at compile time and remove unnecessary bounds checks? Like, "i is incremented from 0 to n-1, the same n that was used to declare the array length, so a[i] has to be safe".

1

u/kinghajj May 13 '15

Maybe, but if you're really accessing it sequentially like that you can just use the Iterator API, which will inline the closures to produce code equivalent to the hand written C style loop.

2

u/badsectoracula May 12 '15

safe code has some extra checks, like bounds

So random access in arrays will always be slower?

EDIT: my mistake, i misread "safe code" as "unsafe code"

8

u/burntsushi May 12 '15

Only in safe code. If a benchmark says bounds checking is slower, than by all means, drop into unsafe and use get_unchecked.

3

u/badsectoracula May 12 '15

Ah my mistake, i misread "safe code" as "unsafe code".

2

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

So I have to call a function with two parameters and follow the returned pointer just to access an element in an array?

Edit: I think the problem is people are specifically pulling at C/C++ coders to switch to Rust, and we are many times in HPC, so we look at this stuff which seems insignificant to others. Before claiming Rust is "better", I need to know about how well the compiler will EVER be able to handle ILP/prefetching/etc. with its syntax, how to align memory allocations, SSE/AVX intrinsics, inline-assembly, etc. before I can make a switch. Every answer is "in the rare case you need unsafe code", well... for the C/C++ crowd that isn't a rare case at all.

6

u/arielbyd May 12 '15

The function is supposed to be inlined, of course.

5

u/rime-frost May 12 '15

In the rare event that you really need that incremental extra performance increase, yes.

In any case, somebody's already proposed syntax sugar for unsafe array access: arr[idx] becomes arr[unsafe idx]. If it turns out that unsafe array access is a really common operation, we already have you covered.

And raw-pointer arithmetic is starting to look like a shoe-in, so if you're writing a very unsafe program, you'll soon be able to define large parts of it using C-style pointers, and just write *(arr+idx) for your array access.

→ More replies (2)

3

u/[deleted] May 12 '15

Yes. The iteration api has no bounds checking though.

-2

u/doom_Oo7 May 12 '15

Well, you can always compile your faster Rust code, get the asm of it and insert it in an asm() function call in your C++ code, and tada, rust loses its edge :p

18

u/ChainedProfessional May 12 '15

compile your faster Rust code

and tada, rust loses its edge

So by using Rust, you're going to make Rust obsolete?

7

u/[deleted] May 13 '15

Brilliant! They'll never see it coming.

2

u/jeffdavis May 13 '15

I think the author misses the point about rust: it's not about safety and performance as about safety and control.

Modern garbage collectors are pretty fast. But they require extra runtime support, which means you can't link it in to arbitrary programs written in other languages, and you can't use it for kernel programming, or embedded systems.

6

u/ggtsu_00 May 12 '15

Kind of a biased point of view considering the blog comes from company whos paychecks rely entirely on a C++ project don't you think?

4

u/viraptor May 13 '15

From a company which exists because of programmers using a language which needs external static analysis tools, because programmers make so many mistakes...

8

u/TheBuzzSaw May 12 '15

I still believe that C/C++ can be "beaten". As others have said, they'll never truly die; we have absurd amounts of code already written in them, but I think it is quite feasible to create a new language that captures more mind share by supplying better tools.

Everyone needs to stop pushing this agenda that modern programming languages need to be "safe". We have a "safe" language ecosystem that lives in VMs. They are welcome to push that front, but a serious systems language needs to be pragmatic and useful. The problem with C++ isn't that it is "unsafe"; its problem is that it is extremely unsafe. There is too much undefined behavior and unclear semantics. There are too many features too.

To draw a real world parallel (yes yes, these rarely work, but stay with me), expert craftsmen use "unsafe" tools: sharp knives, heavy hammers, ovens full of napalm, etc. You don't see many (successful) efforts to completely eradicate dangerous tools. Rather, we see many products/improvements that allow craftsmen to safely handle these tools. Professional chefs will use sharp knives now and forever. Safety campaigns don't get very far on the platform of "well, many chefs cut themselves every year; we should just get rid of sharp knives entirely and come up with a safe sandbox for cutting food".

Everyone's favorite criticism of C is the buffer overrun. So, whenever anyone takes on the task of building a new language, safe array access is at the top of the list, and we are stripped of our ability to use pointers freely. Freedom of control is how we are able to make such fine tuned machines/engines! The answer is not to outright ban every unsafe thing; the answer is to grant more visibility into those operations. Empower the developer to monitor and analyze their code. Keep the syntax simple to where it can easily be emulated in a sandbox.

11

u/jeandem May 12 '15

Everyone needs to stop pushing this agenda that modern programming languages need to be "safe". We have a "safe" language ecosystem that lives in VMs. They are welcome to push that front, but a serious systems language needs to be pragmatic and useful.

And then in the very next sentence you complain about C++ being "too unsafe". Well, attitudes like yours are why there apparently hasn't been much progress in this area - "if you want safety, use a damn VM! A systems programming language can't be safe!" and so on. So what do you want? An incremental improvement? A slightly safer competitor to C++? But then people will complain that the new language doesn't offer enough benefits to switching to that language. Or should we just write everything that needs to be safe in higher-level, VM and whatever language? Right but we can't, because some domains require more control. And then we're back to where we started - implementing it in C++ and friends.

So what language is really "too safe" for you (you're kind of light on specifics, heavy on analogies)? And does it really have no escape hatches from that safety?

→ More replies (1)

6

u/The_Doculope May 13 '15

How many sharp knives have the potential to ruin companies, cause millions of dollars of damage, or kill unrelated people? Because software bugs can do those things, and that's why craftsman's tools are not a good analogy. Software bugs, in many domains, have far more serious consequences than a butcher slicing his thumb open.

The answer is not to outright ban every unsafe thing; the answer is to grant more visibility into those operations.

I can't tell if your post is in support of Rust or not. You seem to disagree with its goal at first, but then your solution in exactly what Rust does. It is safe in standard use, but all the low-level power of C is still there if you need it. Rust gives you the tools to use that power, and once you know you're using it safely to use it again and again without worry.

2

u/TheBuzzSaw May 13 '15

Because software bugs can do those things, and that's why craftsman's tools are not a good analogy.

Fair point. I still stand by mine though. If the fear of bad things happening is taken to its logical extreme, will developers be banned from writing assembly?

I can't tell if your post is in support of Rust or not.

I admire Rust and its goals, but generally, I'm against Rust. When I say I want my language to stay unsafe, I mean I don't want implicit bounds-checking on all my array accesses. I don't want separation of safe and unsafe code.

1

u/The_Doculope May 13 '15

I don't want implicit bounds-checking on all my array accesses.

Good thing you can use unchecked access or iterators ;)

I don't want separation of safe and unsafe code.

I don't understand this wish. Besides a slight amount of syntactic noise, what are the disadvantages of this separation? The gains are huge.

1

u/TheBuzzSaw May 13 '15

Because it's a systems language, and I want fast by default. You're trying to comfort me by pointing out that Rust has unchecked access, but I absolutely would be run out of any project where I insisted on writing copious amounts of unsafe code in a "safe language". Just because it can be done doesn't mean I'd make it very far doing it. I'd rather be in a community/ecosystem where my preferences are accepted.

I don't have a problem with there being safe languages. I certainly think Rust is a great idea, but I feel it should combat Java and C#, not C and C++. We use unsafe languages to build safe languages.

For what it's worth, I have many ideas for improvements on so-called safe languages too. (Allowing null in as the default was a huuuuuuuuuge mistake...)

3

u/dfgdfgvcv May 12 '15

I don't think this is really correct. Safety is absolutely needed. Generally any "real" attempt doesn't make it impossible to do any of these things, but merely makes the programmer explicitly say "it's okay in this case, I promise." And that's very valuable. It's really relatively rare that you need those ultimate control facilities. By making most of the code safe you already gain a lot of safety. You also make it far easier to find and fix issues by concentrating on the portions of the code making use of the unsafe features.

The answer isn't to throw the focus on safety out the window. That's the very thing we need. It's just silly not to include an escape.

1

u/TheBuzzSaw May 13 '15

Generally any "real" attempt doesn't make it impossible to do any of these things, but merely makes the programmer explicitly say "it's okay in this case, I promise."

My only problem with this mentality is that it adds a ton of noise to the syntax. I hate having markers throughout the code indicating I'm doing something on purpose. Again, I don't want the language deciding for me what I should and shouldn't do.

The answer isn't to throw the focus on safety out the window. That's the very thing we need. It's just silly not to include an escape.

This is why I bring up the extremes in language design. I agree that safety is good, and C++ is unnecessarily unsafe. There are many aspects that can be cleaned up without sacrificing an ounce of performance. However, I just don't agree with Rust's lifetime analysis and whatnot.

1

u/dfgdfgvcv May 14 '15

My only problem with this mentality is that it adds a ton of noise to the syntax.

It doesn't have to. Ada doesn't really address memory safety much, but in many other respects it is quite safe. The only real syntax used for escaping this safety is basically the use of an Unsafe prefix to just a couple things.

3

u/[deleted] May 13 '15

Everyone's favorite criticism of C is the buffer overrun.

Among a dozen others. The Obfuscated C Contest is a good reference.

Keep the syntax simple ...

Pascal and later Modula did that ... more than 30 years ago.

Rust however doesn't have a simple syntax.

4

u/[deleted] May 12 '15

People like to say C is a wrapper to asm, but it's really not. Some quick examples: it can't access memory segments/selectors directly, you can only access a memory location via a "type" so increments are "by sizeof type" rather than "by location", the ABI doesn't match the asm interrupt handler requirements, and lots of infix arithmetic turns into compiler intrinsic function calls behind the scenes. Compared to old 8086 asm in DOS, writing kernels in C feels so straightjacketed sometimes.

I'm really looking forward to the next language that tries to represent ISA's better, i.e. be able to write an entire kernel in it with no use of "asm {}" that could still work on say amd64 and ARM. Plus if it viewed memory the same way assembly language does, then the type system could be much better too: if you don't have to break the type system to access real memory as you do in C, then you might get "safe types" and auto-inference for "free".

It's a tall order but I think it's doable.

4

u/klug3 May 12 '15

People like to say C is a wrapper to asm, but it's really not

C is a wrapper to ASM, it just isn't a paper thin one.

2

u/josefx May 12 '15

and lots of infix arithmetic turns into compiler intrinsic function calls behind the scenes

Would that be the same arithmetic where the corresponding instruction (when it exists) produces a completely wrong result?

2

u/[deleted] May 12 '15

What do you mean by wrong?

Do you mean bugs like the Pentium FDIV flaw where the opcode doesn't do what the Intel reference manual says?

Or do you mean wrong where the asm opcode has a different meaning from the C language spec and the C compiler should have done something else?

2

u/TheBuzzSaw May 12 '15

you can only access a memory location via a "type" so increments are "by sizeof type" rather than "by location"

Is uint8_t* an insufficient workaround?

2

u/quzox May 13 '15

The real world analogy often uses cars: you can have speed or you can have safety. You cannot have both!

5

u/gimpwiz May 12 '15

I work in hardware development. Most of my code is firmware level, a bit of driver and application level.

Yeah, we use C and C++. They work. They work well.

Regardless of how great or not great rust is, I'm going to admit to not giving two shits until jobs start asking for rust experience or my coworkers start using it.

It's like every other language that people post about every day on this subreddit, without it actually showing up in real life. They might be amazing languages. But I won't care until they're useful to me, professionally.

20

u/Peaker May 12 '15

To sum up, you prefer to avoid learning as much as you can, and postpone it as late as you can.

I presume this helps with avoiding wasting time on various "fads". But if you're told that there are some interesting new concepts, why would you actively avoid learning? Learning is growing.

12

u/gimpwiz May 12 '15

I prioritize what I can learn and when. Right now, I'm learning how to build flash circuitry and how to process raw USB packets. Both of those are going to be immediately useful, and working with USB will probably stay useful for a long time.

As opposed to fad languages, which won't be useful now nor later. If they're proved useful, I'll learn - what's another language?

I think that actively avoiding learning things that turn out to be fads and go nowhere, apart from saving a lot of time, also prevents polluting the brain. It's like how we avoid learning anti-patterns, because then we just have to re-learn how to write things properly. I think fad languages are anti-patterns.

2

u/Peaker May 12 '15

I wouldn't worry about polluting the brain. If you have a good basis of knowledge, you can discern good ideas from bad.

Rust doesn't sound like a fad, it sounds genuinely insightful (safety without GC is a major idea worth learning) and brings various useful old proven ideas too, which are worth learning regardless of rust.

C++ requires learning an infinite amount of pitfalls and trivia. Rust is a much smaller and simpler language, so it shouldn't be a big investment to expose yourself to the interesting new insights.

6

u/gimpwiz May 12 '15

That's fair, and I respect your opinion. On the other hand, I suspect a lot of what makes rust smaller is fewer features, many of which I need and use. (That's the downside of hardware dev - you end up doing all sorts of weird shit.) What do you think?

→ More replies (1)

1

u/Steel_Neuron May 13 '15

I know this argument has been repeated ad infinitum, but I think it's worth stating it again because there's much more truth to it than it seems:

Learning Rust will make your C++/C better.

The closest analogy I can find is when you start taking private lessons after self-teaching yourself an instrument. You may be good, you may produce amazing music, but a good teacher will nevertheless find your weak spots and improve your abilities much quicker than you could.

The borrow checker is taking the role of that teacher for me. I still use c++ at work exclusively, but my c++ is getting significantly better thanks to Rust. I recoil in fear at some of my old code, now that the concepts of ownership and lifetime are starting to make sense.

1

u/F-J-W May 14 '15

Learning Rust will make your C++/C better.

That may be the case for some people, but it certainly isn't true for everyone.

Similar things have been said about Haskell and I strongly deny that this was the case for me (for a large part, because I was already using all those higher-order-functions in C++ and tried to use the type-system to it's limits).

4

u/quzox May 13 '15

why would you actively avoid learning?

I enjoy having free weekends where I can do fun things.

3

u/Peaker May 13 '15

I understand not having time to learn. It's different from being actively anti-learning.

2

u/fuzzynyanko May 13 '15

To sum up, you prefer to avoid learning as much as you can, and postpone it as late as you can.

I actually don't blame the guy. I've gotten caught up with learning something mainstream in anticipation that I'll use it, and never use it

1

u/Peaker May 13 '15

For learning nitty gritty details (like where to place your semicolons), what you say makes sense.

But when learning new concepts in new interesting languages, you greatly benefit whether you use it or not.

5

u/vatican_banker May 13 '15

TIL proggit is highly biased in favor of Rust. Almost everyone is ignoring the fact that Rust is sold as C/C++ replacement, but it is as slow as Java.

Some guy even goes as far as almost saying developers must learn every single programming language there is. Just because.

Developers like rationality. This is irrational.

Suppose I am to follow proggit's advice and I ditch C++ for Rust to write mathematical algorithms. Where the LAPACK equivalent of Rust? Where's the ARPACK? The article makes that point. There are almost no production-level libraries written in Rust. Heck, even if I google "list of rust libraries" I get links to Git pages, while if I google "list of c++ libraries" I get useful Wikipedia pages with huge lists of open and non-open source libraries.

The fact that you are discrediting the article's points just because the company makes a living selling C++ static analyzers is just bollocks. One can always find false arguments to bully down valid ones.

9

u/awo May 13 '15

I don't think many people are saying that Rust can replace C++ for all your needs, right now. They'd have to be pretty delusional, imo. The library and tooling ecosystem obviously aren't up to scratch yet, and work remains to be done on optimisation.

What people are saying is:

  • There's little about the language that stops compiled Rust code being as fast as compiled C++ code (except for often-avoidable bounds checking). It already often matches C++ code in real-world situations, and when it doesn't it's classifiable as a bug rather than a fundamental limitation.

  • Rust is a better designed language than C++.

  • Rust is an innovative and exciting new language.

In the near future, I would consider Rust for simple applications that aren't too dependent on a large library ecosystem. For myself, I'm mostly learning Rust because I find it interesting.

→ More replies (2)

7

u/[deleted] May 13 '15

but it is as slow as Java

I'd be genuinely interested in seeing the source of this statement, given that all benchmarks I've seen show excellent performance, close to C++'s.

2

u/vatican_banker May 13 '15

Well, they do link to the benchmark. You can find it here

6

u/[deleted] May 13 '15

Yeah except that in toy examples Java often get close to C++ performance. The problem is that for real world applications languages like C++ and Rust gives a lot more opportunities to optimize than Java. You can control memory layout to limit cache misses e.g. something which is impossible in Java without ugly hacks.

2

u/sellibitze May 13 '15 edited May 13 '15

These benchmarks only measure the current implementation of the language and the submitted toy programs. It's likely that, given the young age of Rust, there is room for improvement in both areas.

You should pay more attention to the design of the languages and what these designs enable and disable. For example, a language like Java forces lots of indirections onto you (every class-type variable is a reference and "larger objects" tend to be pointy data structures instead of one block of memory with inlined subobjects). Especially today, this is pretty bad due to cache misses costing more and more cycles. Data layout in memory is becoming more important. This is the kind of control that Rust retains.

The only two things that come to my mind where Rust is likely to perform a little worse compared to C++ are:

  • index bounds checking — safety comes first in Rust. So, this is not going away. However, if your profiler tells you that there is this particular loop that has a major impact on the overall runtime and you determined that you cannot afford index bounds checking in that place, you can write unsafe { myarray.get_unchecked(index) } instead of myarray[index] if you want.

  • C++ exceptions have no runtime overhead as long as no exception is thrown. In Rust error handling is usually done via return type Result<T,E> which requires a branch at the call site (unless perhaps the function is inlined). But Rust shares this "problem" with C and you wouldn't regard C as slow either.

Another thing that pops into my head w.r.t performance is that Rust has stricter pointer aliasing and mutation rules which allows for some compiler optimizations that wouldn't be legal in C++.

full disclosure: I've been programming C++ professionally for about 9 years and Rust in my spare time for about 1 year.

1

u/igouy May 14 '15 edited May 14 '15

These benchmarks only measure the current implementation of the language and the submitted toy programs.

That is more practical than measuring programs that have not been contributed using a future implementation of the language :-)

It's likely that things will change, just as they change for the other language implementations.

3

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

Oh, yes, I see it now.

But those are microbenchmarks; it would be more fair to compare those languages in bigger applications, closer to the real world.

There, Rust's monomorphisation, stack allocation of structs, the absence of a GC and the rarity of reference-counted pointers (in most cases you don't need them at all) will result in a massive performance gain over languages like Go or Java.

Most of Rust's features are designed with performance as a primary concern, and are compiled away. Exceptions include array bound checking and option unwrapping (I may be wrong here, though, but I'm pretty sure unwrapping doesn't compile to a simple pointer dereference since it panics if the Option is None).

To say Rust is slow when it puts such an emphasis on performance is not to have used it for much beyond Hello World, in my opinion.

1

u/igouy May 14 '15

But those are microbenchmarks; it would be more fair to compare those languages in bigger applications, closer to the real world.

It would be no more "fair" but could take a prohibitive effort to discover whether it was "fair" at all.

It could be closer to somebody's particular kind-of "real world" application, but further from other "real world" applications.

1

u/[deleted] May 14 '15

If somebody's kind of "real world" application is similar to the benchmarks posted, then the critical parts of the app are well-known and can be rewritten with unsafe if every cycle matters. Those are small enough for this to be perfectly reasonable.

By real-world application, I mean something that's bigger than these "tiny examples", as the page says.

→ More replies (1)

4

u/[deleted] May 13 '15

If I was writing mathematical algorithms I'd rather use Julia than suffer with C++ ;-) And unlike C++ is comes setup with all these libraries out of the box.

5

u/msiemens May 13 '15

There are almost no production-level libraries written in Rust.

Just like the original article you don't consider AT ALL that the 1.0.0 of the Rust compiler will be released this Friday. On the other hand, C++ has been around for more than 30 years.

0

u/vatican_banker May 13 '15

I'm glad that we found a common ground: there is no reason to seriously consider Rust now because its ecosystem is not mature enough.

Am I gonna use it in the future? Well, my impression is that the Rust community is very passionate (in the wrong way). I really wouldn't want to be part of it.

3

u/jeandem May 13 '15

If we're talking about the Rust community (like /r/rust), then most of them have warned people asking if Rust is "ready" or "can be used in a serious project" that it's not really recommended since it's still not stable. Do so at your own peril/frustration.

2

u/sellibitze May 13 '15

there is no reason to seriously consider Rust now

That depends entirely on the person. Early adopters obviously don't care that much about "been around for 30 years". Apparently, you're not part of the solution to the chicken and egg problem. And that's fine.

0

u/[deleted] May 13 '15

Where the LAPACK equivalent of Rust? Where's the ARPACK? The article makes that point.

No shit sherlock, they probably don't exist because Rust hasn't even hit 1.0 yet.

The point the article fails to make (rather conveniently) is that making a Rust wrapper for existing C libraries like CLAPACK or whatever else, is straight-forward. You won't have to rewrite everything from scratch, which is what the post seems to imply.

There are almost no production-level libraries written in Rust.

And so no effort should be made to develop these libraries so that they do mature over time?

Did C++ magically sprout thousands of mature libraries overnight when the language first appeared?

while if I google "list of c++ libraries" I get useful Wikipedia pages with huge lists of open and non-open source libraries.

Well that is kind of expected if the language has been around for 30-ish years.

The fact that you are discrediting the article's points just because the company makes a living selling C++ static analyzers is just bollocks.

The argument comes from the fact the the poster has a conflict of interests. The same way politicians have a conflict of interests when their campaign financiers "nudge" them to take a particular stance regarding some topic, even if this stance is not in the public's best interest.

Is Viva64 trying to save all us poor developers from the bleak future of Rust or are they trying to defend their bottom line?

-3

u/maep May 12 '15

I thought it made some valid points. But Rust is r/programming's current darling, hence all the down-votes.

20

u/eaurouge10 May 12 '15

Well, they make a living by selling a c/c++ static analyzer, I would be surprised if they published anything positive about rust. Original article (in russian) is published in author's blog and hugely criticized in comments by people who can provide more reasonable and viable arguments.

4

u/maep May 12 '15

I considered that but the article doesn't strike me as the typical FUD. He actually praised the rust static analyzer.

5

u/badsectoracula May 12 '15

On the other hand, because they make a living by selling a C/C++ static analyzer, they know their C/C++ better than most others.

4

u/BigPeteB May 12 '15

Well they're sure not sharing their knowledge very well. For a site called "viva64" that has an entire section of their website on developing 64-bit applications, I learned a lot less from their site than I did just reading man pages and StackOverflow.

3

u/k-bx May 12 '15

I disagree. JetBrains makes most money on Java IDE, yet their employees which I've read never force you to stay in Java (and they make their own language, and they love Haskell etc. etc.). I think it rather depends on a person, no what they do.

1

u/jeandem May 12 '15

What a vacuous comment. Your argument/contribution is that it made "some valid points" (which is..?) and that people are disagreeing with it because Rust is popular here. Like a reverse-appeal to popularity.

-1

u/maep May 12 '15

When I wrote that there were no comments and about ~40% upvote. I wanted to point out that I think many downvoted just because they disagree, which imho goes against reddiquette. "[Please don't] Downvote an otherwise acceptable post because you don't personally like it."

→ More replies (5)

1

u/[deleted] May 13 '15

I feel this post mainly missed the point. He was arguing against a straw man. Sure just like Cobolt, C++ can't be replaced over night. Cobolt is still with us but it has been made irrelevant in the sense that no new projects get started using it.

Lots of people who dislike C++ and express that vocally do this exactly because they DO have years of experience with using it in large projects. I would not have hated C++ so much if it wasn't for that fact that I had the displeasure of using it on large projects. C++ is not very problematic in small toy projects.

While there are lots of tools and practices which can help you maintain quality C++ code, the problem is that learning this is a huge task. Being a good C++ developer is a higher mental load than being a being good in several other sane programming languages. Lots of C++ simply don't bother investing the needed time to be good. Thus as long as you work on a large project rather than a toy project you will face the problem that a lot of the C++ you have to deal with is crap because the people who wrote it didn't have a clue.

Now crappy code is a problem for any language, but the issue with C++ is that it gives you far bigger opportunities to screw up your code. A language like Rust simply wont allow you to screw up your code to the same degree. That might not matter to you personally because YOU after all is a great programmer who learns his/her tools well. However the OTHER guy doesn't. With Rust even the other guy is forced to do something which has some minimum of sanity. And if he/she doesn't it is a lot easier to spot than with C++.

2

u/TheBuzzSaw May 13 '15

Being a good C++ developer is a higher mental load than being a being good in several other sane programming languages.

I dunno about that. I know you said "sane" languages, but considering PHP and JavaScript sit at or near the top of the most used languages today, we are forced to put up with the madness that is weakly typed value comparisons. C++ may be vast and low level, but I find it far more consistent in behavior than these ridiculous scripting languages.

-3

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

Just another typical ignorant person who got no chance to ever comprehend metaprogramming. He does not even understand how macros can work with a decent IDE.

5

u/[deleted] May 12 '15

[removed] — view removed comment

8

u/bcash May 12 '15

Rust has the same fallback option as the likes of Ruby and Python - just link to the standard C library that's been around for 20 years.

I can't see there being much of a shortage of Rust libraries after the initial ramp-up period. There are already 2000 libraries on crates.io

10

u/rifter5000 May 12 '15

LLVM is honestly a much nicer platform to build a language on than CLR or JVM.

1

u/[deleted] May 13 '15

Just out of interest, can you provide a few reasons as to why LLVM is a better platform?

1

u/rifter5000 May 13 '15
  1. You get JIT and AoT compilation for free.

  2. You get all the optimisations of a modern C++ compiler.

  3. You get very easy integration with existing native code.

  4. It's honestly just a really nice API to use. It's nice modern well-designed C++.

→ More replies (2)

3

u/pjmlp May 12 '15

And now with .NET Native and possible AOT compilation in Java 10, even better.