Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
TS left, scala right
class Student {
constructor(fn: string, ln:string) {
this.fname = fn;
this.lname = ln;
}
fname: strin...
TS left, short form scala right
class Student {
constructor(fn: string, ln:string) {
this.fname = fn;
this.lname = ln;
}
f...
differences
• The class definition is also the constructor, that’s
the major difference to note. Also, the keyword
‘var’ h...
thoughts
• the two languages, except for Scala being designed to be less
verbose, have more in common, including interface...
Upcoming SlideShare
Loading in …5
×

Quick typescript vs scala slide

7,080 views

Published on

just a quick side by side

Published in: Software
  • Follow the link, new dating source: ❶❶❶ http://bit.ly/36cXjBY ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ♥♥♥ http://bit.ly/36cXjBY ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • though actually you can use `constructor(public fn: string, public ln: string) { }`
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Interesting to see how similar the syntax is when it's side by side like this. There is a nice shortcut that you can take in the Typescript code by using 'public' on the constructor parameter to create automatic properties - I've converted your example here: https://gist.github.com/stevewillcock/110319cdcfebe460af43

    (I replaced println with console.log to get this to compile and run using nodejs)

    Cheers
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @undefined yup - while a bigger departure from the TS capability, that's an even shorter scala form. i simplified the second slide a bit. cheers
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Quick typescript vs scala slide

  1. 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. 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. 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. 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.

×