1 / 10

안전한 프로그래밍 defensive programming

안전한 프로그래밍 defensive programming. 안전수칙 0 : 함수를 정의할 때 , 함수 타입에 맞는 데이터를 받는지 확인한다 . 꼬리표 + 기타 방식으로 . type checking 안전수칙 1 : 함수를 정의할 때 , 타입에 맞는 데이터 중에서 원하는 경우의 데이터인지를 확인한다 . 꼬리표를 가지고 . requirement checking 안전불감증 vs 안전집착 : 불감 보다는 집착이 좋다 .

mio
Download Presentation

안전한 프로그래밍 defensive programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 안전한 프로그래밍defensive programming • 안전수칙 0: 함수를 정의할 때, 함수 타입에 맞는 데이터를 받는지 확인한다. 꼬리표+기타 방식으로. type checking • 안전수칙 1: 함수를 정의할 때, 타입에 맞는 데이터 중에서 원하는 경우의 데이터인지를 확인한다. 꼬리표를 가지고. requirement checking • 안전불감증 vs 안전집착: • 불감 보다는 집착이 좋다. • 실행중에 “옳지않은” 값이 나도 모르게 흘러다니는 것 보다는 그럴 경우 바로 중단시키는 것이 좋다.

  2. (define (nth-child tree n) (cond ((not (is-tree? tree)) (error)) ((not (is-int? n)) (error)) ((is-leaf? tree) (error)) ((is-empty-tree? tree) (error)) ((<n 0) (error)) (else …) ; programming in safe area ) ) type checking requirement checking

  3. (define (nth-child tree n) (cond ((not (is-tree? tree)) (error)) ((not (is-int? n)) (error)) ((is-leaf? tree) (error)) ((is-empty-tree? tree) (error)) ((<n 0) (error)) (else …) ; safe area )) (define (is-tree? x) (and (pair? x) (or (equal (car x) leaf-tag) (and (equal (car x) node-tag) (fold and (map is-tree? (cdr x)) #t) ) ))) (define is-int? integer?)

  4. 안전한 프로그래밍,불만은 없는가? • type checking 코드를 꼭 장착해야 하는가? • “분명히 필요없는 경우가 있긴 한데. 그럴땐 필요없겠죠…그런데 불안하긴 해요…모르겠네요. 더 좋은 방법이 없을까요?” • “내 프로그램의 실행속도가 문제될 것 같아요. 함수실행중에 매번 타입첵크를 하는 데 시간이 소모되잖아요. 문제될 때 곧바로 중단시켜야 문제를 그때 그때 파악하기 쉽긴 할 텐데.. 모르겠네요. 더 좋은 방법이 없을까요?” • “내 프로그램은 KRX-II 로켓의 진동보정 시스템에 장착될 거예요. 돌다가 멈추면 안되는데, 돌다가 문제되면 결국은 멈출텐데…모르겠네요. 더 좋은 방법이 없을까요?”

  5. 프로그램 안전성 자동 검증기술static type-checking system • 프로그램에서, 함수들의 인자타입에 맞는 데이타들이 항상 흘러드는지 미리 자동으로 안전하게 확인. • “미리”: 실행전에 프로그램 텍스트만을 보면서 • “자동으로”: 프로그래머가 하지 않는다. • “안전하게 확인”: 확인결과가 믿어도 된다.

  6. 프로그램 안전성 자동 검증기술static type-checking system 덕택에, • “분명히 필요없는 경우가 있긴 한데. 그럴땐 필요없겠죠…그런데 불안하긴 해요…모르겠네요. 더 좋은 방법이 없을까요?” • “내 프로그램의 실행속도가 문제될 것 같아요. 함수실행중에 매번 타입첵크를 하는 데 시간이 소모되잖아요. 문제될 때 곧바로 중단시켜야 문제를 그때 그때 파악하기 쉽긴 할 텐데.. 모르겠네요. 더 좋은 방법이 없을까요?” • “내 프로그램은 KRX-II 로켓의 진동보정 시스템에 장착될 거예요. 돌다가 멈추면 안되는데, 돌다가 문제되면 결국은 멈출텐데…모르겠네요. 더 좋은 방법이 없을까요?” Static Type-Checking Static Type-Checking Static Type-Checking

  7. (define (nth-child tree n) (cond ((not (is-tree? tree)) (error)) ((not (is-int? n)) (error)) ((is-leaf? tree) (error)) ((is-empty-tree? tree) (error)) ((<n 0) (error)) (else …) ; safe area )) (define (is-tree? x) (and (pair? x) (or (equal (car x) leaf-tag) (and (equal (car x) node-tag) (fold and (map is-tree? (cdr x)) #t) ) ))) (define is-int? integer?)

  8. 프로그램 안전성 자동 검증기술static type-checking system • ML 프로그래밍 실습을 통해 경험해 볼 것입니다. • C나 Java는 어때서요? • 믿을 수 없는static type-checking 기술: 컴파일러의 type-check결과가 “ok”인데, 돌려보면 type-error. • Scheme은요? • type-check 미리 하지 않는다. • 모든것을 프로그래머에게 맡긴다. “뜻대로 하소서.”

  9. 데이타를 여러방식으로 구현할 때Multiple Representations • 데이터 구현방식마다 꼬리표를 붙이고. • 데이터 속내용 감추기 원리를 유지하면서. • 예를 들어 complex number data 구현방안들을 생각해 보자 • complex number 만들기 • make-complex: real * real -> complex • complex number 사용하기 • real: complex -> real • imag: complex -> real • mag: complex -> real • angle: complex -> real • add-complex: complex * complex -> complex • mul-complex: complex * complex -> complex

  10. add-complex mul-complex real imag mag angle rectangular polar representation representation

More Related