무냐의 개발일지

[OSSU] <UBCx HtC1x_How to Code> / 8a_Abstraction (중요!!!) 코드 간결하게 짜기 본문

OSSU_CS coursework

[OSSU] <UBCx HtC1x_How to Code> / 8a_Abstraction (중요!!!) 코드 간결하게 짜기

무냐코드 2024. 5. 9. 14:07

 One of the things that separates good programmers from the other kind is taking the time to improve the structure of their code once it is written. This material is super important, and... it is really important to practice doing it!

 

 

Abstraction is a crucial technique for managing complexity in programs. 

- One aspect of this is that it can make programs smaller if the abstract functions are used by many other functions in the system. 

- Another aspect is that it helps separate knowledge domains more clearly in code.

 

All the work you've done understanding templates is about to give you a nice surprise !!!

 

 

이제까지는

큰 문제 -> 작은 문제로 쪼개서 푸는 방법

반복을 줄이기 ! Abstraction

 

 

반복되는 부분을 함수화하는거다 

 

 

 

반복되는 부분을 찾아서 함수화하라! 

 

 

Work Flow

 

test 를 먼저 해본다

코드를 고친다

template을 고친다

definition을 고친다

설명을 고친다

 

;;<Signature>
;; __ __ -> __
(define (map2 fn lon)
  (cond [(empty? lon) empty]
        [else
         (cons (fn (first lon))
               (map2 fn (rest lon)))]))
               
               
            
;;<Signature>
;; (X -> Y) (listof X) -> (listof Y)
(define (map2 fn lon)
  (cond [(empty? lon) empty]
        [else
         (cons (fn (first lon))
               (map2 fn (rest lon)))]))