一、框架设计概览
申明式与命令式(Declarative vs Imperative)
申明式和命令式是两种编程范式。vue/react
是申明式的,jquery 那样间接操作 dom 是命令式
Alright here’s a metaphor.
Declarative Programming is like asking your friend to draw a landscape. You don’t care how they draw it, that’s up to them.
Imperative Programming is like your friend listening to Bob Ross tell them how to paint a landscape. While good ole Bob Ross isn’t exactly commanding, he is giving them step by step directions to get the desired result.
申明式就像你通知你敌人画一幅画,你不必去管他怎么画的细节
命令式就像依照你的命令,你敌人一步步把画画进去
换言之
- 命令式编程:命令“机器”如何去做事件(how),这样不论你想要的是什么(what),它都会依照你的命令实现。
- 申明式编程:通知“机器”你想要的是什么(what),让机器想出如何去做(how)。
在放弃可维护性的同时让性能损失最小化。