Microsoft to Explore Using Rust
zdnet.com
zdnet.com
> C#, a programming language developed by Microsoft, also features some memory access improvements but is not as advanced as Rust. [..] Besides [Rust] being superior to C# in regards to better memory protections
That's false, isn't it? C# is a memory safe language, period. It relies on GC for that.
In fact C# has arguably better memory safety than Rust because you can do things safely in C# that you would be forced to use 'unsafe' in Rust for. (Granted, then you have overhead from GC, but that's not what the author is talking about.)
> Rust is also more popular with developers these days and might be easier to recruit for.
The author has misinterpreted what "most loved" means in the quoted survey: it means that among Rust developers, it gets a very high rating. That says nothing about how big that group is, nor how popular it is in the general population of developers.
The Rust community is growing but still very small - it's an emerging language. Almost everyone that uses it decided to use it because they like it. (That doesn't diminish the accomplishment - there are other emerging languages that are not as loved by their users.)
It's quite possible that what the author intends by “memory protections” is broader than what is captured by “memory safety”; e.g., the borrower checker is, in a sense, a way of protecting memory from unexpected changes in parallel tasks.
It is definitely false for the author to say Rust is "superior to C# in regards to better memory protections", in any definition of "memory protections".
Or, did someone prod a journalist with little familiarity in programming theory, to write positive "spin" on Rust being explored by Microsoft? Is it even news for the world's largest software company (by market cap), to explore the use of emerging languages?
I missed the part where whether the author used words and, if so, which words they were was a matter of controversy.
That's the part you cited, and went on to imply the author might be referring to Rust's borrower checker. Nothing from the author's "wording" implies knowledge of Rust's memory protection techniques
See this example where I break encapsulation in a struct by abusing a race condition:
https://github.com/VictorGavrish/MultiThreading/blob/master/...
Could you provide an example? I thought pretty much everything could be achieved, albeit sub-optimally with reference counting (data structures).
The original post's whole sentence there is basically nonsense. They're different enough that it's hard to call either one more advanced or having better memory protection at all.
Using just plain C#, it has better memory protection, since the GC and runtime make it impossible to leak, double-free, or access out-of-bounds. But there's a higher cost for that, and the system for managing non-memory resources is not as reliable - you can leak file handles, network handles, etc more easily. Not up on the latest in Rust, but I think it's possible to leak memory if you are sufficiently clever and doing really weird stuff. But the standard ownership model is great at making it really hard to leak or mismanage any resource, not just memory.
It's hard to call either one more advanced either. .NET has a massive std lib and C# has been getting some cool new features. It's still a runtime language though, with the limitations that come from that. Rust's lifetime and ownership system is pretty advanced, but wouldn't make sense for a runtime language.
Note that Rust provides an easy way to intentionally leak memory, unlike many other languages: https://doc.rust-lang.org/std/mem/fn.forget.html
`Box::leak()` leaks memory.
This is false.
Neither C# nor Rust protect from memory leaks. There are actually some gotchas in C# that can cause memory leaks - for example, you have to be very careful about events. Memory leaks are not memory unsafe, though.
On the topic of actual memory safety - C# has unsafe blocks just like Rust does. Safe Rust is just as safe from memory safety problems as safe C#, even more so, because C# doesn't require unsafe for FFI, where all bets are off. And unsafe C# is just as unsafe as unsafe Rust can be.
In Rust you can leak due to reference cycles for example: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
C# will clean up reference cycles, but an unintended reference can cause leaks (if you forget to remove it).
In both languages such leaks are not good, but at least they aren't memory safety issues.
The only gotcha that can cause memory leaks in C# is a GC root, i.e. referencing something on a stack, that is static or that is pinned. Events/delegates are not special in any way, they are simply a reference footgun because it's non-obvious that they contain a reference to the object that contains the handler.
Ah, that is also false. A GC makes a language safer, but it does not protect against race conditions, so it is not entirely memory safe.
Of course, many languages that are referred to as memory safe have this loophole, but that may also be due to there not previously being a concurrent language with suitable protection in this area.
It's definitely true that this does not imply thread-safe, and the ability to prevent the mess up the consistency of valid objects.
This is absolutely false. Race conditions in native structures can very easily invalidate any memory safety guarantees provided by the language, causing issues such as buffer overflows.
In other words, the presence of any memory unsafe operation leads to a total and immediate loss of all memory safety.
See for example how races in Go can lead to type confusion for interface types (fat pointers) through store tearing (non-atomic writes): https://research.swtch.com/gorace or https://groups.google.com/forum/#!msg/golang-dev/mXjFejQ5A3Q...
The former has a detailed explanation, the latter has a code example that shows more clearly what the technique can be used to do (cast a struct A to unrelated struct B with different length, thus allowing out-of-bounds reads/writes).
If on the other hand you were just saying that these languages are just called memory safe, even though they aren't, then yes. That's what I said.
https://msdn.microsoft.com/en-us/magazine/mt814808.aspx
https://docs.microsoft.com/en-us/dotnet/api/system.span-1?vi...
The MSRC article says:
>in a new blog series we will highlight Microsoft’s exploration of safer system programming languages, starting with Rust
so it appears the zdnet author misinterpreted this to mean it hasn't started using it yet.
As an example, https://github.com/Azure/iotedge had its first Rust code checked in in February 2018.
MS has also already been contributing to Rust and LLVM to get it working on Windows ARM32 and ARM64.
There are several azure services running at least some Rust and job descriptions for IOT stuff have mentioned it for months.
True. I think they are conflating memory-safety and thread-safety here. Rust definitely offers better thread-safety properties. This is somewhat nice, since in my experience thread-safety issues are the more commonly undetected bugs - which are later on tricky to find and might require big refactoring efforts to fix. They are also often the source of the memory-unsafety issues.
Imho Go currently has the best blend of both properties for a GCed language - since the race detector does a good job of detecting thread-safety issues. I wish for Java and C# to get the same.
This says a lot. I'm sure Microsoft has very smart and competent engineers, yet they still get all these bugs. It's because manual memory management is really, really hard.
I'm baffled to keep hearing some people saying that manual memory management is okay when the evidence is this huge.
Perhaps for very simple programs is okay to do manual memory management, but for complex ones like most of them nowadays, it seems close impossible for humans to write safe programs.
1. In a constraint context (embedded/kernel) you want to preallocate most things anyway, since even normal malloc/free isn't deterministic. Once you preallocate objects, it doesn't matter if those are coming from a long-lived GCed heap or from somewhere else.
2. Kernels like Linux rely on the fact that some small allocations never fail. Plugging in a GC and asserting that it won't fail would have the same effect (with some impact on latencies).
What might be most important is that the language supports explicit stack allocations, which avoids the need for any kind of heap when necessary. That is given for languages like C# and Go.
It's a lot easier for someone to scoff at memory bugs on an internet forum than it is to write memory-safe code.
People need to "humble down" and see that if people keep falling into the same traps even with training, it's not as simple as "people sucks"
Hence why we need languages that are better at memory management than C. It's ergonomics.
In the same way you can't put a racing gearbox/clutch in a street car and expect everybody to deal with it. They won't.
The parent isn't saying "people suck" or even that "people who write memory bugs suck".
They're saying that 'programmer machismo' sucks.
Saying, "we don't need better tools, we just need better people, and I'm one of those better people," sucks.
Closely related is saying, "manual memory management is hard, so I guess most programmers should use better tools. But I'm a really advanced 10x 'leet programmer, (in spite of how much of my code has wound up in CVE's), and I'm clearly capable of writing code using manual memory management because of my 'leet skills."
It's one of the peculiarities of the field that we're completely ok with practitioners using dangerous tools and building techniques when better tools and techniques are available.
Besides, if a language guarantees that all pointers are not null, initialized, not dangling, etc you have a solid foundation in which to build large systems.
Also - why are people even mentioning C#? Rust is a language for writing SQL servers, drivers, browsers, and other foundational components where a garbage collector wouldn't make sense. Just about all of my stuff deals with HTTP, which is farther up the stack from Rust's sweet spot.
Yes, you can ducttape rust style memory safety features into C# or C++, but I'd imagine using it is kind of like introducing asynchrony into a C# codebase - it wants to affect everything and if you don't you'll always be contending with the sync/async border. Better to make it a requirement and reap the rewards from knock-on effects.
It’s not a language “for” anything per se, it’s ergonomic anywhere up the stack.
Actually, there is, not having a GC means you can better reason about stack/heap memory usage. That matters for performance critical and things like embedded systems where you might not even use malloc() in c.
Been learning rust for a few months now and really enjoying it so far... waiting on the new async stuff to firm up a little before continuing.
They then took some of those learnings into Windows 8.x, UWP .NET Native and C# 7.x and 8.0 low level memory primitives.
A tracing GC, coupled with value types and manual memory management in unsafe code makes plenty of sense and has been done multiple times since Xerox PARC days.
The only thing missing is a company having the guts to push it no matter what. A bit like Google is doing with ChromeOS and Android.
This. I see a lot of the so call new idea and hype aren't actually new at all. It didn't succeed simply because it never got the investment or drive until it has sustainable critical mass. And every few years or decades we start to reinvent the wheel by new generation of developers.
Especially in tech industry where you are considered old if you are over 40, but in reality it is the age you finally see all the ideas keeps getting recycled again by newer generation and you could finally say meh, no.
I built a domain agnostic virtualization and streaming platform that generalized the “Click2Run” features of Office and could apply retroactively to any traditional app that didn’t include kernel code (e.g. worked on Adobe Creative Suite)
I also worked on the early phases of the sandbox that runs WinRT for JS, which also required paying my dues and fixing bugs or implementing new features (e.g. the fetch API) for the Trident engine in IE.
I wouldn’t consider these trivial projects.
But let's say they were very smart and did not get all those bugs. Even then, why would someone claim the compiler double-checking is not useful?
I have a pretty good grasp of Javascript and can pretty much always predict what type something is going to be. Of course I make mistakes, but even if I didn't: using TypeScript is still great, because I don't have to manually keep track of all those types. Sure, I could do it, but it's more useful to spend my cognitive effort and energy on other things.
Also, being memory safe doesn't get you much (or rather very very little IMHO), because complex code still contains logic bugs, UI bugs, performance bugs, etc, etc. Personally, I want the program to crash rather than keep running only to find out it was silently messing up data or otherwise leaving things in an inconsistent state.
https://www.phoronix.com/scan.php?page=news_item&px=Firefox-...
Not to mention Firefox's poor state in macOS.
On my machine at current gig it crashes every other day making me lose my containers. It doesn't overheat the machine like some others reported though.
That said, you're better off comparing CVE counts for Firefox vs Chrome. That said someone could craft a malformed legacy font file that has to be parsed by some dusty win32 code and BOOM!
https://4e6.github.io/firefox-lang-stats/
They are working on a new Rust-based rendering engine, Servo, but it hasn't received nearly the level of work that a browser like Chrome has yet.
Fuchsia contains a considerable and ever-growing amount of Rust. And if you consider VM infra in the "OS" category, you have Firecracker from Amazon and crosvm from Google as well.
> maybe an entire AAA game written in Rust will be an interesting challenge.
We'll see how it goes; there is one studio that has made AAA-level games in the past using Rust now, and a new studio that is full of ex-EA folks.
> Personally, I want the program to crash rather than keep running
The alternative here isn't keeping running, it's "does not compile in the first place". That's even sooner than your crash, and guaranteed, as opposed to "happens to hit the right code path."
Different people mean different things when they talk about correctness. I think it means accurately capturing the intent of the programmer, i.e. the logic/algorithm/code flow or whatever, and eliminating the ambiguity. How does rust help here?
I'm saying that its this the same kind of programmer error (not being able to specify things without ambiguity or a way to capture intent accurately) that was the cause of the memory bug in C too. Its just that with C you will hard crash whereas in Rust you wont. You didn't crash but you modified a data structure you shouldn't have, and your program will still end up in an inconsistent state.
In much the same way, the kernel doesn't care what happens in userspace - which thread is doing what with memory or what userspace resources are being corrupted, etc. The kernel can trivially kill userspace threads at will, and continue to remain rock solid as ever. So yes while the separation of kernelmode and usermode helped the user escape from poorly coded apps, it didn't really help reduce the actual bugs as much.
Hopefully that made as much sense as it did in my head! :)
Just in this thread stats about memory bugs being 70% of CVEs is presented, so why do you believe "being memory safe doesn't get you much" ? I am not a Rust fanboy and would rather use a GCed language for most work. But I don't get this stubbornness towards progress and better tools. If some tool can make "your" life easier in many ways, use it for your own profit !!
As an aside, I've recently been working with PLCs and I've come to respect a lot of the design elements of things like the Siemens GRAPH language which makes it easy to capture my intent for sequential control stuff.
What's annoying in this article is that it doesn't come right out and say that MS is considering offering a full Windows SDK with a Rust API. The closest I see the article come to mentioning this is: "Exploring the use of a memory-safe language such as Rust would provide an alternative to creating safer Microsoft apps.
But Thomas also argues that third-party developers should also be looking into memory-safe languages as well. He cites reasons such as the time and effort developers put into learning how to debug the memory-related security flaws that crop up in their C++ apps."
It would be interesting to know if a Rust native API is something being actively worked on at MS.
BTW, MS does ship Rust in a product today, the VSCode editor/ide uses ripgrep for search, which the article fails to mention as well.
> it doesn't come right out and say that MS is considering
> offering a full Windows SDK with a Rust API
It's possible that the Security Response Team doesn't have the authority to dictate the priority of new products for the dev tools teams.Creating a fully Rustified Windows API interface would be a massive task. The WinApi is vast and parts of it are ancient. It's practically a living history of Windows. And that's before you get to the more modern COM and UWP stuff.
What they might offer is a more focused subset.
Citation needed. I'm quite sure the pool of C#/.NET devs right now is quite a bit larger than the pool of Rust devs, to be honest, if anything for the sheer amount of headstart that C# has got over Rust.
C#: 450 asked today, 2548 this week
Rust: 14 asked today, 82 this week
Yeah, sooooo much more popular.
https://discordapp.com/invite/aVESxV8 for the community server
Experimenting works the best when MS doesn't yet commit to external Rust API, but writes new code in Rust (especially CVE bug fixes) and transforms gradually.
Dunno, I'm glad there are teams looking at things outside of Microsoft developed technologies. NodeJS receiving kudos for being so good at serving requests lead to articles about how it could be done in ASP.NET (with some rearchitecting of the ready bake application code) which apparently gave way to ASP.NET Core and I'd say if all of that is true, we're all better for it (ASP.NET developers, anyway).
I used it for years and don't have any major complaints.
Hearing that the company with the "best" language (all subjective) is interested in Rust is exciting.
This would be an opportunity for them at the same time to extend the language by offering for example a dialect which is less focused on functional programming idioms and the stranger notations, like lifetimes.
There are many people complaining about the above, and they would probably vote for the MS dialect, which could result in extinguishing current Rust and de facto replacing it with a more beginner-friendly version.
(I noted these words: [...] embrace [...] extend [...] extinguish [...])
I belly laughed. And I really needed to just then. Thanks.
That doesn’t mean they aren’t moving forward with .Net or C#, but the main thing they want to sell to developers in 2019 is Azure where it used to be enterprise licenses for VS and windows server. And they don’t need C# for that.
Also, they seem to be wanting Rust as a replacement for C and C++, so it’s probably mostly unrelated to C#.