ufcpp-live / UfcppLiveAgenda

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

VS 17.1 Preview 2 #50

Closed ufcpp closed 2 years ago

ufcpp commented 2 years ago

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

.NET チームもそろそろホリデーから帰ってきたっぽい感じなので配信も再開(2か月ぶり)。

リリースノート

https://docs.microsoft.com/en-us/visualstudio/releases/2022/release-notes-preview#17.1.0-pre.2.0

気になるとこ:

C# 11

2個ほど実装追加。

17.1p1 から

var a = 1;
var b = 2;
var s = $"a: {
    a // ここの改行
    }, b: {
    b
    }";

17.1p2 から

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

if (x.AsSpan() is [1, .. var y, 5]) // list pattern
{
    foreach (var item in y)
    {
        Console.WriteLine(item);
    }
}
ufcpp commented 2 years ago

配信なかった間に、配信中に口頭でだけ話したけど文章で残してなかったものを色々ブログ化してたけども…

まだまだネタが残ってたり

image

ufcpp-live commented 2 years ago
new[] {1} [0..][0..][0..] is [..[..[1]]]
ufcpp-live commented 2 years ago
new int[] {} [..][..][..] is [..[..[]]]
ufcpp-live commented 2 years ago
// Visual Studio はこれを怒らない。
// Resharper は double negation 直すか?って聞いてくるらしい。
if (x is not not not not not not not not not not not null)
{
    Console.WriteLine("x is not null");
}
ufcpp-live commented 2 years ago

多分バグ。 要バグ報告。

image

new[] { 1  } is [var x] and x is 1
ufcpp-live commented 2 years ago
using System.Text;

var utf8 = Encoding.UTF8.GetBytes("何か").AsSpan();

// BOM を取る
if (utf8 is [0xEF, 0xBB, 0xBF, .. var noBom])
{
    utf8 = noBom;
}
ufcpp-live commented 2 years ago
m(new byte[] { 1, 2, 3, 4 });

void m(Span<byte> span)
{
    if (span is [var head, .. var tail])
    {
        Console.WriteLine(head);
        m(tail);
    }
}
ufcpp-live commented 2 years ago

辞書パターンも出るの? (案だけあって、進捗なし)

// 案はあるけど、リストパターン以上に需要低そう…
// ただ、文法的にはよっぽど素直な予感あり。
var d = new Dictionary<string, string>()
{
    ["abc"] = "one",
};

if (d is { ["abc"] is "one"})
{
}
ufcpp-live commented 2 years ago
var d = new Dictionary<string, string>()
{
    { "abc", "one" },
};

// リストパターンが enumerable 対応するならこう書ける?
if (d is [ .., ("abc", "one"), ..])
{
}
ufcpp-live commented 2 years ago

多分仕様的にダメなんだけど、せめてエラーメッセージもうちょっとまともにしてほしい事案。

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

var y = x[^1, ^1]; // これ、元からダメ。

if(x is [[1,..], [_,_]]) // なのでこれもダメな可能性大。
{
}
ufcpp-live commented 2 years ago
// rectangular array は元から変。
// 最適化もかかりにくくてあんまり使えない。
var x = new[,] { { 1, 2 }, { 3, 4 } };

Console.WriteLine(x is System.Collections.IEnumerable);
Console.WriteLine(x is IEnumerable<int>);

foreach (var item in x) // パターンベース foreach
{
    Console.WriteLine(item);
}
ufcpp-live commented 2 years ago

↑特別な人でした。

image

ufcpp-live commented 2 years ago
var s = $"{123:X}"; // 条件演算子の : と書式指定の : の区別がつかない

void m(object x)
{
    var s = @$"{( // なのでここ、 () が必須。
        x is int i
        ? i
        : "aaa"
        )}";
}
ufcpp-live commented 2 years ago
// C# 10 で improved interpolated string が入ったので、
// {} にいろいろ詰め込むのはメリットなくはない(速い可能性はある)。
// とはいえ、メソッド抽出しろよ。
var s = @$"{( // なのでここ、 () が必須。
    x is int[] a && a is [var i, ..]
    ? i
    : "aaa"
    )}";
ufcpp-live commented 2 years ago
// 多分これ書ける interpolated string handler 書けるはず。
// (せめて key: value であったほしいけど無理w)
var s = CreateDictionary($"{x:Key1}{y:Key2}");
ufcpp-live commented 2 years ago

非匿名 image

匿名、アウトー- image

ufcpp-live commented 2 years ago

Stack Trace Explorer の現状、だいぶ未成熟感ある… まあまだ preview 2 なので…

例外ダイアログとかに組み込まれてくれたらだいぶ嬉しそう。

ufcpp-live commented 2 years ago

「コードクリーンナップの設定がおかしい人がいたのでクリーンナップしておきました。」

ufcpp-live commented 2 years ago

image

ufcpp-live commented 2 years ago

成人式。

image