cc: @ahsonkhan, @stephentoub, @davidfowl, @weshaggard, @terrajobst, @joshfree, @AtsushiKan, @pakrym, @anurse, @GrabYourPitchforks, @ianhays, @bartonjs, @benaadams
Today, Binary class has methods named Read/Write, e.g.
c#
span.WriteInt32(value);
value = span.ReadInt32();
During the API review people commented that the names imply that there is some index being advanced when the methods are called, i.e. subsequent calls to Read would read subsequent values.
Here are some alternative names we would like to explore. Please vote for the proposals, or add your own:
c#
// the current API; has the problem that some people thing Write/Read advances a writer/reader
span.WriteInt32(value);
value = span.ReadInt32();
c#
// Z81 nostalgia API
span.PokeInt32(value);
value = span.PeekInt32();
c#
// is Set replacing the whole span?
span.SetInt32(value);
value = span.GetInt32();
c#
span.PutInt32(value);
value = span.GetInt32();
Agreed with the name confusion on Write. I think I would lean towards Set (I'm not too worried about the confusion around replacing the whole span, it's got "32" right in the name so I'd assume it would fill the first 32 bits only) or Put. I'd love to have Poke but I think other than the nostalgia, it's not a very approachable name :)
Set (or Put)
However, this should definitely exist 馃槈
namespace Microsoft.VisualBasic
{
public static class SpanExtensions
{
public static void Poke<T>(this Span<byte> buffer, T value) => buffer.Set(value);
}
}
Well, we chose the boring old Read/Write :-)
But you know it makes sense for the VB namespace... 馃槈
https://en.wikipedia.org/wiki/PEEK_and_POKE
These commands are particularly associated with the BASIC programming language
good idea for my April 1st PR
Most helpful comment
c# span.PutInt32(value); value = span.GetInt32();