- Imperative programming: telling the "machine" how to do something, and as a result what you want to happen will happen.
- Declarative programming: telling the "machine"1 what you would like to happen, and let the computer figure out how to do it.
例えば指定されたフォルダー内の.coffee
ファイルを表示する簡単なコードを書きます。
命令型:
fs = require 'fs'
path = require 'path'
dirName = process.argv[2]
dirContents = fs.readdirSync dirName
files = (path.resolve(dirName, file) for file in dirContents when file.indexOf('.coffee') isnt -1)
console.log files
宣言型:
fs = require 'fs'
path = require 'path'
dirName = process.argv[2]
dirContents = fs.readdirSync dirName
files = dirContents
.filter((file) -> file.indexOf('.coffee') isnt -1)
.map((file) -> path.resolve(dirName, file))
console.log files