%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
Quick typescript vs scala slide
1. TS left, scala right
class Student {
constructor(fn: string, ln:string) {
this.fname = fn;
this.lname = ln;
}
fname: string;
lname: string;
name() { return this.fname+this.lname;}
greet() {
return "Hello, " + this.name;
}
}
var s = new Student("John", "Doe");
var l = [s,s,s];
var res = l.map(s=>s.name().length).reduce((x,y)=>x+y);
println(res);
class Student (fn:String, ln:String) {
var fname: String=fn;
var lname: String=ln;
def name() = { this.fname+this.lname;}
def greet() = {
"Hello, " + this.name();
}
}
var s = new Student("John", "Doe");
var l = List(s,s,s);
var res = l.map(s=>s.name().length).reduce((x,y)=>x+y);
println(res);
2. TS left, short form scala right
class Student {
constructor(fn: string, ln:string) {
this.fname = fn;
this.lname = ln;
}
fname: string;
lname: string;
name() { return this.fname+this.lname;}
greet() {
return "Hello, " + this.name;
}
}
var s = new Student("John", "Doe");
var l = [s,s,s];
var res = l.map(s=>s.name().length).reduce((x,y)=>x+y);
println(res);
class Student (val fname:String, val lname:String) {
def name = s”$fname $lname”
def greet = "Hello, “ + name
}
var s = new Student("John", "Doe")
var l = List(s,s,s)
var res = l.map(_.name.length).reduce((x,y)=>x+y)
println(res)
3. differences
• The class definition is also the constructor, that’s
the major difference to note. Also, the keyword
‘var’ has the preferred version ‘val’ in scala, which
denotes immutability to enforce sanity, but ‘var’
works just as well.
• … most of it, especially the functional line that
sums up the length of all names (it uses map and
reduce), is basically the exact same syntax with
the exact same meaning, see the line with ‘var
res=’.
4. thoughts
• the two languages, except for Scala being designed to be less
verbose, have more in common, including interfaces, mixins,
generics etc. But where Typescript stops and Node limits to one
thread processing, Scala goes on from here, to full monadic
comprehensions (Microsoft’s Lynq and assorted asynchronous
DSLs), asynchronous and reactive programming, parallel collections
library and full type system, DSL capability, embedded
asynchronous distributed processing etc… due to its telecom and
backend heritage (having evolved from Erlang and Haskell).
• In addition, scala, being a self-contained ecosystem, also compiles
to JVM bytecode, which makes it binary compatible with all JVM
libraries but also compiles to JS/node and JS/web (newer
compilers). The .NET compiler was its first I believe, but it was
discontinued sometime ago.