10 ms·
‘~’ is being removed from Rust
- batmansbelt 13y agoThat was one of my most used features. This stinks!
- steveklabnik 13y agoThe feature isn't going away, just the syntax.
- batmansbelt 13y agoOh thank Christ.
- lazzlazzlazz 13y agoRead before you post!
- steveklabnik 13y agoHere's a quick summary: Rust is adding a new capability, `box`, which is a superset of the existing pointer functionality.[1] Therefore, this special case is being removed, and, if it turns out that `~` is missed, sugar can be re-introduced to bring it back. That said, I don't think it will be. It's only really useful in function signatures, since types are inferred everywhere else, and `~` is harder to search for, as well as not on all keyboards. Plus, in Rust, you should always use stack allocation unless you absolutely have to, and so making heap allocation a little more weighty syntax-wise fits with the goals of the language. `~` -> `box` isn't that much heavier, either. 1: One way it's a superset: previously, only `~` supported 'placement new', and now, all pointers can with `box`. `box` also allows you to specify which allocator you'd like to use.
- phaer 13y ago> `~` is harder to search for, as well as not on all keyboards. Which keyboards do not have a '~' key? How do those people type a path relative to their home directory? Use $HOME/foo/bar all the time?
- jontro 13y agoMy swedish mac keyboard layout forces me to use Alt ¨ + space to type ~. It's certainly annoying and I usually just type "cd" first.
- pavlov 13y agoMany international keyboards don't have a tilde key. For example it's not shown on the Finnish/Swedish MacBook Pro keyboard at all. It's not difficult to type (Alt+¨ followed by a space), but you can't find it by looking at the keyboard.
- moogly 13y agoThat's a specious argument IMO. The same case can be made for the pipe/vertical bar character. So I guess they have to remove that from the language too so Mac users won't be mildly inconvenienced.
- jeltz 13y agoYou do not have to type a space though to get a pipe character. Tilde and backtick are the two characters which are hardest to write on a Swedish keyboard.
- moogly 13y agoI actually use a Swedish keyboard and I've never found these dead keys to be a problem myself. Vertical bar/pipe isn't shown on most European Macbook keyboards, nor is backslash in fact, so I guess backslash has to be removed too. I'm just saying it's not a great argument.
- steveklabnik 13y ago
- dengnan 13y agoDoes this change affects managed box? Or it only affect owned box?
- steveklabnik 13y agoYou'll allocate a managed box with let x = box (GC) 5; if my memory serves. The argument to `box` defaults to HEAP, so these are the same: let x = box (HEAP) 5; let x = box 5; And of course, boxing an integer is silly. This is just for illustration. The @ for managed boxes has been removed from the language for a while now. It's not technically gone because there's one or two instances in the compiler, IIRC, but it should be gone Real Soon Now.
- masklinn 13y ago> You'll allocate a managed box with let x: box (Gc) 5; It's GC in full uppercase FWIW, it's a static marker[0] not the type name. And the syntax already works in 0.10 (although funnily enough only HEAP and GC exist, no e.g. RC) > The argument to `box` defaults to HEAP, so these are the same: Yep[1]. [0] http://static.rust-lang.org/doc/0.10/std/gc/index.html http://static.rust-lang.org/doc/0.10/std/gc/index.html [1] http://static.rust-lang.org/doc/0.10/std/owned/index.html http://static.rust-lang.org/doc/0.10/std/owned/index.html
- steveklabnik 13y agoThanks, I've uppercased it.
- dengnan 13y agoThanks for the explanation! This change makes the code more clear to me. When I first read some rust code, those ~ and @ are annoying because I don't know their meaning and hard to search them for a explanation. The box keyword is a much better way for developers.
- steveklabnik 13y agoThank you. That's exactly our thought process too, though there is some reasonable disagreement about it.
- aidenn0 13y agoFor those reading, you need to read comments by "thestinger" very carefully. A lot of people respond as if he made the following two claims: 1) Recursive data structures are rare 2) Singly linked lists are useless When in fact he made these two claims: 1) definitions of recursive data structures are not prevalent in code 2) unshared singly-linked lists are not useful #1 is true since you define a recursive data structure only once, no matter how often you use it. #2 is slightly less obvious. One of the big advantages of a singly linked-list over other structures is that you can share tails with multiple lists. With unique ownership that advantage goes away. (There is still the use-case of loaning out tails, but that is a fairly weak argument). Another advantage of a singly-linked list is ease of implementation; that is negated when your standard library provides dynamic arrays and stacks already baked in.
- pnathan 13y agoFeh. It's an interesting split between what I'll call the concisionists and the explicitists. As a concisionist, this change stinks. I appreciate that the "not on my keyboard" argument is a big deal, but I'd argue that just merits a change of sigil, not adding verbosity. Designing a language to be prolix just makes code more laborious to understand.
- masklinn 13y ago> As a concisionist, this change stinks. There's two side to it: it makes creating unique pointers slightly harder, but at the same time it makes (unnecessary) overuse of unique pointers slightly harder/less likely, and that looks to be a concern of the core team. > Designing a language to be prolix just makes code more laborious to understand. Does it make the code more laborious to understand though? The concept becomes easier to search for and it's easier to talk about it (both because box/boxing is a term of art, and because "box" is a single syllable).
- cgag 13y agowords are easier grep for, but I'd rather read x = (2 * 2)/y instead of "x assign 2 plus 2 divide y"
- pnathan 13y agoThere's a nuance to point #2. The right amount of concision expresses the situation perfectly to someone skilled in the art, without requiring further reading to grasp or without requiring unneeded information to be waded through. (philosophy) A language should support concision to allow those skilled in the art to use their time effectively.
- mcguire 13y agoIs this a good time to point out that the language is stabilizing?
- bjz_ 13y agoIt shouldn't be a huge change for users of Rust - `~` is used far less than most people think.
- mcguire 13y agoIndeed. Most of the usages I've written have been ~[...] or ~str. I think both have drop-in replacements. (And if I had some bloody time, I'd update my code and find out.) This kind of change doesn't affect how you write code the way that the 1:1 thread/M:N model thing does. Note: I'm not laughing at you, I'm laughing with you.
- sanderjd 13y agoIt seems to me that the current focus on "do all the breaking changes we want to do so that we can get to 1.0" naturally leads to a prevalence of breaking changes. So in a strange way, yes, this sort of breaking change is evidence of the language stabilizing.
- Pacabel 13y agoI don't think we can really consider it to be "stabilizing" when there are relatively significant and breaking changes like this still going on. It may be headed in the direction of stability, but that's quite different from stabilizing. We can consider it to be stabilizing once the language and standard libraries have been frozen, and the only changes happening are very minor ones that are fixing critical bugs. Until then, it's still in the research and development stage, at best.
- sanderjd 13y agoI think "heading in the direction of stability" and "stabilizing" are the same thing. But pedantry aside, it does really seem to me that the breaking changes going on now are fundamentally different in character than those that used to happen - they are much less about experimental functionality, and much more about "let's fix as many of our frustrations as possible before we're stuck with them". For instance, the specific change under discussion would (I think) be fairly easy to re-add backwards compatibly, but probably impossible to remove. But meh, this maybe ours is a (boring) purely definitional disagreement - I think we can consider it stabilized once the language and standard libraries have been frozen and only bug fixes and minor changes are occurring.
- pornel 13y ago~ for allocation was weird, but I will miss lack of ~ as analogy to * . Will they change * to `RawPointer<T>` too? ;) I'm not happy about change of [T] to Vec<T> either. I hope all these changes will make a full circle and get a first-class syntax back.
- illicium 13y ago>first-class syntax Perl-y symbol nonsense is not a first-class syntax
- tormeh 13y agoI agree. Syntax should be descriptive first and concise second.
- tomjakubowski 13y ago> I'm not happy about change of [T] to Vec<T> either. [T] wasn't a thing in Rust. ~[T] hasn't gone and won't go away either. See this email from acrichton: https://mail.mozilla.org/pipermail/rust-dev/2014-April/009352.html https://mail.mozilla.org/pipermail/rust-dev/2014-April/00935...
- dbaupp 13y agoThat email is somewhat outdated. ~[T] is certainly disappearing with that syntax, becoming Box<[T]>, andthere has been much back and forth about whether this Box<[T]> type actually offers anything over Vec<T>, or if it's just a "cute" consequence of the type system. (The borrowed slices &[T] and &mut [T] are certainly here to stay.)
- lazzlazzlazz 13y ago> a first-class syntax back. I would argue that this change elevates the clarity and quality of Rust syntax.
- cmollis 13y agoI like this change.. 'box' is obviously more letters, but cognitively (for some reason) seems to enforce the operation better.
- moogly 13y agoI'll be honest: Rust is kind of losing me with these changes. I started following/tracking the language about a year ago, and I thought the syntax looked really succinct and easily readable back then, but with changes like this, [T] => Vec<T>, the region/lifetime syntax, together with the propensity to abbreviate almost everything, code is quickly starting to look kind of soupy to me. I get the arguments, and they're logically sound, but in the end it's beginnning to read like C++03. On the one hand, the Rust community's generalising a lot of stuff, which sounds great, but then adding a bunch of macros (I know, this ain't yo daddy's C macros) to replace first-class citizens ([1, 2, 3] => vec!(1, 2, 3) for example), and I worry how IDEs will be able to handle macros from an autocomplete/intellisense standpoint, not just checking/displaying type information when using them, but also writing new ones. I guess it's a language primarily by and for text editor users, and I'm beyond that point these days. As I said, I started following the language daily a year ago, and a couple of months ago I was thinking of jumping in around this point in time, but right now I feel like I want to wait another year to see if the syntax has become more readily intelligible. I still think it's a fantastic effort, and kudos for all the hard work.
- sillysaurus3 13y agoI guess it's a language primarily by and for text editor users, and I'm beyond that point these days. What do you mean? EDIT: Imagine a programming language designed around an IDE. Fun thought. Not sure whether it's a useful thought, but it's fun to think about.
- kansface 13y agoText Editor vs IDE.
- sillysaurus3 13y agoHmm... I don't understand why it has to be Text Editor vs IDE. The two concepts are orthogonal. One is for editing text; the other is for understanding and autocompleting text. If their concern is that there aren't any good tools for Rust yet, that'll be solved with time.
- ben0x539 13y agoGee, with this few sigils remaining, Rust is going to have a very hard time finding widespread adoption, since it won't stand out from competing languages!
- pcwalton 13y agoWe still have "fn". :)
- awj 13y ago..and since you're freeing up ~, you can now rename 'fn' to it. Rust criticism would drop to nearly zero, because everyone would focus in on your crazy function-defining-tilde and those people just don't get it.
- xiaq 13y agofn is my favorite keyword for function definition. "function" is too long. "def" doesn't say anything about functions (unless you read it as DEfine Function). "func" sounds too funny. "defun" always reads "defunct" to me. And just out of curiosity, where did the rust designers get the inspiration for "fn"? I know plan 9 rc and clojure have "fn". Or maybe it's independent invention?
- dbaupp 13y agoAnonymous functions in ML, possibly.
- pcwalton 13y agoWell, I slightly prefer "fun", but the Rust community pretty firmly favors "fn", and they're about the same anyway. As far as I know it came from ML.
- xiaq 13y ago"fun" is even funnier than "func"! ML etymology sounds pretty plausible (I didn't know ML uses fn) since I can see there is a strong influence of ML on Rust.
- Dewie 13y agoIs the comparison to Python that great? A language like Rust has more things that you have to keep track of yourself, as a programmer. Having English-like syntax might work great in a language with relatively simple semantics, but I don't think that it necessarily follows at all that that kind of design scales to languages where you have to be explicit on the level of pointer types and such.
- mattgodbolt 13y agoNot specifically related to this exact rust topic, but the interest in rust made me add support to my compiler explorer so you can tap rust code and see how it compiles interactively at http://rust.godbolt.org http://rust.godbolt.org
- dbaupp 13y agoThat's very cool; how do you get colourise to associate lines to the regions of assembly?
- mattgodbolt 13y agoI parse the debug line directives in the assembler output. Something about the way rust/llvm outputs with -O makes this a little worse than the equivalent in C++/clang but it's 'good enough' to get the gist of what's happening I think.
- dbaupp 13y agoOh, nice. Rust's debuginfo does seem to have a few peculiarities where lines numbers don't quite work out (or something, I haven't really been able to "quantify" it); but there's currently someone working on debuginfo.
- pbsd 13y agoNow that '~' is being removed for pointers, can it be used instead for unary bitwise NOT instead of '!'?
- eevee 13y agoWhat bugs me isn't the loss of this shorthand, but the decrease in shorthand overall. Punctuation and other built-in language features give me a baseline for what I can understand and what I can always rely on. If I see ~T, even if I don't know what it means immediately, I still know that it's part of the core language and will get me a step closer to useful understanding; here is a thing I can probably use to solve some problems. Moving as much of the language into a stdlib as possible is a worthy goal that makes for a "cleaner" and more "elegant" language (whatever those mean), but it vastly reduces this effect. The problem is that all of the core syntax and builtins are probably good to know, but not everything in the stdlib is useful. At least half of the stdlib for any given language tends to be worthless junk. Do you do Python? Did you know about the formatter module? popen2? asynchat? sunau? Probably not. But you almost certainly recognize 100% of Python's syntax and at least 90% of its builtins. Contrast with Perl, which (besides having a ridiculous amount of built-in syntax) relegates such basics as OO support into the standard library. Subclassing is done by using a library, and there are even two distinct libraries for doing it in the stdlib! So to understand Perl code, you have to understand a good chunk of its stdlib as well, but not all of it because a lot of it is weird obscure junk, but there's nothing telling you which bit is important because it's just a thing everyone knows. (And the reliance on third-party libraries to fill in gaps in the language makes this far worse.) One of C++'s major offputting properties is that everything is in a bloody library. (The other is that the features it does have all interact in obtuse ways.) You can learn what all of C++'s syntax does, and still be unable to make sense of real-world C++ code. I'd be pretty sad to see that happen to Rust.
- loup-vaillant 13y agoFrom thestinger: > Rust has strived to remove non-orthogonal features for a long time, and the language has been getting steadily smaller and simpler. Hereby avoiding the one mistake that made C++ so horrible: lots and lots of non-orthogonal features. It's not just a matter of being cleaner or more elegant. It's a matter of having less to learn. As for half the standard library being worthless junk… Rust probably won't be doing that mistake. If they simplify the language, they are likely to simplify the standard library as well, which means cutting the worthless junk out. Plus, it will likely be easy to use whatever is most useful: it will be all over the place in tutorials, manuals, examples, and of course actual code. > One of C++'s major offputting properties is that everything is in a bloody library. On the contrary, it's an assurance that you can implement bloody efficient data structures yourself, if the STL doesn't do what you want. This is what makes C++ a generally fast language: it's not optimized for special cases. > You can learn what all of C++'s syntax does, Most programmers can't. Experts do, but for the rest of us… C++ is impossible to parse, and has many, many, MANY pitfalls: http://www.yosefk.com/c++fqa/ http://www.yosefk.com/c++fqa/ Which is precisely what Rust is trying to avoid.
- kalail 13y agoHonestly. it feels like the language is losing something. I'm having a hard time identifying what that is, but I think it's something like the 'Rusty-ness' of the language, similar to how code can be more or less 'Pythonic'. The language is still in flux and there is only one way to find out whether we will miss '~'. Let's do it.
- 4bpp 13y agoOrthogonally to whether this is a good or bad idea, I really wish the PR and subsequent community management had been handled more carefully for something that was pretty much bound to be a very controversial change (tellingly, /r/rust even had a preemptive thread about it before it materialised: http://www.reddit.com/r/rust/comments/236plz/thoughts_on_removing_syntax/ http://www.reddit.com/r/rust/comments/236plz/thoughts_on_rem... ). Although I perhaps am in a bad position to complain after having been caught up in the less savoury parts of the exchange myself, I can't help it but believe that the often outright hostile tone and the swift wagon-circling by the proponents (in response to what they probably felt was an unreasonable onslaught of repetitive criticism) will have left a very bad aftertaste with a lot of readers. Much of this could have been prevented by preparing a clean document explaining the motivation and ramifications of the change to a general audience in advance, and perhaps by having the moderators apply some gentle pressure on the loose guns on either side to pipe it down.
- brson 13y agoThe OP is, in fact, that document. You'll notice this in a pull request to Rust's RFC repo. This change has been prominently brewing in the Rust community for a long time. The fact is that people have strong opinions about Rust and this is a critical time in its development - people are going to complain.
- 4bpp 13y agoYeah, I've read the document, and I would hope that most other people who proceeded to debate the topic did as well. I honestly don't think that it does a commensurate job of presenting the case for it (and after reading many of the comments by proponents, I certainly am under the impression that there is a strong case for it; I just still think the case against it is stronger). A lot of the comments also show widespread uncertainty about the silent assumptions; I, for my part, am still at a loss as to why something like Cons(1, ~Cons(2, ~...)) is not an interesting or common use case according to some proponents (not necessarily restricting the question to cons-cell lists - the invoked universal utility of sharing tails, for instance, seems far less universal across the practical use cases of many other data structures).
- ludamad 13y agoWhen will people get over syntax? It's a bit ridiculous how much time we spend fussing over ASCII considerations instead of working on novel ways to present code (making the manner it was written irrelevant).