3 ms·
Here'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 be
by steveklabnik 13y ago
Here'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 agoCheck it out: http://en.wikipedia.org/wiki/Tilde#Keyboards http://en.wikipedia.org/wiki/Tilde#Keyboards
- masklinn 13y ago> Which keyboards do not have a '~' key? Most euro keyboards need at least AltGr + key, possibly 2 keys (because ~ is a dead key, so a space is needed to insert the character itself) > How do those people type a path relative to their home directory? Use $HOME/foo/bar all the time? It's common to `cd; cd foo/bar`
- luchs 13y agoThese keyboards usually don't have a convenient way to type {}[] either, these are AltGr + number keys in the German and French layouts for example. The keyboard situation doesn't seem to be as bad as for the degree sign °, which doesn't seem to be typeable on an English keyboard at all.
- simlevesque 13y agoFrench layout keyboards do have a convenient way to type {}[], for me with Canadian French it is under 7890 using alt.
- Solarsail 13y agoFrench Canadian keyboards are fairly different from European French keyboards: French Canadian: http://www3.uakron.edu/modlang/french/images/kbd4.gif http://www3.uakron.edu/modlang/french/images/kbd4.gif European French: http://www.fentek-ind.com/images/frenchkeytop.gif http://www.fentek-ind.com/images/frenchkeytop.gif
- dbaupp 13y agoNot being able to type those symbols causes problems with almost all programming languages (i.e. programmers are likely to have customised their keyboards for those symbols), but ~ is really only a major problem for Rust (and maybe bit-fiddling in C).
- kps 13y agoIt is not 1974, and people are not limited to typing the characters molded into the type wheel and keytops at the factory. At the moment, it's as easy for me to type × or † as it is to type + or _, and I would happily make it as easy to type λ or ← to get the benefit of reading code as such. The situation with ~ is simpler; it's used by plenty of programming systems today, and any programmer who uses it and can't type it as easily as on a default US keyboard (i.e. with one modifier+key press) is not using their tools effectively.
- ksenzee 13y agoI rarely use ~ for my home directory, and I type on a US keyboard. ~/ is three inconvenient keystrokes; cd<Enter> is three convenient keystrokes.
- 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.