ufcpp-live / UfcppLiveAgenda

@ufcpp live streaming agenda
MIT License
24 stars 2 forks source link

C#10、あの提案どこ行ったの? #44

Closed ufcpp closed 2 years ago

ufcpp commented 2 years ago

配信URL: https://youtu.be/AzJd1tAZdfo

知らんのか C# 11 が始まる

https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-08-30.md https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-09-01.md

「initial triaging」と書かれてる通り、10に入れれなかったものの整理っぽい回。 「あの提案まだ生きてる?」、「11 (来年)には実現しそう?」みたいなののある程度の指標に。

※ ここに並んでいるからといって11確約でもなければ、ここにないものが来年までに何も出てこないわけではないはず。

ufcpp-live commented 2 years ago
// [A<T>] ができるんならこれも認めてほしい
[TypeAlias(typeof(List<T>))]
struct Id<T>
{
}

internal class TypeAliasAttribute : Attribute
{
    public TypeAliasAttribute(Type t) { }
}
ufcpp-live commented 2 years ago
class X
{
    public int Value
    {
        get => field;
        set => SetValue(ref field, value);
    }

    public void SetValue<T>(ref T storage, T value,
        [CallerMemberName] string? name = null)
    {
        storage = value;
        // 以下略

        // EventArgs がクラスなのゆるすまじ。
        // 結局、ValueProperty みたいな静的プロパティ用意する羽目に…
        var arg = new PropertyChangedEventArgs(name);
    }

    private static readonly PropertyChangedEventArgs ValueProperty = new PropertyChangedEventArgs(nameof(Value));
}
ufcpp-live commented 2 years ago
DefaultInterpolatedStringHandler h;
h.AppendLiteral("/"); // これ、インライン展開かかると ldstr 消えるらしい

// AppendLiteral の中にこの手の分岐あり
var arg = "/";
if(arg.Length == 1) Append(char に分岐)
ufcpp-live commented 2 years ago
using System.Collections.Immutable;

var array = new[] { 1, 2, 3, 4 };

// 元案(没)
//if (array is [len] { var elem1 });

// 結局 [] 使うって。
// initilizer と deconstruct/pattern の対称性あきらめた…
if (array is [elem1, elem2, ...]) ;

// ここでさかのぼって、現在のコレクション初期化子
//var ic = new ImmutableArray<int> { 1, 2, 3, 4 };

// ↑は↓と同じ意味。
var ic = default(ImmutableArray<int>);
ic.Add(1); // ぬるぽ!!!!!!
ic.Add(2);
ic.Add(3);
ic.Add(4);

// これがダメすぎるので、immutable collection initializer 構文みたいなのが新設されるかも。
// [ 1, 2, 3, 4 ] になる?

foreach (var x in ic)
{
    Console.WriteLine(x);
}
ufcpp-live commented 2 years ago
void m(int? x)
{
    if (x is not { } nx) return;
    //x.GetValueOrDefault(); うぜー
    nx;
}
ufcpp-live commented 2 years ago
m(1, 2, 3, 4); // 値型はそう問題にならない
Span<int> buffer = stackalloc int[] { 1, 2, 3, 4 }; // これ扱いすればいい
void m(params Span<int> x) { }

m("a", "b"); // 参照型がきつい
Span<string> buffer = stackalloc string[] { "a", "b" }; // これがまずダメ
void m(params Span<string> x) { }

// なので、params Span は、固定長 safe stackalloc がほしいという話に。
// もともと stackalloc 参照型ができない理由は GC 負担が高すぎるから。
// 静的固定長 stackalloc みたいなのなら GC 負担減るかも。
// ランタイム側の対応必須。
ufcpp-live commented 2 years ago
// Expression blocks (低優先度)がもし入ったら…
var f = () => { F(); G(); }; // Action
var g = () => { F(); G() }; // Func<G の戻り値>
ufcpp-live commented 2 years ago
class C
{
    public string Name; // NRT 警告が消せない…
}

struct S
{
    public string Name;

    // これが書ける今、構造体でも Name に警告出るべき?
    public S() : this("") { }
    public S(string name) => Name = name;
}
ufcpp-live commented 2 years ago
// 後でアンケートとる?
class C1
{
#nullable disable warnings
    public string Name { get; init; }
#nullable restore warnings
}
class C2
{
#pragma warning disable CS8618
    public string Name { get; init; }
#pragma warning restore CS8618
}
class C3
{
    public string Name { get; init; } = default!;
}
class C4
{
    public string Name { get; init; } // この警告は無視する!
}
ufcpp-live commented 2 years ago
// C# 9~10 の現状
class C(int X) // 歴史上はこっちの方がさきに提案あった
{
    public int X = X;
}

record R(int X); // が、現在、レコード型でだけプライマリコンストラクター持てる