Sunday, March 20, 2016

What is Go Lang and How to Setup Go Lang on Windows .!!

What is Go Lang ?

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

You can read more about Go Lang From Here : https://golang.org/

Follow below Steps to Setup Go Lang on Windows Machine :

1.  Download the appropriate go version for your windows (x64 / x86) from here https://golang.org/dl/



2.  Extract downloaded zip.
3. Copy Go folder from extracted folder to C:\Go to make thing easier.
4.Ensure the Go binaries (found in C:\Go\bin) are in your Path system environment variables. To check click System, Advanced system settings, Environment Variables... and open Path under System variables:

Easy way to confirm your path is by typing go version in command line tool.

5.Setup your Go workspace. This consists of three folders at the root: \bin,\pkg & \src.


 6.Create the GOPATH environment variable and reference your Go workspace path. To add, click System, Advanced system settings, Environment Variables... and click New... under System variables:


Set the variable name to GOPATH and value to your Go workspace path (e.g. C:\Projects\Go):

 Check quickly if path has been set correctly or not from command line:

7. Create new file hello.go at C:\Projects\Go\bin directory and write following code into it:


8. That's it you are ready to run your hello world program of go Lang. Just go to your projects folder \bin directory from command line and type go run hello.go.

 

Basics of TypeScript

I was just learning type script and i realized to publish it on internet so any one can easily get it in lay man language:

What is TypeScript ?

As described on official TypeScript website “TypeScript is a typed superset of JavaScript that compiles to plain JavaScript”. TypeScript is not a replacement of JavaScript, it does not add any new features in JavaScript. TypeScript provides developers with features like type safety, compile time type checking, object oriented constructs on top of JavaScript, basically lets developers think in object oriented terms when writing JavaScript. The most amazing thing about TypeScript is, it compiles in JavaScript so we don’t have to support any new VM to run TypeScript which then can be referenced in a web page, used in server side like in NodeJS.

TypeScript is an open-source developed by Microsoft, but is in no way ties to Microsoft platform and can be used anywhere in any environment where there is a need to write JavaScript. Though Microsoft does provide a great support in Visual Studio for TypeScript and we will be using Visual Studio for our examples but we can use TypeScript compiler as well from command prompt to compile TypeScript in JavaScript (we will see a brief example of that as well).

How to install TypeScript ?

Visual Studio has inbuilt support for type script from 2013 and of course any one can install it on 2012 as well. For creating TypeScript Project in Visual Studio 2015 follow below steps:-

1. Click on file-> New->Project-> Select HTML Application With TypeScript From TypeScript Tab.
2. After naming it you will have TypeScript project open which will have app.ts default type script written by Visual Studio and index.html file.


TypeScript file template can be created in similar way as other files are, by selecting “Add New Item” and then selecting a TypeScript file.
All TypeScript files have *.ts extension. Visual Studio plugin for TypeScript automatically creates and updates a corresponding JavaScript file with same name whenever we modify the TypeScript file and save. This generated JavaScript file can then be used as a normal file and included in any web page.

Features Of TypeScript:

Developers can write code in TypeScript which has object oriented concepts and compile time type checking on top of JavaScript which helps writing more structured, maintainable and robust code. TypeScript introduces few of the standard object oriented terms like Classes, Interfaces, Module and Variables which in end gets converted into various different forms of JavaScript.

1.  Module : Module is like a namespace in .Net world and can contain classes and interfaces.


Here Class Comedy is part of Movie module like namespaces in .Net.

2.Interfaces : Developers can create interfaces in type script and implements those in particular class like we are doing in .Net.Compiler will give errors here as well if we are not implementing any member of interface and that is the best feature of type script other wise it is same as java script.


Above is the simple example of interface and its implementation in type script. Interface IStudent has two members Student's yearOfBirth and second one is method which gives us age of student based on yearOfBirth. Here compiler will make sure that methods we are calling from classes has appropriate arguments on all those as we does in .net. When we compile type script interfaces those will go - those will be omitted in actual java script.

3. Classes : Classes are again very similar to .Net/Java world. Classes contains variables, properties and methods which form one logical entity. TypeScript also allows to set scope of the variable and functions with keyword like “private” and “public” though that scope does not have any effect on the JavaScript generated.

In above example we have class Student which has members like firstName ( private) and lastName (public) if we do not specify any access modifier by default it is public in type script. also Constructor can be created using Key word constructor().  When compiler converts type script to java script there is no meaning of Public and private keywords.

4.Functions : Functions are methods which can have logic written in side. in above example FullName is a tyoe script function which alerts fullName of Student.

5. Variables : Variables are the fields defined inside a class or a function. TypeScript allows us to define a variable using keyword “var” and assign a data type to it. Once a data type is assigned any further usage of the variable has to be with same data type else TypeScript will generate error on design and compile time.


Note:
For each of the features in TypeScript we have been relating to corresponding features in OOPs language such as C# and Java but, we need to keep in mind that TypeScript is not a OOPs language. In fact, TypeScript is just a tool on top of JavaScript which provides us with more robust code structure, type safety. TypeScript enhances the productivity of developers writing JavaScript code and it in itself does not provide any specific functionalities or features like libraries such as Jquery.
Most of the features which we use in TypeScript gets removed from the compiled JavaScript file and we are left with nothing more than a pure JavaScript code.