O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Visual basic14 の話

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
Scary storyofthedevelopmentspot
Scary storyofthedevelopmentspot
Carregando em…3
×

Confira estes a seguir

1 de 17 Anúncio

Mais Conteúdo rRelacionado

Semelhante a Visual basic14 の話 (20)

Mais recentes (20)

Anúncio

Visual basic14 の話

  1. 1. 可知 一輝
  2. 2. 自己紹介 • ひとりでやってます(会社員ではないという意味で) • 本名でやってます。 • Facebook:Kazuki.Kachi • Twitter :@kazuki_kachi
  3. 3. 何故に今VBなのか? • VS2015とWindows10がRTMになって早1ヶ月、ですが、C#6.0なお話 はVS2015がCTPな頃からさんざん聞いて聞き飽きてるし、すでに書き 飽きている物と想像しています。 まあ、だったらVBかな?と(軽い気持ち) • VBが終わったとか言わせないぞ!とかではありません。 • でも、そんなに悪い言語ではないと思うので忘れないで! • 今回は、「広く」「浅く」追加された機能を紹介する予定です。 ※深く知りたい場合は「C#」でググれば良いんじゃないかな…
  4. 4. と思ったんですが、 ねこが居なくなって、 やる気が… 昨日帰ってきました
  5. 5. アジェンダ • 追加された機能 • 実は元々有った機能 • まとめ ゴール • VBも(ちゃんと使えば)悪くないと思っていただければ良いかなと。
  6. 6. .NET Compiler Platform(Roslyn) (詳細は他の人に任せるとして)雑な解説 • コンパイラをManaged言語(C#はC#、VBはVB)で実装し直した。 • IDEのコード分析にも同じものを使用する(できる)ようにした。 • コード分析APIを公開した。(誰でも(割と簡単に)使える) 結果…
  7. 7. IDEの機能強化 • リファクタリングが提供された。 • ウォッチウインドウがΛ式、LINQの結果表示に対応した。 • 以下の機能がC#と同等になった • (IDEが提供する)リファクタリングが強化された。 • ソリューションエクスプローラに「参照」dllが表示されるようになった。 これは2013のどこかのUpdateからかも(2013Update5では表示されている) • SharedProjectに対応した。
  8. 8. Feature Example C# VB Auto-property initializers public int X { get; set; } = x; Added Exists Read-only auto-properties public int Y { get; } = y; Added Added Ctor assignment to getter-only autoprops Y = 15 Added Added Static imports using static System.Console; … Write(4); Added Exists Index initializer new JObject { ["x"] = 3 } Added No Await in catch/finally try … catch { await … } finally { await … } Added No Exception filters catch(E e) when (e.Count > 5) { … } Added Exists Partial modules Partial Module M1 N/A Added Partial interfaces Partial Interface I1 Exists Added Multiline string literals "Hello<newline>World" Exists Added Year-first date literals Dim d = #2014-04-03# N/A Added Comments after implicit line continuation Dim addrs = From c in Customers ' comment N/A Added TypeOf ... IsNot ... If TypeOf x IsNot Customer Then … N/A Added Expression-bodied members public double Dist => Sqrt(X * X + Y * Y); Added No Null-conditional operators customer?.Orders?[5] Added Added String interpolation $"{p.Name} is {p.Age} years old." Added Added nameof operator string s = nameof(Console.Write); Added Added #pragma #Disable Warning BC40008 Added Added Smart name resolution N/A Added Read-write props can implement read-only interface properties Exists Added #Region inside methods Exists Added Overloads inferred from Overrides N/A Added CObj in attributes Exists Added CRef and parameter name Exists Added Extension Add in collection initializers Added Exists Improved overload resolution Added N/A この中で、VBに関係があるのは…
  9. 9. Feature Example Read-only auto-properties public int Y { get; } = y; Ctor assignment to getter-only autoprops Y = 15; Null-conditional operators customer?.Orders?[5] String interpolation $"{p.Name} is {p.Age} years old." nameof operator string s = nameof(Console.Write); #pragma #pragma warning disable Partial interfaces Partial Interface I1 Multiline string literals "Hello<newline>World" Read-write props can implement read-only interface properties #Region inside methods CObj in attributes Partial modules Partial Module M1 Year-first date literals Dim d = #2014-04-03# Comments after implicit line continuation Dim addrs = From c in Customers ' comment TypeOf ... IsNot ... If TypeOf x IsNot Customer Then … Smart name resolution Overloads inferred from Overrides こんな感じ
  10. 10. Read-only auto-properties Ctor assignment to getter-only autoprops Class Point ReadOnly Property X As Integer ReadOnly Property Y As Integer ReadOnly Property Name As String = NameOf(Point) Sub New(x As Integer, y As Integer) Me.X = x Me.Y = y End Sub End Class
  11. 11. Class Point Private _x As Integer ReadOnly Property X As Integer Get Return _x End Get End Property Private _name As Integer ReadOnly Property Name As String Get Return _x End Get End Property Sub New(x As Integer, y As Integer) _name = “Point” _x = x End Sub End Class コンパイル時には上記のように解釈されます。 セッションではReadOnlyなPrivateフィールドに格納されると言ったな? あれは嘘だ!(と言うか、C#は確かにreadonlyなフィールドに格納されるんだけど…) まさか(こんなことが)違うとは思わず、確認を怠っておりました。申し訳ない…
  12. 12. Null-conditional operators Private Sub IntroduceNullConditionalOperators( ps As IReadOnlyList(Of Point), Optional act As Action = Nothing) Dim p = ps?(0) 'これはIndexer Dim s = p?.ToString() WriteLine(If(s, "Null")) Dim x = p?.X WriteLine(If(x.HasValue, x.ToString(), "Null")) act?.Invoke() 'delegateの場合はInvoke()を使用する End Sub
  13. 13. String interpolation Private Sub IntroduceStringInterpolation() Dim formated = $“{1000:C}” ‘String.Formatに展開される WriteLine(formated) ‘(日本語環境での)実行結果は 1,000 With New Object() Dim format1 As IFormattable = $"{1000:C}“ Dim ci = CultureInfo.GetCultureInfo("en-us") WriteLine(format1.ToString(Nothing, ci)) ‘実行結果は$1,000.00 End With End Sub
  14. 14. nameof operator Private Sub IntroduceNameOf(Optional arg As String = Nothing) If arg Is Nothing Then Throw New ArgumentNullException(NameOf(arg)) End If WriteLine($"{NameOf(arg)}:{arg}") WriteLine("おまけ") WriteLine($"{NameOf(DateTime.Now)}") WriteLine($"{NameOf(DateTime)}") WriteLine($"{NameOf(Date.Today)}") 'WriteLine($"{NameOf(Date)}") これはBuild error End Sub
  15. 15. 他の実例を挙げると、 INotifyPropertyChangedの実装でしょうか 今まで Property FamilyName As String (略) Set(value As String) If _familyName = value Then Return _familyName = value RaisePropertyChanged() RaisePropertyChanged("FullName") End Set End Property 他にはExpression使ったり… これから Property FamilyName As String (略) Set(value As String) If _familyName = value Then Return _familyName = value RaisePropertyChanged() RaisePropertyChanged(NameOf(FullName)) End Set End Property こんなの書きまして、 Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged Sub RaisePropertyChanged(<CallerMemberName> Optional propertyName As String = Nothing) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName)) End Sub
  16. 16. Multiline string literals Console.WriteLine("Hello World") Year-first date literals Dim today = #2015-08-29# '年は1000以上でないとBuild error Dim todayOnOldVersion = #08-29-2015# '年は100以上でないとBuild error
  17. 17. 以上です。

×