언어/Scala

[Scala 찍먹하기] 시작하기: 설치부터 프로젝트 생성/실행/종료까지

보리시스템 2024. 6. 3.

0. Scala란?

2004년에 발표된 객체지향/함수형 프로그래밍의 요소가 결합된 멀티 패러다임 프로그래밍 언어이다. Scala는 확장 가능하다는 의미의 단어 'Scalable'에서 유래되었다. JRE(자바 실행 환경)와 서로 잘 호환되도록 설계되어 JVM(자바 가상 머신)에서 실행할 수 있고, Java 언어와도 호환된다.

Scala는 Spring의 초대량 요청 처리에서의 한계를 극복하는 데 도움이 될 수 있다고 한다. 함수형 프로그래밍으로 불변성, 순수 함수를 강조하기 때문에 예측 가능한 코드를 작성할 수 있기 때문이다. 또한 강력한 타입 시스템으로 런타임 안정성을 높여주기도 한다. Scala에서 많이 사용되는 Akka 프레임워크는 액터 모델을 기반으로 하여 분산 시스템과 동시성 처리를 쉽게 할 수 있도록 지원한다고 한다.

https://docs.scala-lang.org/tour/tour-of-scala.html#what-is-scala

 

Introduction

Info: JavaScript is currently disabled, code tabs will still work, but preferences will not be remembered. Welcome to the tour This tour contains bite-sized introductions to the most frequently used features of Scala. It is intended for newcomers to the la

docs.scala-lang.org

 

  • 객체지향과 함수형 프로그래밍의 차이?
간단하게 말하면
- 객체지향 프로그래밍 언어는 객체 자체의 내부상태가 바꾸는 방식으로 동작하고
- 함수형 프로그래밍 언어는 그 객체를 새로 만들어 대체하는 방식으로 동작한다.

 


 

1. Scala 설치하기 (맥OS 기준)

$ brew install coursier/formulas/coursier && cs setup

 

https://docs.scala-lang.org/getting-started/index.html#install-scala-on-your-computer

 

Getting Started

To start experimenting with Scala right away, use "Scastie" in your browser.

docs.scala-lang.org

 


 

2. sbt 설치하기 (맥OS 기준)

sbt란?
최신 빌드 도구 중 하나로 스칼라로 작성되었고, 스칼라에 사용하기 편한 기능을 많이 제공함 (범용 빌드 도구이긴 함)

*참조: https://twitter.github.io/scala_school/sbt.html

 

$ brew install sbt

 

https://www.scala-sbt.org/download/

 

Download | sbt

Download

www.scala-sbt.org

 


 

3. 프로젝트 생성하기

// 빈 폴더로 이동하기(cd ..)

// 1. 프로젝트 생성하기
// 1-1. Scala 3 프로젝트를 생성하는 경우
$ sbt new scala/scala3.g8

// 1-2. Scala 2 프로젝트를 생성하는 경우
$ sbt new scala/hello-world.g8

// 2. 프로젝트명 작성하기(name [Scala 3 Project Template]: 뒷부분에 프로젝트명 작성)
$ name [Scala 3 Project Template]: project-name

 

https://docs.scala-lang.org/getting-started/index.html#create-a-hello-world-project-with-sbt

 

Getting Started

To start experimenting with Scala right away, use "Scastie" in your browser.

docs.scala-lang.org

 


 

4. 프로젝트 실행/종료하기

// 1. 프로젝트 폴더로 이동
$ cd into project-name

// 2. sbt 실행하기
$ sbt

// 3. 프로젝트 실행하기
// * ~를 넣으면 파일이 저장될때마다 sbt가 재실행됨
$ sbt:project-name> ~run

// 4. 프로젝트 종료하기
$ [Enter] 또는 [Ctrl+D] 입력하기



https://docs.scala-lang.org/getting-started/index.html#run-hello-world

 

Getting Started

To start experimenting with Scala right away, use "Scastie" in your browser.

docs.scala-lang.org