The one technology that piqued my interest in TypeScript. As a software engineer that has work mostly on dynamic typed languages such as Ruby and Javascript, learning TypeScript has been a really eye opening experience for me.
My general experience of using TypeScript and this is based on my personal experience , using a typed language does the following things better than a dynamically typed language:
- Types together with Automated tests, give developers the confidence to refactor code, because of the help you get from the compiler and IDE. This generally means that the code will have less technical debt.
- Modelling domain objects using Typescript' structural sub-typing. As opposed to the classic typing from c# and java, typescript's type system .
Now code are written coupled to interface, as opposed to class-typing done in Java.
interface Named {
name: string;
}
class Person {
name: string;
}
let p: Named;
// OK, because of structural typing
p = new Person();
- In my opinion, Typescript will slowly take over javascript as the default language used in the frontend, when more and more people realize the benefits of a typed system.
Stack uses LILO ( Last in last out) The last object into a stack is the first object to leave the stack, used by a stack
Queue uses FIFO ( First in first out ) Every element which enters a queue is the first object to leave the queue, used by a queue.
Below is a sample example of Stack and Queue implemented in Ruby.
module Sample
class Queue
def initialize
@array = []
end
def enqueue(elem)
@array.unshift(elem)
end
def dequeue
@array.pop
end
end
class Stack
def initialize
@array = []
end
def push(elem)
@array << elem
end
def pop
@array.pop
end
end
end
queue = Sample::Queue.new
stack = Sample::Stack.new
queue.enqueue("apple")
queue.enqueue("orange")
queue.enqueue("pear")
queue.dequeue # => apple
stack.push("apple")
stack.push("orange")
stack.push("pear")
stack.pop # => "pear"