Gheorghe Curelet-Balan Blog

Monday, April 14, 2014

Draft notes on latest features of Typescript 1.0 presented at BUILD2014

Anders Hejlsberg announced Microsoft's latest version of Typescript open source language http://channel9.msdn.com/Events/Build/2014/3-576 that addresses the maintenance issues with big Javascript projects by providing static types and optional typing of Javascript projects.

My time stamped draft notes, in the format MinutesSeconds (mmss) format, follows:

636 ref Google's Closure compiler that allows adding type annotations in comments
900 interface introduced, eg. Entity
1100 easy refactoring via VS2013 Update 2 ( or VS2012 Typescript power tool) of prop renaming due to local var name collision
1200 interface is structural typing, specifying  obj's properties: duck typing
1430 optional prop name ends with "?". But has type to be obeyed if prop is used
1500 can have methods in an interface
1640 javascript (JS) type system manifests at run time. Typescript reveals it at compilation.
2040 generics use in sorting example
2115 generics are used to flow types. "T extends Entity"
2345 callback use in generics array sort example
2450 lambda expression use not yet in Ecmascript 6
2610 Typescript is a preview of Ecmascript 6 compiled to code that can run on Ecmascript 3 browser
2740 ref type declaration file
2850 declaration file can be written for any Javascript framework. Gain the power of type checking and editor statement completion
2910 ref https://github.com/borisyankov/DefinitelyTyped site repository of type declarations for hundreds of Javascript frameworks
3030 writing classes is same with future Ecmascript 6 classes
3400 example of Typescript class methods translation into Javascript
3425 private properties support has no JS equivalent but may be used to support future Ecmascript 6 symbols = properties with hidden names
3550 productive implicit definition of public properties via their declaration in constructor's signature
3610 support of Ecmascript 6 feature of default argument value, eg. "y: number = 0"
Used if constructor doesn't provide values. The generated Typescript code for the constructor assigns the default value if its type is undefined.
3646 inheritance
3730 generated JS code for inherited Typescript class
3750 prototype chain setup JS code by __extends() function is the only case when Typescript generates code not written by you
3830 internal modules. Typescript translates the module into a JS function closure like in JQuery. Acts like namespace.
4000 external modules similar with node.js or require.js
4040 Typescript can work on server too. Node.js module system aligns with common.js specs
4100 Typescript app example with 2 modules. First, make a ref to node's type declaration file to get advantage of its types in editor's statement completion
4345 server using node.js module, code example
4450 client module using the server module
4550 command line compilation on client file will produce server JS file too, due to client module dependency on server module. Module compilation flag used for common.js: "tsc hello.ts -m common.js"
4645 convert existing JS projects to Typescript. Example of Audio File Viewer Javascript project conversion
5215 advantages of Typescript type checker in spotting errors that were not covered by unit tests
5230 improving Javascript projects by adding types to existing code. Configure project build by not allowing any implicit types
5517 Typescript doesn't enforce to add types to everything. Optional typing.
5650 main advantage of Typescript is to enable tooling
5730 the Typescript ecosystem
5830 the advantage of Typescript definition files: community writes the metadata of programs on the web
5848 Typescript tools
5915 Typescript roadmap

Labels: , , , ,

Tuesday, April 08, 2014

Object-oriented design decisions should consider code testability.

How easy can we test the code and how easy can we troubleshoot it if something goes wrong. The answers to these questions depend on how the code was designed.

A good test should be able to easily test any portion of the application.

Misko Hevery has great tips on how to design code for this purpose in his 2008 talk Don't Look for Things!:

- Class constructors should be simple, reduced eventually to only assignments.
- The use of Service Locator should be avoided (see minute 8:45).
- Dependency Injection (DI) is the solution to Law of Demeter (minute 19:14)
- Rules for object factories use (minute 22:00)
- Why NULL testing paranoia is bad for testing (minute 23:57)
- use of Google's Guice framework to build auto dependencies via reflection (minute 32:40)

Labels: , , ,