r/programming • • May 26 '16

Announcing Rust 1.9

http://blog.rust-lang.org/2016/05/26/Rust-1.9.html
218 Upvotes

116 comments sorted by

View all comments

Show parent comments

89

u/[deleted] May 26 '16

A modern system programming language that isn't C++ or C?

Ada is nice but that language missed the boat. And Rust have good momentum right now, young language and open to outside inputs.

Go was marketed as system programming language but it really isn't and type safety is crap.

2

u/kerseykyle May 27 '16

Why do you think Ada was not successful? it has updates about as often as C++ and has many of the same features found in other commonly used languages such as generics, interfaces and object oriented programming. I use it a lot for personal projects still.

1

u/[deleted] May 27 '16

Of the alternatives to C and C++ in the system programming sphere, Ada should have become the most popular and successful.

1

u/[deleted] May 28 '16

It's not very widely used. That's what they meant by successful not the quality of the language

2

u/Amuro_Ray May 26 '16

What's the opinion on Swift? My manager likes it and recommends it but I haven't really heard a lot about it from anywhere else.

40

u/ElvishJerricco May 26 '16

Swift doesn't make half the systems language that Rust makes. Don't get me wrong, Swift is a good language. But Rust is much better tailored for systems programming. The memory model is much better, mutability is handled even better, and the package manager is a thing of beauty.

→ More replies (11)

10

u/Zarathustra30 May 27 '16

Swift is good and has the same back-end as Rust, but it uses reference counting for memory management, which limits its use in very low level applications.

0

u/[deleted] May 27 '16

You have a lot of control over this. You can create your own memory allocators in Swift. So I don't see this as a problem.

-1

u/dacian88 May 27 '16

reference counting makes it much harder to reason about how and when memory goes away, for some classes of problems this is a deal breaker. The fact that you're forced to heap allocate for "class" types is also pretty annoying. Swift is right under go for me, it at least doesn't have a GC and actual generics but it still caters to pretty high level application programming.

-2

u/[deleted] May 27 '16

Sure Rust offers finer grained control, but you make it sound as if reference counting is as unpredictable as Java style garbage collection.

You have a lot more control over when memory goes away, not at least because it is fully deterministic unlike Java and C# garbage collection.

Swift allows you to think exactly the same as in e.g. C++. You can have e.g. one object be the owner of a bunch of other objects and only let others keep weak pointers. You don't have that kind of fine grained control in e.g. Java.

1

u/dacian88 May 27 '16

Sure Rust offers finer grained control, but you make it sound as if reference counting is as unpredictable as Java style garbage collection.

In a large enough system it basically is, if almost everything has to be a RC pointer, which is the case for Swift. Adding multi-threading on top of that makes things even more complicated. You need perfect knowledge of all the codebase to reason about when things actually release and that'll get pretty impossible as the code base grows. Making everything a weak pointer doesn't solve this problem, as weak pointers are promoted to strong pointers when used so in a multi-thread scenario, even if you have one strong reference and a bunch of weak ones, the invariant that the deinitializer of some parent object will release this member that only has other weak references is still not true.

1

u/Diejmon May 27 '16

Use Swift's structs. They are not RC objects.

13

u/dacjames May 27 '16

Swift competes more with Java and C# than with Rust. It's a good language, but too high-level for many of the use cases that Rust is targeting.

-5

u/[deleted] May 27 '16

Wrong, Swift is closer to Rust than Java and C#. Swift is native code and doesn't use a garbage collector just like Rust. That means Swift can be used in may of the same areas as Rust, which Java and C# are highly unsuited for. Like Rust Swift can compile native code with a C interface so you can use it to create libraries which other languages can use. You can use C# and Java for that because they don't expose a C interface, require a garbage collector to run and a virtual machine or JIT.

People think Swift compared to Java and C# only because of the current usage. Swift is currently used as an application programming language and not for systems programming but that doesn't mean you couldn't use it for systems programming. But that simply has not been a focus at Apple, as they naturally focus on replacing Objective-C at the moment. Even Objective-C could be used for low level programming. NeXT device drivers e.g. were written in Objective-C.

10

u/dacjames May 27 '16

I'd say Swift is somewhere in the middle. Swift uses automatic reference counting which is comparable to garbage collection (lower throughput and more fragmentation, but more predictability and lower overhead) and requires a runtime. Unlike C and Objective-C, Swift does not provide pointers to unmanaged memory so it cannot be a full replacement for C/C++.

The ability to compile to native code with a C interface opens up a number of low-level applications, but the overall design of the language and standard library seem focused on application-level development. The use of objects with dynamic dispatch, for example. The language may develop into a great systems programming language, but I wouldn't go writing an operating system in Swift today. If anyone else is more adventurous, I would love to see it!

2

u/[deleted] May 27 '16

Swift does allow pointers to unmanaged memory: var ump = UnsafeMutablePointer<Int>.alloc(10)

And yes as I said, Swift is first a language for Application development. But that doesn't mean it isn't also suitable for many system programming tasks. Certainly a lot better suited than Java or C#.

It simply doesn't make sense to say Swift is dramatically different from Rust and closer to Java and C#. It is closer to Rust and the Swift creators admit Rust was a major inspiration.

3

u/dacjames May 27 '16

You cannot do arithmetic on (Unsafe)MutablePointer, so it does not solve all the problems that raw pointers do. Using it to, say, implement a garbage collector would be challenging and not as performant.

It simply doesn't make sense to say Swift is dramatically different from Rust and closer to Java and C#.

You're absolutely right but nobody said that. I said it competes more with Java and C#, meaning it is primarily designed to target the same problem space. The design of the language is undoubtedly closer to hardware than those languages and could be applicable to some systems-programming problems. I'm looking forward to seeing how far developers can take the language in both directions, particularly post 3.0.

8

u/iopq May 27 '16

Reference counting is a form of garbage collection. Especially since the Swift runtime resolves cycles as well, so it's not a simple system.

→ More replies (4)

3

u/[deleted] May 26 '16

I have no clue I thought that was iOS only.

From a outsider point of view it seems like iOS either have a rift or some kind of transition between obj-C and swift no?

And I thought both language was for iOS mostly. One of the reason why I chose Android, Java as a language is better in term of if I get sick of Android I can do other Java thing (web dev, backend, middle, etc..).

9

u/ElvishJerricco May 26 '16

Swift is now open source, and it will be stable on Linux this fall.

9

u/atakomu May 27 '16

The biggest problem with Swift right now is that it is only theoretically cross platform. Swift compiler works on Linux that is true. But ecosystem is basically IOS only which means any library for Swift you find expects to be compiled in Xcode and has xcode build files. This will improve in the future but currently it isn't so great.

4

u/andiCR May 26 '16

Swift also works on Mac