新しい言語を作るということ
“
every programming language – consists of 10%
new and 90% stuff that is just bread and butter
for programming and that just has to be there
「 全てのプログラミング言語は10%だけ新しく、
90%はパンとバターみたいなありふれた必需品
”
」
Masterminds of Programming内でのAnders Hejlsbergの言葉
新しい言語を作るには:
• 作る人にとって、10%の楽しい作業のために10倍の労力
• 使う人にとっても、うれしいのはたった10%
言語に機能を足すということ(1)
“
We can add, but we can never take away. This weighs
heavily on our minds as we evolve C#. Anders famously
says that “every feature starts with minus a hundred
points”.
「 我々は機能を足せるけど、絶対に消せない
あらゆる機能は-100ポイントから考え始めろ
”
」
MSDNブログ内でのMads Torgersenの言葉
言語を新機能を足すには:
• かなり慎重・保守的であるべき
• やらないのが基本。やるには相当の理由を求める
言語に機能を足すということ(2)
“
we need to be bold. We need to not be stymied by our
responsibility to a distant future. Because otherwise we won’t
have that future. C# needs to be among the greatest programming
languages today, or it won’t be among them tomorrow.
「 我々は大胆でなければならない
今、最高でなければ、未来の最高にはなれない
”
」
C#開発チームの今:
• かなりアグレッシブに新機能を取り入れる
• 常に最高であろうとしている
MSDNブログ内でのMads Torgersenの言葉
ダメだと思うもの言われても困る
ダメ元で言ってみるけど、
破壊的変更してでもシンプルな構文ほしい
class Program
static void Main(string[] args)
int a = 10
int b = 20
if a == 10
if b == 20
WriteLine("Value of a is 10 and b is 20")
elsif b > 50
WriteLine("Value of a is 10 and b greater than 50")
else
WriteLine("Value of a is 10")
{} とか ; とか
なくていいよね!
INotifyPropertyChanged
• INotifyPropertyChangedを実装したい
• 実装例
class Point : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(PropertyChangedEventArgs args) => PropertyChanged?.Invoke(this, args);
private void SetProperty<T>(ref T storage, T value, PropertyChangedEventArgs args)
{
if(!EqualityComparer<T>.Default.Equals(storage, value))
{
storage = value;
OnPropertyChanged(args);
}
}
public int X
{
get { return _x; }
set { SetProperty(ref _x, value, XProperty); OnPropertyChanged(SumProperty); }
}
private int _x;
public static readonly PropertyChangedEventArgs XProperty = new PropertyChangedEventArgs(nameof(X));
public int Y
{
get { return _y; }
set { SetProperty(ref _y, value, YProperty); OnPropertyChanged(SumProperty); }
}
private int _y;
public static readonly PropertyChangedEventArgs YProperty = new PropertyChangedEventArgs(nameof(X));
public int Sum => _x * _y;
public static readonly PropertyChangedEventArgs SumProperty = new PropertyChangedEventArgs(nameof(Sum));
}
class Point
{
public int X;
public int Y;
public int Sum => X + Y;
}
6 pointでないとスライドに収まらないこの
コード、意味のある情報はほとんどない
以下のクラスにINotifyPropertyChangedを実装したいだけ
言語機能としてサポートすべき!?
レコード
• 純粋にフィールドだけを持つ型、作るの面倒じゃない?
struct Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public void Deconstruct(out int x, out int y) { x = X; y = Y; }
// Equals, GetHashCode, ==, !=, With...
}
これも、意味のある情報かなり少ない
この程度→
struct Point
{
public int X { get; }
public int Y { get; }
}