10 ms·
Rust via its Core Values
- bogomipz 11y agoCould someone explain this - "Ruby also protects you from segmentation fault errors. But to do so it uses a garbage collector."? How does GC protect you from a segfault? Surely trying that doesn't help you when you attempt to access the 5th element of an array with only two elements. Maybe its just confusing that the author used that as an example. I'm guessing aside form a dangling pointer GC doesn't offer much protection form a segfault?
- catnaroek 11y agoOf course, garbage collection per se doesn't protect you from segfaults. For example, there exist garbage collectors for C. They reclaim unused memory, but you can still cause segfaults if you want to (or are careless). Automatic memory management (whether done at runtime with a garbage collector, or at compile time as in Rust) frees you from logical memory errors by making them inexpressible. But automatic memory management doesn't guarantee that segfaults won't happen - it only guarantees that they won't matter to the programmer. For example, a garbage collector could deliberately trigger segfaults (by `mprotect()`ing all managed memory) to forcibly pause the mutator during a garbage collection cycle. Every managed thread must install a `SIGSEGV` handler that waits until the collection process is done.
- bogomipz 11y ago"For example, a garbage collector could deliberately trigger segfaults (by `mprotect()`ing all managed memory) to forcibly pause the mutator during a garbage collection cycle. Every managed thread must install a `SIGSEGV` handler that waits until the collection process is done." Interesting, is this actually a common implementation pattern for languages that have a GC built into their run time?
- catnaroek 11y agoNo idea. I haven't read the source code of any serious, production GC. I've only written toy ones.
- samth 11y agoI don't think the exact thing you describe is common, but plenty of garbage collectors use memory protection to implement the write barrier. This is particularly useful when integrating with arbitrary code you don't control, since it will also be affected by memory protection.
- barrkel 11y agoA segfault implies a pointer to an unmapped page in memory. An array out of bounds error isn't the same class of error. The former implies that what pointers can point at isn't constrained; instead of pointing at unmapped page, it could point at the inside of some sensitive data structure (think: web response buffer pointing at database credentials). The latter implies that indirections are checked; this is a very different guarantee.
- bogomipz 11y agoThanks, could you explain the "indirections" in this context? I haven't heard this before.
- barrkel 11y agoArray accesses are implicit indirections. The base, index and element size are used to compute the address of a location which is then indirected to store or load. Without range checking, array accesses can be used to read or write arbitrary locations in memory, just like pointers.
- bogomipz 11y agoAh ok right, that makes perfect sense. Thanks.
- rntz 11y ago> I'm guessing aside form a dangling pointer GC doesn't offer much protection form a segfault? Correct. By using GC and banning free() you avoid use-after-free bugs, but not out-of-bounds accesses. Out of bounds accesses have to be forbidden in some other fashion; most languages do bounds-checking and throw an exception rather than trying to access the memory and getting a segfault (or, worse, reading some random other object's memory).
- bogomipz 11y agoThanks
- abritishguy 11y agoI like this a lot, it's always tempting to think that we can create a perfect language that would be the best in all situations but we can't. Rust is great for projects where its values are valued: - Speed - Memory Safety - Concurrency Go is great for projects where its values are valued: - productivity (from being able to immediately understand a new code base due to the small and simple language to the toolchain it provides). - concurrency Likewise, Ruby and Python are great choices for some projects.
- Scarbutt 11y agoProductivity in Go is an illusion but I see the appeal of it for big enterprise teams composed of disposable programmers.
- catnaroek 11y agoNo complaints about the meat of the article, just with two introductory remarks: > For example, Ruby famously values Developer Happiness and that value has impacted Ruby’s features. Really? Every time I give Ruby another chance (admittedly, not too often), I end up feeling angry. I can stare at five lines of code for several minutes, and have no idea what it will do. Not even Haskell. > Ruby also protects you from segmentation fault errors. But to do so it uses a garbage collector. This is great, but it has a big impact on your program’s speed. Is garbage collection the main culprit? Not duck typing? Not dynamic metaprogramming? I reckon performing a hashtable lookup during every single method call has a bigger effect on performance than garbage collection.
- pcwalton 11y ago> I reckon performing a hashtable lookup during every single method call has a bigger effect on performance than garbage collection. Well, a high-performance Ruby VM will perform inline caching to mitigate this. And if the VM isn't a high-performance VM (i.e. it's interpreted), then the overhead of the interpreter dispatch loop dominates everything.
- catnaroek 11y agoI'm admittedly not very familiar with compiler backends - especially not JIT compilers. But how does this optimization even work if I'm constantly modifying the method tables of objects at runtime? If I understand correctly, ORMs and Web frameworks for dynamic languages do this sort of thing all the time.
- cwzwarich 11y agoIn a JIT for a dynamic language, you generally have to predicate your more aggressive optimizations on some runtime condition, e.g. "this variable is actually an integer", or "this object has the same method layout as other objects did before". These conditions are checked before relying on the optimization, and if they fail, the generated code jumps into a runtime that may decide to use an interpreter, generate deoptimized code, etc.
- Animats 11y agoThis should be titled "A Ruby programmer looks at Rust". There are now a very large number of programmers who have zero experience with anything below the level of a scripting language, and have never had to think about memory allocation. To them, Rust is rather intimidating, and this writer is trying to make it simpler. Unfortunately, it looks like he doesn't really understand borrowing. The key idea of borrowing is that a borrowed reference can't outlive the thing it came from. It's a lifetime thing, not an immutability thing. Go is a hard-compiled language compatible with the mindset of scripting language programmers. That's just what Google needs. They have a lot of server side code to write, and it has to go reasonably fast or they have to build additional acres of data centers. With Go, they can put programmers from the scripting language community on the job.
- nickpsecurity 11y agoYour analysis is good except that last part. Google hires tons of geniuses who could handle Rust easily with a bit of training. The extra efficiency would reduce datacenter requirements even more. Most of their tools are also internal where scripting community has minimal contribution. So, I don't see a clear benefit for them to choose Go over Rust except saving face. They'd be better off investing in both for various reasons with critical stuff like F1 RDBMS in Rust and rapid dev in Go.
- arto 11y ago"The key point here is our programmers are Googlers, they're not researchers. They're typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They're not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt." -- Rob Pike (http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2014/From-Parallel-to-Concurrent http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2014/Fro...)
- gnuvince 11y agoYeah he said that, but presented no evidence to support his claim.
- vaibhavkul 11y agoMaybe this is off topic, but while reading this article it occurred to me that wouldn't it be useful if the ownership transfer is syntax highlighted? e.g. in let new_owner = original_owner; println!("{}", original_owner); we could have original_owner on the second line have a different color signifying it doesn't own anything. Or, does such a syntax highlighter already exist?
- kam 11y agoAtom with linter-rust highlights compile errors: http://i.imgur.com/ac7FTpW.png http://i.imgur.com/ac7FTpW.png Or do you have a more specific visualisation for moves/ownership in mind?
- vaibhavkul 11y agoDidn't know about linter-rust. Thanks for sharing. It didn't occur to me that: ownership transfer means variable cannot be used, so if it's used means there's an error, so checking for error itself gives you the information that you cannot use it. So highlighting error can be used instead of the specific ownership transfer. I don't know of any other specific cases where there's no error, but it would be helpful to have a different color for certain ownership semantics.
- kazagistar 11y agoThat syntax highlighter would basically have to be attached to a compiler. If a type is Copy, then it follows move semantics instead of copy semantics. Plus, ownership can be transferred through things like method invocations as well, depending on the type signature of the method.
- nv-vn 11y agoA bunch of languages are moving towards integrating IDE tools into the compiler with some kind of API. This allows for on-the-fly type checking, better syntax highlighting, better autocompletion, automatically generating bits of boilerplate, instantly testing a block of code, etc. For a language with a great example of this, check out Idris's IDE protocol: http://docs.idris-lang.org/en/latest/reference/ide-protocol.html http://docs.idris-lang.org/en/latest/reference/ide-protocol..... The way this works helps create an awesome feedback loop where the editor _is_ the REPL. Something like that would be a great addition to Rust and would definitely help improve the overall tooling for the language.
- dschiptsov 11y agoMixing some C++ into Standard ML is not necessarily a good idea, like mixing a bit of shit into a bucket of honey.
- andrewvijay 11y ago"Of course, Rust developers also wants people to write programs in Rust. So we can declare things to be mutable if we really need to." - I laughed so hard on this more than I should have :D Really a good one!