Introduction to Scala

All We Need is Data, itself !·2022년 5월 24일
0

DataCamp

목록 보기
11/13

What is Scala?

  • Scala fuses OOP and FP
    : scala is scalable
    • object oriented
      • every val is an obj
      • every operation is a method call
    • scala is functional
      • funcs are first-class values
      • operations of a program should map input values to output values rather than change data in place

Immutable variables and value types

val (immutable) :

  • can't be reassigned

  • double, int, bool, string is the most important

val (mutable) :

  • can be reassigned
  • pros and cons
    • pros:
      • data won't be changed inadvertently
      • code is easier to reason about
      • have to write fewer tests
    • cons
      • extra memory required due to dat copying

Scripts, applications and real-world workflows

scala scripts

  • a sequence of instructions in a file, executed sequentially
  • useful for smaller projects
  • at a command prompt, the scala command executes a script by wrapping it in a template and then compiling and executing the resulting program

Interpreted language vs. compiled language

Scala applications

  • compiled explicitly then run explicitly
  • consist of many source files that can be compiled individually
  • useful for longer programs
  • no lag time since applications are precompiled

Array

Collections

  • mutable
    • can be updated/extended in place
  • immutable

and Array is mutable.

  • Initialize elements of the Array

강사님 ㅋㅋㅋㅋㅋ Bye Alex 무엇 ㅋㅋㅋㅋㅋㅋ


  • Recommendation : use val with Array in Scala

  • mix and match the parameters in Array


Lists

  • Array is mutable and Lists is immutable obj

How Lists are useful while immutable

  • list has methods, like all of Scala collections
var players = List("A", "B")
players = "C" :: players

<Returns>
palyers: List[String] = List(C, A, B)
  • :: called 'Cons'


Scala's static type system

Scala is Compiled, statically-typed languages.


  • Relational and logical operators
    • Relational
      • , < , >= , <= , == , !=

    • Logical
      • && , || , ! (not)

  • foreach

profile
분명히 처음엔 데린이었는데,, 이제 개린이인가..

1개의 댓글

comment-user-thumbnail
2023년 4월 5일

who need help improving their coding skills bubble slides, daily game solve cross

답글 달기