Hacker News new | past | comments | ask | show | jobs | submit login

More people need to read up on C#'s ref's:

https://em-tg.github.io/csborrow/

These kinda-sorta fall under borrow checking or regions, just without any annotations. Then again, Ada/Spark's strategy also technically falls under Tofte-Talpin regions:

https://www.cs.cornell.edu/people/fluet/research/substruct-r...




Isn’t that a form of “5. a mechanism where a pointer cannot point to an object that is more deeply scoped than itself”?

Also, since it’s an error, I guess it must be different from gcc and clang (and, likely other C compilers) -Wreturn-local-addr warnings (https://www.emmtrix.com/wiki/Clang:Flag/-Wreturn-local-addr), which can have false positives.

What’s the difference? Is the language stricter, disallowing some constructs that are valid, but hard to prove or is the error not always triggered for buggy code?


> Isn’t that a form of “5. a mechanism where a pointer cannot point to an object that is more deeply scoped than itself”?

That constraint is just a Tofte-Talpin region restriction, eg. lexically scoped regions.


Here's an example where ref returns make a big impact:

https://github.com/prasannavl/WinApi

The performance of this interop layer is so close to native it's difficult to argue for doing things the much more painful way.


Yeah C# is very well designed for gradually introducing low level concepts for performance.


The reverse is arguably the one trait Rust is missing that is holding it back from mass adoption. You can write high-level C# code and seamlessly introduce low-level concepts into it as you see fit. However, although you can write low-level Rust code easily, introducing high-level concepts is very painful and, in many cases, impossible.


Also F#


As of now - F# needs more work w.r.t. support for [<Struct; IsByRefLike>] types and byref<'T>s. There's a reason ref lifetime analysis in Roslyn is quite a sophisticated part of its implementation even if most developers aren't aware of it.

F# has other cool features like `inline` bindings and [<IlineIfLambda>] function attributes but I found it more difficult to work with for systems programming when attempting to stay within safe constructs.

But if you don't need byrefs, ref structs and spans, then regular pointer-based or even array-based code is quite pleasant to write, for example https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

With that said - F# is an incredible language, but for systems programming you are likely to get better results in C#. I hope eventually someone contributes subsequent spec and compiler work to change this (and if you think you have time and could try it - please do! it's a nice small community).


Doesn't F# have byrefs, inrefs and outrefs. How are they different from C# refs? Asking as someone with surface level knowledge of both languages https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: