LoginSignup
1
1

More than 5 years have passed since last update.

命令型 vs 宣言型プログラミング

Posted at

  • 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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1