Friday, September 20, 2013

My Talk at brewww on TypeScript, TDD and code kata’s.

I did my first "real" talk last Friday 13th. "TypeScript Kata: The TDD style"
I think it went pretty well, in the light of it was Friday 13th, and the lack of my presentation just finished 30 min. before I had to go to the event. So I didn't have the time to do any review or rehearse.

My talk was meant to be a lightning talk that is max. 15 min. long, so that was, what I prepared for.
The other speaker couldn't make it, so I could talk for as long as I wanted – Great! I forgot Time and Space and don’t know for how long I talked.….

The attendee’s was very good to ask question, and we had some great discussions back and forth. Some of the guy’s said that I was pretty brave. In the light of, that all the attendees were drinking beers, and Open Source PHP/APACHE/LINUX/APPLE guy’s and in the fact that I’m a "Microsoft" man, showing of code in Visual Studio.


Hopefully I inspired a few people to dig into TypeScript, TDD or start making code kata’s.- And Basim realize that TypeScript is way better designed than CoffeeScript ;-p

Even though @mortendk and @christianjul, got inspired to make a bitch fight on Text editors and IDE's later this year, and of cause they want's me or somebody I know to defend Visual Studio! 

Thanks people @Brewww to give me an awesome night, this is not the last time I attend @Brewww or given talks, - I think Im already addicted :-)
What is Brewww?
Brewww is for web developers, designers, nerds, geeks and all others from the web industry. The people is primary Open Source PHP/APACHE/LINUX/APPLE guys. The meetups is quarterly for lightning talks / beer tasting and in copenhagen. Brewww is the brainchild of @mortendk and @christianjul. 

Wednesday, August 21, 2013

TypeScript v0.9 enum bug

/*
Update, after upgrading to v.0.9.1 it works as it should!
*/

I think I found a bug in the TypeScript enum. in the below example the WindeDirections.None should automatically be assigned the value 4, but it's actually 0.

TypeScript code
enum WindeDirections {
    North = 0,
    South = 1,
    West = 2,
    East = 3,
    None      
}

compiled code:
var WindeDirections;
(function (WindeDirections) {
    WindeDirections[WindeDirections["North"] = 0] = "North";
    WindeDirections[WindeDirections["South"] = 1] = "South";
    WindeDirections[WindeDirections["West"] = 2] = "West";
    WindeDirections[WindeDirections["East"] = 3] = "East";

    WindeDirections[WindeDirections["None"] = 0] = "None";
})(WindeDirections || (WindeDirections = {}));

I will write about TypeScript enum in details later :-)



Friday, August 2, 2013

TypeScript : Generics, < T > is for Type

Finally we got generics in TypeScript version 0.9, I have patiently waited for that feature, and now it's here, great!

There is already a few that have ben blogging about TypeScript Generics and give some examples. This is cool, though they haven't ben telling the fundemental of generics in TypeScript. So I have trited to do that, instead of another cool example :-)

What are Generics

Generics was introduced in version 0.9. Generic types allow for code reuse with type safety. The Internal algorithm remains the same, only the type changes and disappears again on compilation and generates no artifacts to the resulting JavaScript.

Why use generics

Generics provide quality to your solution by giving your type-safe at compile-time, and reduce repetitive programming tasks, by creating generic type-safe abstractions to classes and methods.

Generic type parameters

Specifies when they instantiate a variable of the generic type.
Type parameter name commonly starts with T. Consider not just give the parameter the name T For example, call it TThing as below:
In a generic type or method definition, a type parameter is a placeholder for a specific type that a client specifies when they instantiate a variable of the generic type.

class ItemCollection< TThing >
{
    private _things: Array< TThing >;

    Add(thing: TThing) {
        this._things.push(thing);
    }
}


Generic constrains

When you define a generic class, you can apply restrictions to the kinds of types that client code can use for type arguments when it instantiates your class. If client code tries to instantiate your class by using a type that is not allowed by a constraint, the result is a compile-time error. These restrictions are called constraints. Constraints are specified by using the extends keyword. You can define constrains with an interface or a specific class. Example below by making a constrain to IAnimal.

class AnimalCollection< TAnimal extends IAnimal >
{
    private itemArray: Array< TAnimal >;
   
    constructor() {
        this.itemArray = [];
    }
   
    FeedAll() {
        this.itemArray.forEach(
            (item) => item.Feed()
        );                   
    }       
}


Generic classes

Generic classes encapsulate operations that are not specific to a particular data type. The most common use for generic classes is with collections like the Array. A simple example of a generic class could be a class as follows:

class ItemCollection< T >
{
    private itemArray: Array< T >;
   
    constructor() {
        this.itemArray = [];
    }
   
    Add(item: T) {
        this.itemArray.push(item);       
    }
   
    GetFirst(): T {
        return this.itemArray[0];
    }
}


Generic methods

A generic method is a method that is declared with type parameters, as follows:

    Add(item: T) {
        this.itemArray.push(item);       
    }

You can also specify constrains on Type parameter, the below tells you that the parameter animal should implement the interface of IAnimal as follows:

function Add< T extends IAnimal >(animal: T)
{
    //...
}

Conclusion

TypeScript generics ensure type-safety and quality, reduce repetitive programming tasks, simplify the overall programming model, and do so with elegant, readable syntax. Generics is a compile-time only concept that disappears on compilation and generates no artifacts in the resulting JavaScript.

Thursday, July 25, 2013

Visual Studio RavenDB DataSource Explorer

Helping other developers being more productive at their daily work, is something that I enjoy. The last idea I got was trying to extend Visual Studio, by making a RavebDB DataSource Explorer prototype. This was fairly easy thanks to the documentation on msdn http://msdn.microsoft.com/en-us/library/bb165051(v=vs.100).aspx

It is still just a prototype, it needs validation and code cleaning. For now I can register new data sources by clicking on 

and the below dialog opens to create the datasource.


When RavenDB explorer is open I can right click on a datasource and connect to the server, or remove it from the explorer window.












When I have connected to the server it list all the databases




























When I double click on an item it opens an internet explorer window and goes directly to that document in the RavenDB Management Tool.
I have a bunch of ideas to this project, basic management options like, create new Database etc.
If you have any ideas/feature you think could be valuable, please let me know, I will love trying to implement them.

Sunday, July 14, 2013

Simple TypeScript Unit Test Project Templates

Inspired by John V. Petersen's latest post http://codebetter.com/johnvpetersen/2013/07/05/a-simple-jquery-qunit-based-javascript-unit-test-project-template/ I thought that TypeScript needed Unit Test project templates to.

I prefer using the Jasmine test framework, but knows that Qunit is popular, so I decided to make a project template for each of them. I have published them on the visualstudiogallery.

TypeScript Qunit Test Project
TypeScript Jasmine Test Project

After installing your preferred Test Project you can find it by choosing new project and go to "other langauges => TypeScript"














The basic structure for the jasmine project looks like this:



The Quint look almost the same, the only different is that I have installed the qunit.d.ts file via nuget instead of the jasmine.d.ts.
The reason for the d.ts files is placed in this structure "Scripts/typings/jasmine/jasmine.d.ts" is that, this is the basic structure when you install TypeScript definition files from nuget.

To get it working you also needs to install the chutzpah javascript runner

When this is done, the test will show up in the VS test explorer window.


Thanks John, for the inspiration. I now don't need to copy paste my TypeScript test projects.

Wednesday, July 3, 2013

2013 Microsoft® MVP Award! in Visual C#

A couple of month’s back I’ve got an email from Microsoft that I have been nominated for a MVP award, the only thing I should do was to fill out a word document. First I thought it was a spam mail and reread the mail. When I was sure it wasn’t spam I filled out the document, and then forgot all about it.
Then a few days ago I’ve got an email “Congratulations 2013 Microsoft MVP!”



I couldn’t believe it! And I still really can’t!.. But my MVP award should arrive on Monday, and when I have the award in my hand I’m sure that I believe it :o)

Today, there are more than 4,000 MVPs worldwide. They represent more than 90 countries, speak over 40 languages, answer more than 10 million questions a year, and are awarded in almost 90 Microsoft technologies.

And I must thanks for those that have nominated me and how proud I am to be a MVP.

Thursday, March 14, 2013

Brewing beer Kata 1st. draft

I am giving a 15min. lightning talk at @brewww "TypeScript kata: The TDD style" Friday 22. of marts.

And thougt I would make a brewing beer kata to the talk, though I'm not sure the following kata is good enough as a standard Kata, please give comment to improvements. Ill promise to post the final Kata in TypeScript later :-)

First draft of the kata:
  1. Create a simple Brewary with a method IBeer Brew()
    1. The method take 0 parameters but needs to return an IBeer
    2. The Beer should be of type lager
  2. Allow the Brew method to handle a brewingTemperature and a fermentationInDays argument
    1. If brewingTemperature is less than 5 throw exception “Temperature is to low”
    2. If brewingTemperature is greater than 4 and less than 11 return a beer of type lager
    3. If fermentationInDays is less than 7 and greater than 14 throw exception “fermentation for lager beers should be between 7 and 14 days”
  3. Add optional ingredients of type string as “roasted malt” and “barley” to make a stout
    1. If fermentationInDays less than 5 and greater than 6 throw exception “fermentation for stouts beers should be 5 or 6 days”
    2. brewingTemperature not equal 20 throw exception
    3. Expect result to be of type Stout
    4. Expect beers alcohol to be 7percent if fermentationInDays is 5
    5. Expect beers alcohol to be 8percent if fermentationInDays is 6