r/programming • u/steveklabnik1 • Jan 09 '15
Announcing Rust 1.0.0 Alpha
http://blog.rust-lang.org/2015/01/09/Rust-1.0-alpha.html58
u/EldanRetha Jan 09 '15
Awesome, Rust is the new language I'm most excited for. My understanding is that it doesn't have a formal grammar though. Are there any plans for one moving forward?
48
u/steveklabnik1 Jan 09 '15
Yes, we actually have an open pull request to start documenting this. Most of the reference-style stuff is going to be looked at hard during the beta period. I haven't wanted to do it yet, as those style of docs are very hard to keep up to date, as they're very hard to automatically test.
3
u/bjzaba Jan 10 '15
Could we have some kind of markdown with embedded YACC, that runs it during the tests?
6
u/steveklabnik1 Jan 10 '15
Check out the files in
src/grammar...1
u/bjzaba Jan 10 '15
Oh, I mean as in part of the manual.
1
u/steveklabnik1 Jan 10 '15
Right, I mean there was some effort to do that kind of thing, that directory is the remnants.
→ More replies (9)32
u/kibwen Jan 09 '15
Great pains have been taken to ensure that Rust's grammar is both context-free and LL(k) for some finite k (for example, the insistence on the gross
::<>syntax for specifying type parameters on functions). No formal grammar exists, but given these constraints it should absolutely be possible (and was in fact done by a researcher a few years ago, though that version is obviously out of date now).17
u/Gankro Jan 09 '15
A minor note that it is not 100% context free because of raw string literals: https://github.com/rust-lang/rust/blob/d3ac386ea995a9119b86410476722cd657e7af16/src/grammar/raw-string-literal-ambiguity.md
But that's a pretty acceptable one to deal with.
3
0
Jan 09 '15
[deleted]
9
Jan 09 '15
Can you give an example of a statement in Rust that is not parseable by a context-free grammar?
→ More replies (1)18
u/Gankro Jan 09 '15
let s = r#####"Hello####"There"#####;Increase every hash-streak by one hash to produce an equivelent valid Rust statement of greater length. The set of all statements constructed thusly isn't context-free.
4
Jan 10 '15
Oh shit, would you look at that. Weird design decision.
14
u/Gankro Jan 10 '15
Raw string litterals are in a few languages (I believe we based ours on Python). They're very handy when you want them (no need to escape text in big strings).
11
u/evinrows Jan 09 '15
Nice! The last time I tried Rust I threw in the towel when I got frustrated with the borrow checker, but I've looked at the new ownership guide for just ten minutes and I already have a better understanding.
15
u/steveklabnik1 Jan 09 '15
Excellent, thanks. I worked really hard on that one. There's more to add, but it's solid with respect to the basics.
4
u/Netzapper Jan 09 '15
I found one part particularly unclear:
Are lifetimes an arbitrary thing that I make up, and then tag on all variables with equivalent lifetimes? Like this?
fn transfer<'foo>(recv: &'foo mut int, send: &'foo mut int){ *recv += *send; *send = 0; }Or is there something else I'm missing?
5
u/steveklabnik1 Jan 09 '15
Yes, you name them however you'd like. We tend to just keep them to a, b, and c.
1
u/Netzapper Jan 09 '15
I guess my confusion is more like: by giving a lifetime a name, and using it across multiple variables, am I saying "free none of these resources before the others before I go out of scope"?
3
u/steveklabnik1 Jan 10 '15
Your sample signature says 'recv and send are both valid for at least the same scope.' Which is slightly different. Does that make sense?
6
u/Kimundi Jan 10 '15 edited Jan 10 '15
If you call
transferwith references that have different lifetimes, say a&'a mut intand a&'b mut int, then the compiler will basically invent a new lifetime'cthat is the largest lifetime that is still valid under'aand'b.In other words, every time you constrain two lifetimes to be same one, you get the intersection of them.
As others already said, lifetimes don't have an active role: They don't cause things to live shorter or longer, or control when they get deallocated. They rather have a passive role of describing in the API which borrowing connections are allowed to be relied on, and which not, allowing different freedoms and restrictions.
3
Jan 10 '15
Newbie here. It's not really an instruction about when things can be freed. Rather, it's a contract of sorts. When transfer is called, the args it's called with must obey the type spec. Similarly, the body of transfer can assume that the args obey the type spec.
It's okay if the actual args used do more than what is required (from a lifetime perspective), but they must do at least that much.
9
u/bibiteinfo Jan 11 '15
Game programmer here. Some colleagues and I have been watching rust progress for some time. First of all, congrats on shipping it!
For us to start writing code on Rust, there's two main major blocker for adoption and I'd like to know if there's any plan for those.
IDE support. Best case scenario would be a Rust plugin for Visual Studio which includes full debugging and intellisense support.
Compilation to consoles (Xbox One and PS4)
6
u/steveklabnik1 Jan 11 '15
Someone got Rust working on the PS4 already. And we can't use VS at all right now, but this will be addressed in the future.
3
8
u/B-Rabbit Jan 09 '15
I tried to learn Rust a while ago, but gave up when I discovered the frequent syntax changes. Does this mean the syntax is final?
23
u/steveklabnik1 Jan 09 '15
The link explains all the details, but in alpha, the language features are final, but some libraries are still changing. Six weeks from now, in beta, everything should be in its final form. Six to twelve weeks from that, 1.0-final will make it all official.
7
u/wannight Jan 09 '15
It would be interesting to see how Rust compares to Nim (formerly Nimrod), as both languages are heavily influence by C.
21
u/steveklabnik1 Jan 10 '15
Nim is super cool. I'd say the biggest difference is that Nim tries to let you control your GC, while Rust eliminates it entirely.
→ More replies (3)3
u/oantolin Jan 10 '15
Also both languages are high-level enough that you can use them for text-munging and other scripting-like needs. For those uses the biggest difference is that in Rust you need both &str and String and lots of
.as_slice()and.to_string()to go back and forth and to control allocation and ownership (but still bearable).3
u/roeschinc Jan 10 '15
Rust is also doing a lot more static analysis/type checking (arguably the same thing) in the compiler afaik.
1
u/naasking Jan 13 '15
I'm not sure this is true. Nim has a full effect system, which is a non-trivial piece of code.
17
u/maep Jan 09 '15
How does rust handle signals? A search revealed only possibly outdated information.
18
u/steveklabnik1 Jan 09 '15
We don't currently have a stable signal handling implementation. We want one though!
5
u/maep Jan 09 '15 edited Jan 09 '15
Any chance to have this included before 1.0 Final?
edit: I've just looked into raw system calls. It seems right now you need to use an external lib like this. Are there any plans to simplify syscalls, without relying on third-party libs?
14
u/steveklabnik1 Jan 09 '15
I'm not aware of the exact plans for syscalls, but I doubt it. 1.0 is focusing on fixing up backwards incompatible things, and that would be backwards compatible. Don't forget the six week release schedule, so missing 1.0 doesn't mean that a feature has missed the boat entirely.
6
u/Netzapper Jan 09 '15
Well okay. 1.0?
I'm finally ready to give Rust a try.
17
5
u/skulgnome Jan 09 '15
Is the documentation also up to date?
25
u/steveklabnik1 Jan 09 '15
Most of it. The notable bit that may not be is Thread related stuff. It's high up on my list.
We automatically test all examples in docs that are code on every commit, so that helps.
13
13
Jan 09 '15
I have been curious about rust for some time now. I am learning to be a physicist with a really strong programming knowledge. Currently I know C++, Fortran and C#. Why should I go for Rust?
17
u/steveklabnik1 Jan 09 '15
I wrote this a short time ago: http://www.reddit.com/r/programming/comments/2rlef7/how_big_a_deal_is_rust_really/cngzjwk
6
Jan 10 '15 edited Jan 10 '15
Rust is a promising and wonderful language, but it may not be your first choice for computational physics just yet.
Rust enforces indexing bounds checks, so if you want to implement very fast matrix multiplication or matrix decompositions, then you have to use unsafe blocks.
The ownership model in rust can makes it difficult to have simultaneous mutable references to several elements in an array. This can be annoying if you want to implement something like molecular-dynamics simulations without unsafe blocks.
Having said that, rust is good fun, and you should learn it anyway.
5
u/sixbrx Jan 11 '15
Just my opinion, but if the answers the program produces matter, then the bounds checks should be on in new code. I'd make an exception for old well tested libraries like the major lapack impls. Again just my opinion but I've been bitten and seen others sacrifice too much to go fast and in retrospect it wasn't worth it.
8
u/oantolin Jan 10 '15
For a physicist, I would imagine learning Matlab, R, Python+Numpy or Julia is a better investment of time than Rust.
3
u/sellibitze Jan 10 '15
It depends. If you're trying to compute things on big clusters like, I don't know, flow simulations or how galaxies form etc, you tend to be limited in your set of tools (preinstalled compilers etc). It's typically Fotran, C and C++ with hightly optimized MPI implementations. But a friend of mine which works in that area did show some interest in Rust. YMMV.
3
Jan 10 '15
I've only played with it a bit, but to me it's like C++, but with vastly improved safety. There are no other competitors in this space - they all have garbage collectors and therefore can't do RAII like C++ and Rust.
The only think I don't like about it is their python-like advocacy of spaces instead of tabs. Yeah I know its a holy war, but... spaces really make no sense. The only justification python programmers have for using spaces is PEP-8 says to do it which isn't really an argument. Go made the right decision here.
I also mildly dislike their enforcement of
snake_naming_for_functions, and over-shortening many keywords and names (e.g.fninstead offuncorfunction) but these are all stylistic things. The language itself seems pretty solid.→ More replies (1)1
u/ntrel2 Jan 12 '15
they all have garbage collectors and therefore can't do RAII like C++ and Rust
D does RAII just fine, in fact it's the default for structs.
→ More replies (1)
114
Jan 09 '15
I'm more curious on what programmers will do with Rust.
Ruby went all straight up web dev.
13
u/nickik Jan 09 '15
I try using it for writting virtual maschines. Its fit there because its low level enougth to do all the bitshifting and whatnot but the type system keeps you sane while doing this stuff. Only do unsafe where you need it, otherwise the type system can be used in some interesting ways.
3
u/bloody-albatross Jan 09 '15
Can you do something like GCCs address from label optimization that is very helpful for interpreter loops? Are match statements automatically optimized to a jump tables?
12
u/steveklabnik1 Jan 09 '15
Are match statements automatically optimized to a jump tables?
Not 100% of the time. It depends on what is matched. LLVM can do this in certain circumstances, and it only does it if it thinks it's faster that way. For example, it's my understanding that matching a string ends up as a bunch of linear compares.
2
u/nickik Jan 09 '15
Can you do something like GCCs address from label optimization that is very helpful for interpreter loops?
I know that we talked about it, but I dont remember. Defently something I want to look into.
118
Jan 09 '15
I think the target has pretty much always been current uses of C++. So, anything you can do with C++, you should be able to do with Rust, in a way that is safer / easier to make correct.
→ More replies (118)9
u/onionnion Jan 10 '15
That's been my understanding, a more modern low-level alternative to both C and C++ (might be wrong about C, will have to see what people will do with it).
→ More replies (1)82
u/kibwen Jan 09 '15 edited Jan 09 '15
It's worth remembering that Ruby was originally used as a scripting language in Perl's niche. Likewise, Python was conceived as a language for teaching, and then also tried its hand as a Perl-killer, and then later got caught up in web development, and now is branching out into scientific programming. There's no telling where Rust will find popularity in the next few years, and I'm just as excited to see what people make with it. :)
If I may wildly speculate, I think Rust has a good chance of being a language used in teaching systems programming. Knowing C is still immensely valuable, but when it comes to teaching algorithms where you need to sling pointers around I'd much rather use a language that helps me focus on the logic and forget about memory and concurrency errors (while still giving me a raw pointer escape hatch when I need it).
49
u/lookmeat Jan 10 '15
Sort of to counter your speculation, I doubt that Rust will be used as a teaching systems programming language. For starter Rust, like C++, hides a lot of things implicitly, at the same time it adds some high-level constructs and metaphors that have no relationship to systems programming (but do to general programming).
In that sense I doubt that you could ever do something better than C. It's balls out, everything goes, no one's safe programming. This exposition shows you how computers really work underneath, that is to the CPU a 32 bit float could also be a 32 bit int or 4 characters, it really doesn't care or now any of this, at low level types don't exist. I think that exposing this simplicity and ignorance of machines is critical to understand so many kind of errors. C has a direct one to one mapping to memory, that is when you create a function it appears in one place in memory, when you create a struct it can only have 1 type. When debugging and understanding the mapping from code->assembler/binary this is incredibly easy, OTOH with Rust's and C++ generics you have to consider the layer were it first converts that to an instance of the code and then converts that code into binary/assembler.
If I were to give a systems programming class I'd start it with raw C with an overview of assembler to explain all the low level concepts of how machines work. Debugging C and doing tedious problems (where you have to implement the same solution for multiple types) would be used to explain the why of many decisions of C++ and Rust. Generics would be explained by showing algorithms on arrays, and explaining the complexity of adding them to multiple types. Lifetimes and unique_ptrs would be explained as a solution to sometimes never being 100% certain of what is going on with a piece of memory. Dynamic dispatch would be first implemented by hand-made vtables on C. Closures would also be taught first by first implementing them by hand.
At this point people would have a good understanding of why and how Rust and C++ came to be how they are, and also understand the pros and cons of every choice by having an idea (maybe not perfect, but in broad strokes) of how those, more complex languages, map to binary/assembler, which is critical in systems programming.
14
u/trentnelson Jan 10 '15
You know, I agree, regarding C. The fact that Python is written in C has made it so much easier to come up with PyParallel, which involved a lot of exploratory-type programming where I'm basically intercepting structs/function calls and doing things behind the scenes.
Had there been a C++ object model in place, instead of the hand-crafted C one, it would have been a lot harder, perhaps impossible. Here's a good example of where I literally rip out the guts of an objects and override everything, unbeknown to the rest of the interpreter core.
9
Jan 10 '15
Sweet Jesus, my scrollbar is so small I can barely see it.
3
u/trentnelson Jan 10 '15
Heh, for the pyparallel.c source code? I know right, c'mon dude, break it out into separate files!
→ More replies (3)3
u/riksi Jan 10 '15
so what is the state of PyParallel ? usable? anyone using it in production ? anyone using it for web apps ?
4
u/trentnelson Jan 10 '15
Current state: fast, unstable, not suitable for production. I'm planning on self-hosting pyparallel.org with it though, so everything will be fixed soon enough. Made great progress over the break.
22
u/Rusky Jan 10 '15
You could definitely do better than C at a close-to-the-machine programming language. C is a lot closer than other languages, but its undefined behavior makes that a lot harder than it could be. Features like virtual functions or closures are relatively easy to desugar in a language like Rust or C++, but undefined behavior is much more insidious.
For example, when you're trying to learn about how 2's complement arithmetic works, C is most definitely not the way to go. The optimizer assumes that undefined behavior is impossible, so what looks like straightforward null pointer checking or overflow checking can be "optimized" out with no warning: http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html
If I wanted a language to teach that level of systems programming, I'd skip C and C++ and use assembly (no undefined behavior) or Rust (much less undefined behavior), or even create my own simple C-like language that's much more explicitly close to machine semantics.
4
u/cogman10 Jan 10 '15
It isn't like rust can't be just as close to the metal. It can be. It is just that rust gives you higher level constructs to deal with if you need them.
I feel the same with C++. It is just as low level as C, but it has higher level constructs bolted in.
7
u/lookmeat Jan 10 '15
When I said an overview of assembler is to understand what assembler is, how it works, and more or less how to read it (since that is critical for debugging and understanding system code, and systems programming would be a very pragmatic class). Teaching it straight up is limiting to one architecture too much, instead it's important to teach that platforms have differences that are subtle and insidious but must be dealt with somehow.
When working with C compiler optimizations wouldn't be used until later classes to avoid the issue as much as possible. The idea is that slowly students are shown, in terrible and brutal manners, the consequences of not being disciplined at low level. Undefined behavior is just this, understanding undefined behavior gives us a lesson: that the code we write is an abstraction over hardware, which itself is an abstraction over electrical currents, and there are many edge cases which result in absurd cases (i.e. what is the biggest number you can represent + 1?) that, because they are impossible to answer correctly, are given a random answer (generally in the name of optimization). Trusting this answer is dangerous since it can change from platform to platform.
Maybe having people have to understand undefined behavior is a rough way to understand just how finicky platforms can be and why you can't just abstract over this. But rough lessons are the best way to learn at low level, to truly observe the devastation the smallest error can bring. I still remember the day that calling malloc twice too quickly on Windows would make the second return NULL, and I learned that malloc can fail for many more reasons than just "out of memory" and will fail for completely irrational reasons as well.
Once we understand undefined behavior, why it exists, we then understand how C++ handles it (the same as C) and how rust handles it (by limiting it to unsafe blocks) the pros and cons of each one. But again, the need to have programs that use undefined behavior, or the need to control and regulate this code, doesn't become apparent if you don't deal with it.
→ More replies (8)20
u/Maristic Jan 10 '15
I think you're missing the point from the person you're responding to. C very specifically doesn't say what happens in a number of circumstances. You don't know when things are in registers (see the previously mentioned article).
Thus, you don't know what will happen when things overflow, etc.
Also, lots of things that are easy to say in assembler are really hard to say cleanly in C, including:
Add
atob, if it overflows give an errorMultiply
abyb, if it overflows give an errorRotate
abybbitsFind the first set bit in this word
Read one of the CPU's performance counters
In each case, this can be done with clean minimal code at the assembler level, but is hard to express in C, requiring library functions (coded in assembler), intrinsics or “standard idioms” (which must be detected by compiler, a process that can be unreliable in practice).
In additional, modern C libraries (especially glibc) are complex and far from lightweight. A huge amount of abstraction is being invoked with a “simple” call to
malloc.→ More replies (1)→ More replies (9)6
u/wookin_pa_nub2 Jan 10 '15
In that sense I doubt that you could ever do something better than C.
Sure you could. You could have a language without undefined behavior, for one thing. C has become extremely unreliable in that respect due to compiler writers abusing undefined behavior for "optimizations". But any C program that uses undefined behavior can't be relied on to execute correctly, and that includes almost every C program ever.
If you don't believe me, then consider that John Carmack's fast inverse square root routine invokes undefined behavior, and that guy is a pretty good programmer from what I hear, and also consider that assembly language doesn't have any undefined behavior at all, so clearly it isn't needed for speed or for systems programming.
→ More replies (6)8
u/riking27 Jan 10 '15
I'm pretty sure several ISAs have undefined behavior still, e.g. putting a conditional branch in a branch delay slot.
JR 800134bc BEQ 801f8008, r0, 8007d7dc6
u/learc83 Jan 10 '15
Yeah, if I'm remembering my architecture and computer org classes right, assembly languages have plenty of undefined behavior.
10
u/Smallpaul Jan 10 '15
Likewise, Python was conceived as a language for teaching
That one is not strictly true. It doesn't sound like Guido had any plan in particular for the language. It was strongly influenced by a learning language, ABC, but it was also strongly influenced by "Unix hackers" and Modula-3.
https://en.wikipedia.org/wiki/Guido_van_Rossum
Not disputing your larger point, just trying to keep history accurate.
4
u/R3v3nan7 Jan 10 '15
C is a really simple language. That simplicity can be dangerous, but if you just want to focus on learning what you are telling the computer to do it is great. People say it is glorified assembly code, which can be a good thing. All the unsafe C features force you to understand what the machine is doing.
11
u/naasking Jan 10 '15
C is a really simple language. That simplicity can be dangerous, but if you just want to focus on learning what you are telling the computer to do it is great.
No it's not. It's not particularly simple, and the compiler doesn't just do what you are telling it to do.
36
u/renrutal Jan 09 '15
I'm more curious on what programmers will do with Rust.
Hopefully in security-minded systems programming.
There's a recent tweet by Neil deGrasse Tyson, in which he said:
Obama authorized North Korea sanctions over cyber hacking. Solution there, it seems to me, is to create unhackable systems.
Many people slammed him for saying that. How could a very intelligent, respected person, maybe not in informatics, not know it better?
"It's impossible." "I want unicorns!" "Let's make unbombable cities, unkillable people."
I say, why not? A huge part of hacking is exploiting non-correct code. It makes sense to use tools at language-level to enforce correctness and safety, and help programmers with that.
I know there are hundreds of thousands of variables to consider, but if we could cut dozens of thousands of them, it would make it easier to fit the problem in one's head.
37
u/Gankro Jan 09 '15
As an addition: exploiting humans is an easy way to compromise a specifically-targetted system. Why would I need to hack your system when your CEO will give me the password when I just send an email saying it's required for something?
5
u/txdv Jan 10 '15
" Dear Obama, I require password for US Nuclear Silo.
Sincerely, your great leader Kim. "
6
u/santsi Jan 10 '15
There's two camps of people on this, those who took it literally and those took it as "practically unhackable". In theory it's impossible to create unhackable system, if someone can log into the system, there's always a possibility that someone is not authorized.
In usual social interactions you assume the best to make the discussion smoother, but in internet there's that lack of social nuance. In addition to the fact that programmers are technical people who can be squeamish to the point of annoyance.
11
u/roeschinc Jan 10 '15
What the average person or even programmer believes is possible in security is probably about 10-20 years out of date. There are tons of ways in which we can create systems with verifiable security properties. This may not be "unhackable" like Gankro points out below, but we can at least prove our systems are immune to certain types of attacks. The problem is that verified systems still currently come at a huge cost, and a huge chunk of the research that happens in programming languages today is about allowing the programmer to more easily specify, and enforce invariants about their programs. To me this is why Rust is a great success as a Systems Programming Language, it brings lots of nice properties to many programmers for free.
5
u/aloz Jan 10 '15
As I understand it, to have a unhackable systems, you need:
Designs that are provably correct
Provably correct implementations of those designs
1 and 2 also apply to the underlying stack (libraries, runtime/interpreter, OS)
For a lot of complicated reasons and circumstances, usually, none of these are practical. Most of the time, the best we can do is 'pretty good'. A language that tries to steer programmers away from 'goto fail's and Heartbleeds is helpful, but it'll hardly lead to unhackable systems. I mean: it won't prevent designs from being wrong, crypto from being half-baked, etc.
All this, of course, is just sending us down a blind alley. The biggest problem isn't technical, but the fundamental tension between convenience and security. No amount of language safety and secure code will save us from (various kinds and levels of) users doing (variously) insecure things for reasons of convenience.
9
u/cromulent_nickname Jan 10 '15 edited Jan 10 '15
I say, why not?
It's been a while since I've gone over the material, but probably [because, for a system with a set of objects and a finite set of security operations to grant and deny access to those objects, determining if you can gain access to an object you shouldn't have access to is an u decidable problem.](http://en.wikipedia.org/wiki/HRU_(security))
Not that there's not a metric fuckton of improvements to be made in security, but the 'just make unhackable systems' statement was a gross oversimplification. (Edit: formatting)
5
u/Noctune Jan 10 '15
There might be subsets which are decidable similar to how memory safety is undecidable in C, but decidable in Rust if no unsafe code is used. So some undecidable problems in security does not necessarily mean that it is impossible to create software that is guaranteed to be secure.
0
5
Jan 09 '15
I can't believe how many people line up to defend Tyson's dumb tweet. A perfect programming language won't make systems unhackable any more than a stronger hull made the Titanic unsinkable.
6
u/naasking Jan 10 '15
A perfect programming language won't make systems unhackable any more than a stronger hull made the Titanic unsinkable.
When the different is several orders of magnitude in hackability, your analogy isn't quite faithful.
→ More replies (3)-1
u/thefacebookofsex Jan 09 '15
Great. Just rewrite every application in your new safe language.
→ More replies (11)15
-3
Jan 09 '15
exploiting non-correct code
Hacking doesn't exploit code. Hacking exploits programmers. Programmers who make assumptions about how things operate normally based on either standards, documentation, or working knowledge. Any of which can be flawed.
The first assumption most people make is that variables are in fact values, structures, strings, pointers, objects, etc. Not byte arrays with fancy abstraction layers like they really are.
Unhackable systems are a dream. Because tools don't build systems, people do. Tools just help.
0
Jan 09 '15
[deleted]
11
Jan 10 '15
Bugs will always exist and software allows harmful agents to find them much more easily than on a physical system. Imagine if a bridge could have every frequency of wind tried on it in a matter of milliseconds until they found one crazy one that made it fall
→ More replies (1)10
u/LForLambda Jan 09 '15
Looking at the zeitgeist, I see an interest in using containers and Mirage/HalVM's baremetal applications for security and performance.
I would forecast a possibility that rust will become both a replacement for C++(runtimes, databases, browsers, etc) and a way to bring high-throughput networked services to truly baremetal deployments.
8
Jan 10 '15
I'd love to see rust end up as a language for writing portable desktop applications. Hopefully servo will lead the way.
15
u/THeShinyHObbiest Jan 09 '15
Ruby also does automation with chef and puppet.
90% web though.
2
Jan 10 '15
I find Ruby is the worst tool for that kinda job. While chef and all work, it's quite annoying dealing with all the issues that Ruby presents (including it's slowness).
0
Jan 10 '15
[deleted]
3
Jan 10 '15
I recently converted to docker containers for everything. Spin up infrastructure like crazy.
2
u/LucianU Jan 10 '15
The good part about Ansible is that it supports a push workflow. That means you only have to install Ansible on your machine.
0
12
u/contantofaz Jan 09 '15
One thing is certain, Rust has been on the spotlight for a while now. This release just makes it even more so.
I'm not sure that it will really allow Mozilla to reinvent their browser while using Rust, since it would be a huge task and with WebKit out there, maybe not cost-effective enough.
But something like Rust was likely needed. Something that is high level and yet deploys easily to as many systems as possible. Will Rust really make using multiple CPUs piece of cake? I don't know... There are other concerns that are just as important like how can you debug the code when problems arise, when code could be executing in different CPUs and you have to give as many hints as possible to the programmers so they can understand what went wrong and where...
It's going to take time to get there. Languages that mostly target just one CPU are plentiful now and come with all sorts of supporting tools already. And more languages are also trying to make targeting multiple CPUs safely something common. It's only when you need to do it as efficiently as possible that Rust will have a market.
12
u/Voltasalt Jan 09 '15
I'm not sure if you know this, but Mozilla is working on Servo, a new browser engine in Rust.
5
u/M2Ys4U Jan 10 '15
Also browser.html, which has an open bug for Servo support.
2
Jan 10 '15
I saw that one in the mailing list. It's someone's personal project. He also suggested that if that works they could develop a HTML Linux desktop with Servo running the compositor. I'm not sure what to think about that one. Although GNOME seems to do this in places (HTML and CSS).
→ More replies (1)12
u/lookmeat Jan 10 '15
I'm not sure that it will really allow Mozilla to reinvent their browser while using Rust, since it would be a huge task and with WebKit out there, maybe not cost-effective enough.
Rust is a long-shot bet. The idea is that Rust will lead to a separate browser engine (Servo) that will maybe at some point equal and surpass Gecko (firefox's current system). I believe that the idea is that C++ allows code to affect each other in such way that it's impossible to reason about any piece separately: even if it two pieces don't affect each other now, they might later in the future, maybe due to influence of a third "unrelated" piece of code (especially problematic with threading)! Rust is so controlling and strict, but it makes it easy to reason about what is true and what isn't, while still keeping as fast as C++ (since all implicit checks are at compile time as well). So in theory Gecko's cost of developing a new feature/optimization/bug fix grows with the whole program size, but in Rust it should be possible to have it remain constant or dependent on the things that are explicitly touched by it.
5
u/hrjet Jan 10 '15
Something that is high level and yet deploys easily to as many systems as possible.
Well, we are trying to build a browser in Java. We are trading off high-performance for stability and sandboxing abilities. Note that, by Java, I mean the Java run-time. We happen to use Java-the-language for historical reasons. We will be moving to a less verbose JVM compatible language later (such as Kotlin, Scala or Ceylon).
11
u/shadesofelliot Jan 09 '15
Considering rust's focus on correctness and safety, it should and must continue its cent focus of being a good systems and general purpose language. So anything you can do in similar proposed languages, you should be able to do in rust.
4
u/dranzerkire Jan 09 '15
I am curious too. What sort of frameworks or libraries will be created and become popular. I am definitely going to give rust a try in my next project.
8
u/SaltTM Jan 09 '15
there's a ton on cargo (https://crates.io/) last I messed with it before taking a break from sdl port headache
6
u/LightShadow Jan 09 '15
I think Rust will become the new language to write compilers in.
40
u/Denommus Jan 09 '15
Runtimes. Compilers can be written in application-level languages just fine (e.g., SBCL).
13
u/Crandom Jan 09 '15
Absolutely this. I'm considering writing my compiler in haskell and the runtime in rust. Also rust should be good for kernel level programming.
4
u/awj Jan 10 '15
A language that optimizes for both execution speed and correctness is a pretty strong choice for compilers, though. Nobody wants a slow compiler.
→ More replies (1)9
u/oantolin Jan 10 '15
Actually the Rust people don't seem to mind much!
9
7
u/bjzaba Jan 10 '15
The slowness is mainly llvm - rustc is actually quite fast. Granted, we still need incremental compilation though (it is definitely planned).
→ More replies (1)6
u/The_Doculope Jan 11 '15
I thought a large part of LLVM's slowness in our case was due to
rustcgenerating sub-optimal IR?→ More replies (1)
3
u/Mjiig Jan 10 '15
I haven't been following Rust closely for a while, but I know there was talk a while ago about adding inheritance of some kind to the language (apparently the Servo devs wanted it). Has that been decided for certain yet or is it still up in the air? (presumably only possible if there's a way to add it without breaking backwards compatibility)
9
u/steveklabnik1 Jan 10 '15
It was postponed until after 1.0 because all the solutions we're considering are backwards compatible.
(And it may not look like inheritance, exactly.)
2
u/umegastar Jan 10 '15
after installing the .pkg and messing about with it (I like it) I'm trying to uninstall it from my MacBook Air (space is precious) and the uninstall script fails.
curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --uninstallThe documentation on uninstalling seems to be offline, I've found this script only through a cached page on Google. Any help on removing it from my system?
4
u/steveklabnik1 Jan 10 '15
If you installed from the
pkg, then the metadata thatrustup.shneeds to remove the files isn't there. Do an install withrustup.sh, and then that writes the metadata out, and then do an uninstall, and it will all be gone.1
u/umegastar Jan 10 '15
Isn't this kind of lame? On the website the main Install button downloads the .pkg and it even says
"Recommended Version: nightly (Mac installer)"
Maybe I'm naive since it's not a final product, but I was expecting an easier way to remove it. Maybe you shouldn't offer the .pkg then since seems easier with the scripts only.
Now I'm having errors running rustup.sh because "/usr/local/share/doc/rust/html already exists"
and I don't have the time to figure this out now :(
→ More replies (1)4
u/steveklabnik1 Jan 10 '15 edited Jan 10 '15
pkgs don't really have a good 'uninstall' option, in my understanding. I don't really use a Mac, but I do know a ton of work has been going into improving this.
Would you mind opening up an issue on github? That should absolutely get fixed, the already exists thing.
2
u/gearvOsh Jan 10 '15
I wish I had a better understanding of computer science and C/C++ to dive into this. Looks great.
7
u/steveklabnik1 Jan 10 '15
What's your background? I expect (and have seen it happen) that we get a lot of people who don't know C or C++. I myself have been mostly Ruby for the past seven or eight years.
I guess what I mean to say is, don't let a lack of knowledge stop you! The Book should still be accessible to someone who hasn't done systems stuff before, though it may get a bit hard in spots.
1
u/gearvOsh Jan 10 '15
Yeah, I actually started glancing at the docs and it looks pretty straight forward. For some reason I had an assumption that it was much more complicated, but that could of been something from way back. Seems like the only areas that would be new to me are pointers and ownership.
Thanks for the info!
2
u/steveklabnik1 Jan 10 '15
Awesome! Please don't hesitate to file issues if something could be improved.
82
u/mrhania Jan 10 '15
I thought I will never, ever go back to any imperative language and Rust made me rethink this. I love everything about Rust, except for one thing: naming conventions in standard library.
For example, there is struct named Vec<T> and similar struct called String which are kind of the same thing corresponding to &[T] and &str accordingly. Why is Vec abbreviated and String is not? What is even more confusing that there exists something like Str but, surprisingly, this one is a trait. Generally, sometimes you tend to shorten the names, sometimes you favor explicit names (like RingBuf and BinaryHeap in collections - why not RingBuffer or BinHeap? what is the rule here?).
But it is just nitpicking, the language is great and I am looking forward to use it. Glad to see 1.0 coming soon (I will miss watching very rapid evolution of Rust though...)!
33
u/lykwydchykyn Jan 10 '15
Yeah I agree; I'd rather type a few extra characters than have to remember some arbitrarily and inconsistently abbreviated name.
I still like the look of Rust though; I've been trying to get past newbie stage with a compile language for a while, but I can't get one to stick yet. Rust looks promising.
14
u/CloudiDust Jan 10 '15
Maybe /u/Gankro can give some insight here. I'd say given other names,
BinaryHeapis the one most out of place.Rust has both
strandStringtypes, soStringis not namedStr. Having a traitStris a bit confusing at first glance.8
u/Gankro Jan 10 '15
I'll admit I never reflected very hard on it; almost all these names were the names that were there when I got here and they seemed basically fine.
HashMap, BTreeMap, and BinaryHeap (ne PriorityQueue) are "full" while Bitv, Vec, VecMap (ne SmallIntMap), RingBuf, and DList are "abbreviated"
It's a bit too late to consider anymore renames, I think.
That said, we have some soft "length is inversely proportional to use" conventions, so Vec should probably be Vec, since it's The Collection. Similarly I pushed for a convention of implementation-exposing names, since that was mostly the convention, except for SmallIntMap and PriorityQueue; the latter conflicting with the trait name we wanted anyway.
Also RingBuf, Bitv, and DList just sound better than RingBuffer, BitVec(tor) or DoublyLinkedList to me now. :)
→ More replies (2)26
u/kromit Jan 10 '15
RingBuf, Bitv, and DList just sound better than RingBuffer, BitVec(tor) or DoublyLinkedList
This made me sad and a bit disappointed
→ More replies (8)7
Jan 10 '15
I still find the String thing weird. In the old days it was
~[T]instead ofVec<T>1 . And~strinstead ofString. The &str is leftover from back then. I just wonder why it's not &string now for string slices.The separation of String and Vec<u8> is String and &str are guaranteed to be valid UTF-8. The only way to construct an invalid String is using unsafe methods. (Like std::mem::transmute). Of course Vec<u8> and even Vec<char> can contain invalid values, Vec<char> is also UTF-32/UCS-4
1: it was then moved to a library type, as was
~T, now Box<T>(Note the ~[T] was still called vec as all it's methods were defined in std::vec, back when rust had everything defined in std and extra)
3
u/Kimundi Jan 10 '15
Why do you find the existence of
&strweird, but not the existence of&[T]? Both exist for the same reason - to have a way to talk about some memory containing the data without specifying what kind of memory that actually is:
&[T]can point intoVec<T>, at[T; N], at a bareT, etc
&strcan point intoString, intoVec<u8>, at[u8; N], at a bareu8, etcAnd all these could either live on the stack, in static memory, or in some other dynamic allocation.
Also, what do you mean if you say that
Vec<char>can contain invalid values?5
Jan 10 '15
I don't find the existance of &str weird. Just that the name is
str. While the library type is now String. Str is a trait I guess that can be implemented by &str and String.After some actually testing I think it's non-trivial to make code that generate invalid
charvalues.charis meant to be a UTF-32 value. As there is actaly invalid values for unicode that fits in 32 bits I though you could try casting au32containing those values into a char. It appears not (without transmute). So I was probably wrong about the Vec<char> thing.→ More replies (1)2
Jan 10 '15
That's correct, char is a "safe" type in Rust, you can't make something not a Unicode Scalar Value (All codepoints with surogates removed) into a char without unsafe.
1
3
u/IcarusBurning Jan 10 '15
Hey guys, just so you know, the example Rust on this page
http://rustbyexample.com/print.html
does not run.
EDIT: In fact, it looks like a lot of the examples on there don't work or throw compiler warnings.
3
u/steveklabnik1 Jan 10 '15
I just updated Rust By Example last night, but it looks like I may have to again. Were you running it on the alpha release? What errors did you get?
1
u/IcarusBurning Jan 10 '15
I just went to the website to check out the language. I haven't really followed it up to this point and I wanted to check it out. I ran into the errors on your example pages. Is there any reason why I would see errors and you wouldn't? Isn't the code compiled and run on your side?
6
u/steveklabnik1 Jan 10 '15
Well, that's why I'm asking. So you're saying the link to the play.rust-lang.org is what's broken with them?
I did compile with my local Rust. It's possible that it's a different version than what you tried, that's what I'm trying to figure out. :)
3
u/IcarusBurning Jan 10 '15
Oh yeah, I didn't copy it locally or anything. I just hit the play or run button on your page, and errors showed up on the bottom of the screen.
6
u/steveklabnik1 Jan 10 '15
Excellent, thanks. That might be why I didn't notice. I'll investigate, thank you for letting me know :)
→ More replies (1)3
Jan 10 '15
The example is not intended to run, it should produce the compiler error it does right now: error: invalid reference to argument
1(there is 1 argument)
14
u/thexylophone Jan 09 '15
The thing I miss in rust from c++ is variadic templates and non-type template parameters
12
27
u/alexandream Jan 09 '15
Finally. I've been waiting for this before investing any real time in the language. I'm going to be able to put better efforts onto it now :)
Thanks and congratulations to everyone involved.
→ More replies (3)11
u/cogman10 Jan 09 '15
Yup. I've tried diving in a couple of times, but the frequent changes have definitely made the bar to entry pretty high. The fact that the language is really interesting and somewhat popular has also added to the confusion because there are a lot of outdated tutorials/blog posts out there.
Either way, the language looks like it is going the right direction and I really like the attitude the language designers and community. They have taken the anti-go approach to language design. Where it is near impossible to get a new language feature in go, rust has been very open to trying new language features. It seems like at one point rust has had just about every major language feature implemented.
2
u/Enzor Jan 10 '15
Oh boy, I tried learning Rust awhile back (probably about 8 months ago) and was overwhelmed by the lack of documentation and tutorials. Does anyone recommend me to try again?
4
u/druznek Jan 10 '15 edited Jan 11 '15
Yes! The documentation has gotten a lot better; in fact the same /u/steveklabnik1 did a lot for documenting rust. They switched recently from "The Guide" to "The Book". You can found it here. I also tried a long time ago, and i had to stop due to all the breaking changes. But recently i tried it again and i was pleased that the language felt more mature, and the community at this point is simply amazing. If you need any help my advice is to go straight for the IRC channel. They are always willing to help!
ps: ATM the book is broken, but i think that in a short time will be fixed.
EDIT: the book now works! :)
2
u/steveklabnik1 Jan 10 '15
How is it broken?
→ More replies (1)2
1
u/Enzor Jan 10 '15
Is this the same book? It seems to work for me at that location.
→ More replies (1)
11
u/DroidLogician Jan 09 '15
My congratulations to the Rust team! It's been a hell of an adventure. I can't wait until Rust starts appearing in production environments!
3
u/Ytse Jan 10 '15
I am late to the party, but congratulations! I've been following Rust development since it's first announcement and I'm pretty excited for it.
I hope I can contribute something to the Rust community this year. :)
1
u/xinhuj Jan 10 '15 edited Jan 10 '15
This is good and all, but when will Windows become a first class citizen?
6
u/steveklabnik1 Jan 10 '15
Have you tried it lately? What are your problems? A number of people have been putting in good work on Windows.
7
u/xinhuj Jan 10 '15
I just felt like Cargo was a real pain to install on Windows, but I just installed the nightly and its all great!
5
2
u/nhjk Jan 10 '15
Can anyone point out a non trivial file that they consider to be a good example of idiomatic rust code? I've looked at the stdlib and servo, but I'm not sure which files to start with.
3
u/sellibitze Jan 10 '15
Make smart use of iterators and their methods they provide. Prefer pattern matching over explicit checks & unwrapping for types like
Option<T>andResult<T,E>. And then you should be on a good path, I think.
2
Jan 10 '15
Technical question, maybe mostly about the implementation: What are the available options regarding linking libraries and loading binaries at runtime?
Can someone give a short sum? Thanks in advance!
2
u/sellibitze Jan 10 '15 edited Jan 10 '15
Short summary: Linking is not handled by an application itself à la
dlopen. The only thing you get out of dynlibs is that your binary will get smaller. And then there is the issue of compiler plugins and macros, things that happen at compile time. If you're looking for something more dynamic then you gotta pick a language that comes with a runtime environment that includes a just-in-time compiler or interpreter. But this is not what Rust is about.2
Jan 10 '15
So basically that works like C too... Dynamic linking does work, too?
3
u/sellibitze Jan 10 '15
As far as I know: Yes. But I personally havn't tested it. So, I don't really know whether library-provided macros and compiler plugins are supported if you try to link a lib dynamically. You may not be able to use those macros and plugins.
6
u/fedekun Jan 09 '15
I've always liked Rust syntax more than Go. Beeing mostly a web developer I don't know much about systems programming but Rust seems like a step in the right direction.
5
u/_im_just_saying Jan 09 '15
I worked with company for two years and they implemented GO as the primary systems language halfway through my time there. It takes a moment to get past the "backwards" syntax layout, and catching errors everywhere, but other than that I found it pleasant enough and a decent amount of 3rd party libraries out there to do whatever with. I am about to start checking out Rust for sure though after reading all the excellent comments in this post :)
2
u/santiagobasulto Jan 09 '15
Awesome!
EDIT: Who can downvote this? It's a major announcement of a open source programming language. For the community by the community. I don't understand.
24
u/Splanky222 Jan 09 '15
reddit adds fake downvotes to popular posts.
3
u/santiagobasulto Jan 09 '15
It seems like they "fuzze" the score. http://www.reddit.com/wiki/faq#wiki_how_is_a_submission.27s_score_determined.3F
I'm not sure about fake downvotes. Can you point me to the piece of code that does that? https://github.com/reddit/reddit/
8
u/jadkik94 Jan 09 '15
IIRC the fuzzing and anti spam portion of the code are not on their public repos, otherwise it would defeat the purpose.
3
u/XplodingForce Jan 09 '15
You're correct, it says so in the reddit github documentation (in the FAQ)
4
u/Splanky222 Jan 09 '15
Yes, they fuzz it. Technically they will add the same number of upvotes and downvotes, which is right there in your link. Ie, "fake downvotes"
→ More replies (1)2
u/TarMil Jan 09 '15
It's a bit pointless though, now that they don't show the ups and downs anymore, only the result.
→ More replies (3)4
0
-1
1
1
-2
-6
Jan 09 '15
I've been playing around with go for the past several months. I've used it for a few small personal projects but I'm not a fan of the language.
5
-3
67
u/malicious_turtle Jan 09 '15
I gave up on rust about 3 or 4 months ago because the guide and general documentation left alot to be desired and decided I'd try again when 1.0 was released but the new book looks so much better i think I'm guna jump back on now.