19 ms·
The Periodic Table of Rust Types
- carterschonwald 13y agoI think this a great way of presenting type features that interact! props to the author for cooking it up
- _pmf_ 13y ago> I think this a great way of presenting type features that interact! props to the author for cooking it up It's a great way to present it, but like Scala's infamous "Periodic Table of Dispatch Operators", stuff like is rather off putting. Why use crude sigils when you could just as well use easily understood keywords (like ref, out, unsafe etc. in C-Sharp)?
- Ygg2 13y agoFunny enough, ~ sigil will probably be retiring in favor of box. let x = ~"Thing"; //old code let x = box Thing // new code probably Note: I said probably because it's probably because: A) Not sure it will be implemented B) Not sure if that will be syntax --- PS. Any link to dispatch operator periodic table? Also I take your scala and raise you a Perl: http://glyphic.s3.amazonaws.com/ozone/mark/periodic/Periodic%20Table%20of%20the%20Operators%20A4%20300dpi.jpg http://glyphic.s3.amazonaws.com/ozone/mark/periodic/Periodic...
- noelwelsh 13y agoRe: the dispatch periodic table. This is from a library in Scala (a web client called dispatch) that was someone's first project in Scala and went very overboard on the use of operators. It is generally considered bad design. The Dispatch periodic table is here: http://www.flotsam.nl/dispatch-periodic-table.html http://www.flotsam.nl/dispatch-periodic-table.html
- modersky 13y agoJust to avoid any misunderstandings: The linked page is a (very nicely done) joke. These are not Scala operators, but (by now retired) operators of a particular third party library for Http dispatch.
- Djehngo 13y agoThat's a shame, I happen to like the use of sigils to denote pointer types, to my eyes it makes code a lot easier to read. Out of curiosity why are they making the change? And will they add the `let x = box Thing` syntax or as an optional addition to the language or will it fully replace the old `let = ~Thing` syntax?
- Ygg2 13y agoI think the idea is to make heap allocation taxing to type. Basically the sigil is too easy to type, so its easy for application to just allocates a whup ass of memory. So, this way it might force you to think about each allocation.
- andolanra 13y agoIt's nice to have very common features be syntactically lightweight, and sigils are incredibly lightweight compared to two-or-three character keywords. Rust code uses these pointers in all but the most trivial code, so they'll be showing up a lot; in contrast, I suspect as a non-C# programmer that ref and out are not as widely used in most C# codebases as ~ and & are in Rust. There are also not that many sigils, all told—three sigils for pointers plus a few other operators that appear in this table. Additionally, this table is different from the tables of Scala dispatch operators, Perl operators, &c because of its regularity—it has two axes and a good deal of the information presented is a straightforward function of a cell's position in the table[1]. For example, the entry in the Owned column and the String row is going to be an... owned string, which is going to be prefixed with ~ (like every cell in the Owned column) and have a base type of str (like every cell in the String row). This is a far cry from the table of Scala's dispatch operators, in which there's no consistent indication of what a given operator will necessarily do aside from a general grouping of like operators. [^1, edit]: That isn't to say that ALL the information is a (predictable) function of a cell's position in the table. Some of that irregularity comes from arguably expected consequences of Rust semantics (e.g. of course you can't have a bare string, because you can only have bare values whose sizes are known in advance, and you don't know how long a string will be) while some is genuinely arbitrary, like the syntactic sugar for functions.
- steveklabnik 13y agoAnd one of those sigils has effectively been deprecated, it's just & and ~ now. And ~ might turn into `box`.
- ehsanu1 13y agoMy understanding was that `box` would be for allocation, but type definitions still need to have the ~ sigil. But I could be mistaken.
- deleted 13y ago[deleted]
- dnautics 13y agocan we just make it "table"? There are no periodic trends that I can see.
- Dewie 13y agohttp://glyphic.s3.amazonaws.com/ozone/mark/periodic/Periodic%20Table%20of%20the%20Operators%20A4%20300dpi.jpg http://glyphic.s3.amazonaws.com/ozone/mark/periodic/Periodic...
- lifthrasiir 13y agoThat was my direct inspiration, though I suck at graphics design. Fortunately the periodic table of Rust types was much concise than that of Perl 6 operators...
- dbaupp 13y agoThere are some trends. Types to the right are "subsets" of types to the left; e.g. a &mut T can coerce to a &T, similarly, you can box a T into a ~T, or take references to get an &mut T or &T.
- dnautics 13y agoperiodicity refers to (originally) that the trends are cyclical with respect to atomic mass - we now know that it's with respect to atomic number and that the period increases (2 - 8 - 18 - much more) but nonetheless between multiple rows there's an increasing valence. Hence there is a repeating aspect 'period' driven by a connection between row n and n+1 (row n+1 immediately follows row n in atomic number). There's no connection between row n and row n+1 in this table of rust types. The vertical organization is completely arbitrary, there is no ascending value across the table, and therefore it's not periodic.
- TylerE 13y agoThis all seems like a mis-feature. Smells of C++.
- lifthrasiir 13y agoYou can make a similar table with C++, complete with pointer, pointer-to-member, function pointer, member function pointer, reference, r-value reference, array, std::auto_ptr, std::unique_ptr, std::shared_ptr, const and volatile. :)
- hdevalence 13y agoExcept C++ doesn't have, for instance, a way to mark data as immutable, so the table's going to be a bit lacking...
- Tyr42 13y agoErr, I'm a big fan of Rust and all, but I'm pretty sure c++ does have const and so on. What c++ lacks is a difference between owned and borrowed pointers, except by convention and so on.
- bzbarsky 13y agoC++ const doesn't actually provide constness for purposes of concurrent access unless you follow a bunch of other rules (no const_cast, no use of "mutable", no use of mutable class statics, no use of mutable file-level statics, no use of mutable globals) that in practice people violate all the time even with const objects.
- hdevalence 13y agoAh, but C++ "const" doesn't do what it says on the tin! What "const" means is not "constant", but "read-only". Something that's const to you might not be const to something else, so you can never depend on it staying the same. I may be wrong, but my understanding is that Rust's constants are actually constant, and proved as such by the compiler, which is a major difference over C++.
- noelwelsh 13y agoThis is great, and just what I needed to organise Rust types systems in my head. This should definitely be a part of the official documentation.
- deleted 13y ago[deleted]
- banachtarski 13y agoIf you don't need a systems language than for christ's sake don't use or learn one. Go use your go. shoo. Also, you care about syntax, others care about safety and correctness. It's not your cup of tea but no need to be all "this is a horrible language" crap. I dare you to have a face to face discussion with anyone on the development team and see if you'll talk so big then.
- deleted 13y ago[deleted]
- anon1385 13y ago>Go is also a systems programming language No it isn't.
- pcwalton 13y ago> Go is also a systems programming language so I don't know what you mean. I would like to use Go, yes, and I do when I have a chance. Go is a fully garbage collected language that doesn't offer a lot of support for manual memory management (and that isn't intended to attack Go—it just wasn't one of its goals). Rust is a low-level systems language that allows full control via zero-cost abstractions, but is safe. Achieving that goal requires some new machinery and syntax. Systems programming often entails writing for environments in which you can't use a GC (or even any runtime at all) for performance or other reasons. > Also your point about syntax vs safety and correctness makes no sense, since it implies that those are mutually exclusive so I'm just going to ignore that one. Rust has a unique feature—manual memory management with safety—so it needs syntax for it. It's not just syntax for its own sake—it's what gives the language a niche all its own.
- deleted 13y ago[deleted]
- didgeoridoo 13y agoAww, I thought this was going to be a table of metal oxides and their chemical & physical properties.
- mcguire 13y agoStructure types?
- steveklabnik 13y agoThey're of type T.