Tuesday, February 19, 2013

Declaration source files and google analytics

What is Declaration source files?

Declaration source files are restricted to contain declarations only. Declaration source files can be used to declare the static type information associated with existing JavaScript and expose their behavior.

I have started to implement TypeScript in my projects at work :-)

In that case I had to implement google analytics but ran into the problem, that I did not have intellisence for the that.

I googled a bit and could not find any declaration file for that, so I made my own.
I can now acces ga, _gaq, _gat and the Tracker object with intellicense in my TypeScript file, nice...

Example

describe("tester Google Analytics Code  _gaq object", () => {
    it("can create _push", () => {
        _gaq.push(['_setAccount', 'UA-XXXXXXX-YY']);
        _gaq.push(['_gat._anonymizeIp']);
        _gaq.push(['_trackPageview']);

        _gaq.push(() => {
                var tracker = _gat._getTrackerByName('UA-65432-1');
                tracker._trackPageview();
            }
        );
    });  
});

I have pushed it to https://github.com/borisyankov/DefinitelyTyped but until it is merged you can get the files here https://github.com/RonnieHegelund/DefinitelyTyped/tree/master/google.analytics



Sunday, February 17, 2013

TeaCrunch - CodeCoverage for Typescript

When working in .NET and writing unit test, I really like the green dots NCrunch gives me. I think its a great way to show what code you have test coverage on.

I would love to have this in TypeScript to, but haven't found any, so I have started making a prove of concept my self.



The prove of concept works, but is very unstable and have to rewrite the code, and need to find out how I can read the results from the test explorer. The biggest problem is to find the time to rewrite my code :-)

Saturday, February 16, 2013

TypeScript - The rest parameter

Rest parameter in TypeScript has nothing todo with REST (REpresentational State Transfer)

If you are familiar with C# params keyword, The rest parameter is the same. The rest parameter lets you specify a function parameter that takes an argument where the number of arguments is variable.

An example could be a function that make a Sum of a variable length of numbers:


Sum(1,2,3,4);

C# example

public int Sum(params int[] list)
{
  int sum = 0;
  foreach (int i in list)
    sum += i;
  return sum;
}
TypeScript example

public Sum(...list Number[]) : number
{
    return list.reduce( 
        (a,b) => { a + b }
    );
}
And the result when compiled to JavaScript

function sum() {
    var numbers = [];
    for (var _i = 0; _i < (arguments.length - 0); _i++) {
        numbers[_i] = arguments[_i + 0];
    }
    return numbers.reduce(function (a, b) {
        return a + b;
    });
}


Wednesday, February 13, 2013

Update to the book content has changed a bit


Update to the book content has changed a bit.

Introduction to enterprise design
    What is enterprise design?
        Design priciples
            Reliability
            Sepreation Of Concern
            Flexibility
            Maintainablitiy
            Reuseablity
            S.O.L.I.D
                Single responsibility principle
                Open/closed principle
                Liskov substitution principle
                Interface segregation principle
                Dependency inversion principle
        Design patterns
            Working with design patterns
            The benefits of patterns
            Antipatterns

The road to enterprise 
    Testing strategies.
        Unit tests
        Components Tests
        Integrations tests
        System tests
        Manual tests
    Acceptance test
    Test driven development     
        What is TDD
        TDD Kata as an example
    Testing frameworks
        jasmineJS
        QUnit
        Selenium - automated browser tests
    Continous Integration
        Teamcity
            Setting up automated tests
            Setting up automated deployment
        Continous Delivery

Design patterns in action
    View patterns
        MVVM
            Knockout as an example
        MVC
            Backbone as an example

TypeScript Fundamentals
    What is TypeScript
    TypeScript keywords
    Types
        Primitive Types
            The String type
            The Number type
            The Boolean type
            The Null type
            The Undefefined type
    Interfaces
    Classes
    Functions
        Functions arguments
        Arrow Functions
        Extension methods
            What is code smell?
    Inheritance
    Modules
    Generics (not supported yet) .
    Declaration Source Files

TypeScript Tools
    Visual Studio
    Web Essentials
    Sublime text

Thursday, January 24, 2013

Enterpise development in TypeScript


I have started writing a book” Enterprise development in TypeScript”

I am an agile developer, so this book will be published Early and Published Often. This way I can get feedback from readers and make the book as good as possibly.
The focus of this book is to use TypeScript in your enterprise applications. The book will go through the basics of TypeScript, different tools and frameworks, how to create unit tests and, then automate your tests, builds and deployment. The book is far from done, and if you think the book is missing something please don’t hesitate to contact me.

Please, tweet and show your support by saying what you'd like to pay for it at https://leanpub.com/enterprise-development-in-typescript

Book contents would be something like this
1.       TypeScript Fundementals
·         What is TypeScript
·         Static vs Dynamic type language
·         Interfaces
·         Classes & functions
·         Inheritance
·         Modules
·         Arrow functions
·         Generics (not supported yet)
·         TypeDefinitionFiles

2.       TypeScript Tools and frameworks
·         Visual Studio
·         Web Essentials
·         Sublime text

3.       Introduction to enterprise development
·         What is enterprise development?
·         The enterprise code

4.       The road to enterprise
·         Decouple of code
·         Test driven development
·         Continous Integration
·         Continous Delivery
5.       Design patterns
·         Inversion of Control / Dependency Injection
·         Facade pattern
·         Factory pattern
·         MVVM
·         MVC

Sunday, January 20, 2013

Retrospective of day 2 - Warm Crocodile Conf


#WarmCrocConf Day 2


Continuous Delivery in Action - Jimmy Bogard
Thanks to Jimmy I got a flashback when worked at 123hjemmeside/simplesite regarding SQL change management, I haven't done that since I moved on. But the Tarantino Project looked really impressive - this is a must in my future projects.
Contact Jimmy on Twitter @jbogard or read his blog

xUnit.net and AutoFixture - Mark Seeman
Mark did yet another awesome presentation, he's really good to involve the audience. He mad a good point why using Xunit. MSTes is not extensible, but xUnit.net is. In xUnit.net, you can extend the Fact or Theory attributes and support parametrized tests. mark has write a good blog post. He showed how cool AutoFixture is by given an example by using the FizzBuzz kata and using the InlineData attribute.

Follow Mark on Twitter @ploeh or read his blog


Getting Started with Azure Mobile Services - Henrik Frystyk Nielsen
Didn't get mutch out of this session, it seemed more like a sales speach than showing of some cool things, and wasn't very impressed, most of the session I just thought "yet another service repository". And didn't agree on all that he said, but maybe the API has changed since last time I made an windows phone app.

Follow Henrik on Twitter

Layers Considered Harmful - Chrisitan Horsdal
Christian did a cool presentation and showed how quickly we mess up our code with layers. Go basic remember YAGNI "You Ant Gonna Need It", don't code for reuseabillity, does I really need this in other places?

Follow Christian on Twitter or read his blog

RavenDB & the magic beans - Ayende Rahien
Maybe this Session was great, can't say, was late, so didn't get a seat in the front, and the lack of my hearing of deep voices I couldn't here what he said, but I love the product anyway :-)
Read his blog 

C# behind the scenes - Bart De Smet
Bart Is just an amazing speaker, really geeky but in a cool way. He talk about Expression Trees, and Iterator State machines. very interesting.

Read his blog

Retrospective of day 1 - Warm Crocodile Conf

Its already 3 days ago I left the #WarmCrocConf and think its time to write my experience when the conference is still fresh in my mind.

The conference was all in all great, cozy and intense. I think that we were about 200 people, and that did the conference intimate, i think that was really great because it was easy to get a chance to talk to the speakers, and connect with other geeks after dinner. The only really thing that I can complain about was the amount of changes to schedules.

I talked with the cool guys working on AutoFixture, especial nikos aka  , and showed nikos an enriko aka  my AutoFixtureTS project (a typescript version of AutoFixture.) I think they thought it was interesting?.

Alot of stuff was going on at the conference and Eventifier  has collected tweets, slides and images.

Session retrospektiv:

Day 1

BREAKFAST  KEYNOTE - Growing effective agile teams by Roy Osherove
Roy Osherove (@RoyOsherove on twitter) is the Chief Scientist at Bouvet.no
He did er great job and inspired me and got me thinking - have I ben in the comfort zone to long?...  maybe, so now I'm actually making a list of what kind of avalanche I wan't to dig into.

Get the keynote slide

Grokking Git by seeing it - Enrico Campidoglio
I didn't really know what I would expect to learn in this session. I thought I knew the basic of GIT, I was terribly wrong, yes I knew the basic commands, but that was it :-)

He was really good to explain how GIT actually worked by showing it step by step.
Things I need to remember and dig into here is:

SeeGit => Realtime repository visualizer
Posh-GIT => A better GIT with powershell
GIT tutorial => Need to try this :-)

Enrico works at tretton37 and can be contacted through his blog or on Twitter @ecampidoglio

Tour de API - Anne-Sofie Nielsen
Anne-Sofie did a great talk about oAuth and how to use it with different API's. The presentation was in 3D, pretty cool, and a good outbreak from normal .PPT slides.
She also mention to be aware of API changes and how API keys works. This was something a colleague and I hasn't been aware of :-(
Anne-Sofie has 3rd degree black belt in karate and can be contacted on her blog or on Twitter @femalenerd get the slide

NuGet (Anti-)Patterns: Tales from the trenches - Xavier Decoster
Xavier talked about Package Version, Package Repositories and general Anti patterns.
Things I remembered her was:

Package Version
Use semantic version with NuGet and how NuGet version's defers from SemVer.

Package Repositories
Split package repositories by audience, by using different feeds, I will dig into MyGet.org to see if I can use it.

Xavier can be found at http://www.xavierdecoster.com and you can follow him on Twitter @xavierdecoster

Get the Slide

Unit Testing best practices and horrible mistakes -  Roy Osherove
Roy Talks allot and love to sing, he should definitely publish the songs on YouTube.
Top 5 best practices  I think he covered in his session

  1. Test only public's
    1. Testing a private makes your test more brittle
    2. Test-First leads to private members after refactoring, but they are all tested
  2. Test Only One Thing
    1. avoid multiple Asserts
    2. one mock per test
  3. Enforce test isolation
    1. No dependency between tests!
    2. Don't run a test from another test
  4. Separate unit from integration tests
  5. Naming a unit test
    1. use _ to describe the test

Get the slide


Taking the hippie bus to the enterprise - Mogens Heller Grabe
Great Session, really showed how simple you could use a service bus with Rebus, I have to integrate in several of my projects. A fun thing was I got an error in one project while attending the Rebus session that Rebus could have prevent from happened.
Find him on Twitter @mookid8000 Read his blog Get the slide Get the demos

Organize your chickens: NuGet for the enterprise - Xavier Decoster
We had a good discussion about Package Management, dependency hell and the NuGet eco system. Then we discussed MyGet vs. TeamCity as a pacakage server, and though we have TeamCity and TeamCity has some of the same features, it maybe make sense for me to use MyGet. I need to dig into this...

Get the slide