Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
270
이펙티브 러스트
아이템
28
: 매크로를 신중하게 사용하라
함수보다는 매크로로 작성해야 한다고 결정하기 쉬운 경우가 있는데, 그건 매크로만이 할 수
있는 일이기 때문이다.
폴 그레이엄
Paul
Graham
, 『
On
Lisp
』(
Prentice
Hall
,
1993
)
러스트의
매크로
macro
를 사용하면
메타프로그래밍
metaprogramming
을 할 수 있다. 즉, 코드를 생성하
는 코드를 작성할 수 있다. 내용이 확실하고 반복적이며 매크로 없이는 일일이 동기화시켜줘야
하는
보일러플레이트
boilerplate
코드에 특히 유용하다.
러스트를 처음 접하는 프로그래머라면 입력 텍스트를 토큰 단위로 바꾸는 방식으로 수행하는
C
/
C
++의 전처리기의 매크로 기능을 써 본 적이 있을 것이다. 러스트의 매크로는 좀 다른 능
력을 갖고 있다. 토큰 단위로 파싱된 프로그램 코드를 처리할 수 있을 뿐만 아니라, 프로그램의
추상 구문 트리
abstract
syntax
tree
(
AST
)도 다룰 수 있다.
즉, 러스트의 매크로가 코드 구조를 인식할 수 있어서 매크로 관련 문제를 모두 피할 수 있다는
뜻이다. 특히 다음 절에서 보겠지만 러스트의 선언적 매크로는 위생적
hygienic
이다.
4
즉, 주변 코
드에 있는 로컬 변수를 참조 (캡처)하는 실수를 저지를 수 없다.
매크로는 코드에 대한
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

이펙티브 타입스크립트

이펙티브 타입스크립트

Dan Vanderkam
파이썬으로 살펴보는 아키텍처 패턴

파이썬으로 살펴보는 아키텍처 패턴

오현석, 해리 퍼시벌, 밥 그레고리

Publisher Resources

ISBN: 9791169212946