The idea behind top down development - eunmin/Midje GitHub Wiki
Abelson๊ณผ Sussman์ด "programming by wishful thinking"๋ผ๊ณ ๋ถ๋ฅด๋ ์ฝ๋ฉ ๋ฐฉ๋ฒ์ด ์๋ค. ๋น์ ์ ๋ช๊ฐ์ ํจ์๋ฅผ ๋์ถฉ ์์ฑํ๋ค. ์ด๋์ ๋ ์ง๋์ ๋ค๋ฅธ ํจ์์์ ์ ํด๊ฒฐ ํ ์ ์๋ ๋ฌธ์ ๋ฅผ ๋ฐ๊ฒฌํ๊ฒ ๋๋ค. ๋๋ฒ์งธ ํจ์๋ฅผ ์์ฑํ๋ ๋์ ์ ๋๊ตฐ๊ฐ๊ฐ ์์ฑํ๋ค๊ณ ์น๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ ํจ์๋ฅผ ์ฌ์ฉํด์ ๋ฌธ์ ๋ฅผ ํ๊ณ ๊ทธ ๋ค์์ ๊ทธ ํจ์๋ฅผ ์ฐพ๋๋ค. ๋ชป์ฐพ๋๋ค๊ณ ๊ฒฐ๋ก ์ด ๋๋ฉด ๊ทธ ํจ์๋ฅผ ์์ฑํ๋ค. ์ด ๊ณผ์ ์์ ๋ ๋ค๋ฅธ ๋๊ตฐ๊ฐ๊ฐ ์ด๋ฏธ ์์ฑํ๊ธฐ๋ฅผ ๋ฐ๋ผ๋ ์ธ๋ฒ์งธ ํจ์์ ๋ํ ์๊ฐ์ ๊ฐ์ง ์๋ ์์ ๊ฒ์ด๋ค.
And so onโuntil all the functions you need actually have already been written.
์ด๋ฐ ๋ฐฉ์์ ์ฝ๋ฉ์ด ์ด์ํ ๊ฒ์ ์์ ์ด ๋ค ๋๋ ๋๊น์ง ์ค์ ํจ์๋ฅผ ์คํํ ์ ์๋ค๋ ๊ฒ์ด๋ค. (์ต์์์ ํจ์๋ฅผ ์คํํ๊ธฐ ์ ์ ์์กด๋๋ ํจ์๋ฅผ ๋ชจ๋ ๋ง๋ค์ด์ผํ๋ค.) ๋๊ตฐ๊ฐ์๊ฒ๋ ์งํํ๋ฉด์ ๊ตฌ์ฒดํ๋ ๊ฒ ์์ด ์์ ํ๊ธฐ ๊ธด ์๊ฐ์ด๋ค.
Midje๋ prerequisites๋ฅผ ๊ฐ์ง๊ณ ์ด๋ฐ top-down ์คํ์ผ์ ์ง์ํ๋ค. Prequisite๋ ํ๋์ ํจ์์ ๋ค๋ฅธ ํจ์(์์ง ๊ตฌํ์ด ํ์ ์๋) ์ฌ์ด์ ๊ด๊ณ๋ฅผ ๊ธฐ๋กํ๋ค. ์๋ฅผ ๋ค์ด ๋ค์๊ณผ ๊ฐ์ด ํ์๋๋ old-style LED ์ซ์๋ฅผ ์ฝ๋ ์ผ์ด ์๋ค๊ณ ํ์ :
(fact
(account-number [" _ _ _ _ _ _ _ "
" | _| _||_||_ |_ ||_||_|"
" ||_ _| | _||_| ||_| _|"])
=> "123456789")
์ปฌ๋ ์ ์ ๋ฌถ์(๋งต์์ ์ด์ฐจ์ ์ปฌ๋ ์ ๋ฌถ์??? ๊ฐ์ ๊ฒ์ด๋ผ๊ณ ์๊ฐํ๋ค.)์ ์ ๋ ฅ๊ฐ์ผ๋ก ํ์ฌ ํธ์ถํ๋ค. ๋ค์๊ณผ ๊ฐ์ด ๊ฐ๊ฐ์ ์บ๋ฆญํฐ๋ฅผ ์ํ ์ซ์๋ฅผ ๋ชจ์ ๋ค์์ ํ๋์ ๋ฌธ์์ด์ ๋ชจ๋ ๋ฃ๋ ๋ฐฉ๋ฒ์ผ๋ก ๋ฌธ์ ๋ฅผ ํ์ ์๋ค๊ณ ์๊ฐํ ๊ฒ์ด๋ค :
(unfinished digit-parcels digit)
(fact "an account number is constructed from character parcels"
(account-number ..parcel..) => "01"
(provided
(digit-parcels ..parcel..) => [..0-parcel.. ..1-parcel..]
(digit ..0-parcel..) => 0
(digit ..1-parcel..) => 1))
์ฌ๊ธฐ์๋ ํฅ๋ฏธ๋ก์ ๊ฒ๋ค์ด ์๋ค. ์ฒซ์งธ๋ก account-number
์ ๋ ๊ฐ์ helper ํจ์ ์ฌ์ด์ ๊ด๊ณ๋ helper ํจ์๋ค์ด ์ ์๋๊ธฐ ์ ์ ์ฌ์ฉ๋์๋ค.
??์ฐ๋ฆฌ๋ ์์ ์ธ ๊ฐ์ ๋ฌธ์ ๋ค into ํฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค.
We've broken a larger problem into three smaller problems, one of which (how results are assembled) can be coded and checked immediately.
๋ค๋ฅธ ํฅ๋ฏธ๋ก์ด ์ ์ metaconstants๋ฅผ ์ฌ์ฉํ์ฌ ๊ตฌ์ฒด์ ์ธ ๋ฐ์ดํฐ ํํ์ผ๋ก ์ถ์ํ away ํ๋ค๋ ์ ์ด๋ค.
The other interesting thing is that we've abstracted away from a concrete data representation by using metaconstants.
๊ทธ๋ ๊ฒ ํจ์ผ๋ก์ ์ค์ ๋ชจ๋ ๋ฐ์ดํฐ์ ํํ์ ์์กดํ์ง ์๊ณ account-number
๋ฅผ ์์ฑ ํ๋ค. : it hands that issue off to digit-parcels
. ์ด ์คํ์ผ๋ก ์ฝ๋ฉ์ ํ ๋ ์ข
์ข
๋ฐ์ดํฐ ๊ตฌ์กฐ๋ฅผ ๋ช
์ํ๋ ๊ฒ์ ํ์ ํ๊ธฐ ์ ์ ์ฝ๋ฉ์ ํ ์ ์๋ค.(go a way)
By doing that, we've documented that account-number
doesn't actually depend on the "shape" of the data at all: it hands that issue off to digit-parcels
. When coding in this style, you can often go quite a way before having to commit to specific data structures.
์ถ์ํ ๋จ๊ณ๊ฐ ์ฌ๋ผ๊ฐ๋ฉด์ ํ๋ก๊ทธ๋จ์ logical structure๋ก ์๊ฐํ๋ฉด์ prerequisites๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ์ ์ ์๋ค. ๊ทธ๊ฑด checkable facts ์ฃผ์์ด ๋ฌ๋ฆฐ ํจ์๋ค์ ๋ชจ์์ด๋ค. ๋์ฑ์ด ์ด ํจ์๋ค์ facts๋ก ์์ฑ๋ ๊ด๊ณ๋ค์ ์์กด์ฑ์ ์ํด์ ์ฐ๊ฒฐ๋์ด ์๋ค.