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๋กœ ์ž‘์„ฑ๋œ ๊ด€๊ณ„๋“ค์˜ ์˜์กด์„ฑ์— ์˜ํ•ด์„œ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋‹ค.

Interrelationships

โš ๏ธ **GitHub.com Fallback** โš ๏ธ