Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lessons learned designing the Windows Runtime

Similar presentations


Presentation on theme: "Lessons learned designing the Windows Runtime"— Presentation transcript:

1 Lessons learned designing the Windows Runtime
11/19/2018 4:12 AM PLAT-876T Lessons learned designing the Windows Runtime Brent Rector Senior Program Manager Microsoft Corporation © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

2 Agenda Design considerations building a multi-language OS runtime
How these decisions affect coding in your preferred language Apply this knowledge in your Metro style apps

3 Don’t make me write this again!
Agenda Please RT Don’t make me write this again!

4 Windows Runtime APIs Available to all programming languages
JavaScript C#/VB C++ Available to all programming languages Requires a language neutral type system

5 Casing of APIs in multiple languages
Many languages use PascalCasing for names of types, methods, properties, and events JavaScript has well established naming conventions “Types” are PascalCased Methods and Properties are camelCased Events are all lowercase Windows Runtime uses PascalCasing for types and members JavaScript maps methods, properties and event names to its conventions Causes oddities occasionally – UIElement -> uielement

6 Windows Runtime types Basic Types INT32, UINT64
Most basic types supported Strings HSTRING Avoids copying in multiple languages Structures struct Rect; Can contain strings, but not interfaces References IInspectable All classes, methods, properties and events are modeled using interfaces Simple Arrays INT32 [] For very basic collections Events event T^ Signaled; Modeled as interface Collections IVector<T> Type-generic interfaces

7 Numeric types Behave differently in .NET/C++ compared to JavaScript
C++/.NET - Signed, Unsigned; 8, 16, 32, 64 bit int; 32, 64 bit float JavaScript – double-precision 64-bit binary format IEEE 754 value Windows Runtime – Same as C++/.NET without signed 8-bit integer But… Operating system uses 64-bit integers in some places file sizes, position, etc. JavaScript number can only represent 53 bits of precision

8 Numeric types ECMAScript (ECMA-262) Standard
Requires numbers treated as IEEE bit floating point values JavaScript applications using the Chakra runtime cannot accurately determine the values of some 64-bit integers But such values can be received from and passed back to WinRT APIs Many (most) values will work fine Use caution with 64 bit values whose absolute value is greater than 2^53 (9,007,199,254,740,992)

9 public ref class MyClass sealed { __int64 _largeNumber;
MyClass () { _largeNumber = ; } property __int64 LargeNumber { __int64 get() { return _largeNumber; } void set(__int64 value) { _largeNumber = value; } } bool CompareInt64(__int64 a, __int64 b) { return a == b; } }; © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

10 var b = new MyLibrary.MyClass(); var val1 = b.largeNumber;
var isEqual = b.compareInt64(val1, val2); // true val1 = val1 + 0; isEqual = b.compareInt64(val1, val2); // false © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

11 Windows Runtime types Basic Types INT32, UINT64
Most basic types supported Strings HSTRING Avoids copying in multiple languages Structures struct Rect; Can contain strings, but not interfaces References IInspectable All classes, methods, properties and events are modeled using interfaces Simple Arrays INT32 [] For very basic collections Events event T^ Signaled; Modeled as interface Collections IVector<T> Type-generic interfaces

12 Strings Immutable or mutable? Null
Immutable – JavaScript, .NET; Mutable – C++ Null JavaScript: null is an object, string is a type C++: std::string has no 'null' semantics .NET System.String: reference type has a 'null' distinguished value Windows Runtime: string's immutable, no null representation

13 public ref class MyClass sealed { Platform::String^ _myString;
MyClass () {_myString = nullptr; } property Platform::String^ MyString { Platform::String^ get() { return _myString; } void set(Platform::String^ value) { _myString = value; } } }; © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

14 // What is the value of ‘s’? b.myString = null;
var s = b.myString; // What is the value of ‘s’? b.myString = null; b.myString = ""; // What is the value of ‘s’ © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

15 Windows Runtime types Basic Types INT32, UINT64
Most basic types supported Strings HSTRING Avoids copying in multiple languages Structures struct Rect; Can contain strings, but not interfaces References IInspectable All classes, methods, properties and events are modeled using interfaces Simple Arrays INT32 [] For very basic collections Events event T^ Signaled; Modeled as interface Collections IVector<T> Type-generic interfaces

16 Structures Handled differently by languages As a result…
C++/CLR: Structures are value types, can contain all types JavaScript: Has no structure construct but structures can be simulated Windows Runtime supports structures, with restrictions on content Can only contain numbers, strings or structures Windows Runtime structures cannot contain pointers Windows Runtime structures are value types As a result… Structure valued property behavior differs in languages

17 using namespace Windows::Foundation; public ref class MyClass sealed {
Rect _myBounds; property Rect MyBounds { Rect get() { return _myBounds; } void set(Rect value) { _myBounds = value; } } }; © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

18 b.myBounds = { x: 100, y: 200, width: 300, height: 400 } ;
b.myBounds.width = 42; // What is the value of ‘width’? b.myBounds = { x: b.myBounds.x, y: b.myBounds.y, width: 42, height: b.myBounds.height }; var bounds = b.myBounds; bounds.width = 42; // What is the value of ‘b.myBounds.width’? © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

19 Windows Runtime types Basic Types INT32, UINT64
Most basic types supported Strings HSTRING Avoids copying in multiple languages Structures struct Rect; Can contain strings, but not interfaces References IInspectable All classes, methods, properties and events are modeled using interfaces Simple Arrays INT32 [] For very basic collections Events event T^ Signaled; Modeled as interface Collections IVector<T> Type-generic interfaces

20 References & pointers Target languages handle pointers and references differently C++: All types can be passed by value or by reference .NET: Objects are passed by reference, value types by value JavaScript: Objects passed by reference, numbers passed by value Windows Runtime: Objects (Interfaces) passed by reference, all other types passed by value As a result… Method parameters are [in] or [out], never [in, out]

21 Windows Runtime types Basic Types INT32, UINT64
Most basic types supported Strings HSTRING Avoids copying in multiple languages Structures struct Rect; Can contain strings, but not interfaces References IInspectable All classes, methods, properties and events are modeled using interfaces Simple Arrays INT32 [] For very basic collections Events event T^ Signaled; Modeled as interface Collections IVector<T> Type-generic interfaces

22 Arrays Reference or value types? Windows Runtime
JavaScript, .NET, C++: Reference types Windows Runtime Arrays are value types so marshal by value ONLY WHEN they are marshaled!

23 public ref class MyClass sealed {
void ArrayMethod (array<int>^ arr) { arr[0] = 42; } void ArrayMethod2 (array<double>^ arr) { arr[0] = 42.0; } }; © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

24 // What is the value of arr[0]? b.ArrayMethod2(arr);
var arr = { 1, 2, 3, 4, }; b.ArrayMethod (arr); // What is the value of arr[0]? b.ArrayMethod2(arr); © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

25 Windows Runtime types Basic Types INT32, UINT64
Most basic types supported Strings HSTRING Avoids copying in multiple languages Structures struct Rect; Can contain strings, but not interfaces References IInspectable All classes, methods, properties and events are modeled using interfaces Simple Arrays INT32 [] For very basic collections Events event T^ Signaled; Modeled as interface Collections IVector<T> Type-generic interfaces

26 Events Event syntax differs across languages Be aware…
C++/CLR – Clients add events with += operator JavaScript – Clients add events with either the addEventListener function or by setting the “on<eventname>” property on the object. Be aware… JavaScript event name casing is all lowercase Assigning to the property implies one listener while addEventListener allows multiple listeners Misspelling the event name in either case silently fails

27 public ref class SignaledEventArgs sealed {
public: SignaledEventArgs() { }; }; public delegate void SignaledEventHandler ( Platform::Object^ sender, SignaledEventArgs args); public ref class MyClass sealed { event SignaledEventHandler^ Signaled; © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

28 var b = new MyLibrary.MyClass();
b.addEventListener ("Signaled", function () { … }); // What just happened? b.addEventListener ("signaled", function () { … }); b.onSignaled = function () { … }; b.onsignaled = function () { … }; © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

29 Events vs. delegates Windows Runtime prefers events over delegate-typed properties Both are (potentially) multi-cast JavaScript nicely maps events to JavaScript event conventions addEventListener (“eventname”, func) oneventname property Delegate properties are just that: properties No addEvetListener form Normal camelCasing of property name occurs: eventName

30 Windows Runtime types Basic Types INT32, UINT64
Most basic types supported Strings HSTRING Avoids copying in multiple languages Structures struct Rect; Can contain strings, but not interfaces References IInspectable All classes, methods, properties and events are modeled using interfaces Simple Arrays INT32 [] For very basic collections Events event T^ Signaled; Modeled as interface Collections IVector<T> Type-generic interfaces

31 Collections Windows Runtime collections are relatively straightforward
Vectors – similar to array, projected with array syntax Maps – key/value pairs, projected as dictionary to CLR apps Surprise… Because collection value accesses require a method call, they can be unexpected performance bottlenecks Can use the GetMany method for bulk retrieval

32 Method overloading Two criteria used when handling overloads
Overload on number of params (arity) JavaScript, .NET, C++ all distinguish methods by arity Overload on parameter type .NET, C++ all distinguish methods by type of parameters JavaScript has a limited notion of type Windows Runtime methods Overload on arity but not on type

33 public ref class MyClass sealed {
Platform::String^ AnOverload (Platform::String^ a) { return a; } Platform::String^ AnOverload (Platform::String^ a, Platform::String^ b) { return a + b }; © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

34 var str = b.AnOverload ("Hello"); // What just happened?
var str = b.anOverload ("Hello", " audience"); // What just happened? var str = b.anOverload ("Hello", " audience", " at BUILD"); © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

35 Asynchronous APIs Platform design goal that APIs cannot block the UI thread Guidance: Anything taking > 50 ms should be asynchronous Resulted in prevalent use of Async Pattern in platform Established a naming pattern: <verb>[<noun>]Async GetThumbnailAsync Return value mapped to a promise for a future result In .NET – await obj.GetThumbnailAsync() In JavaScript – obj.GetThumbNailAsync().then (func);

36 Further reading and documentation
C++ language extension summary The Windows Runtime Windows Runtime Design

37 thank you Feedback and questions http://forums.dev.windows.com
Session feedback

38 11/19/2018 4:12 AM © 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. © 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

39


Download ppt "Lessons learned designing the Windows Runtime"

Similar presentations


Ads by Google