在上一篇文章中,小编为您详细介绍了关于《魔兽世界好玩么?魔兽世界森提纳克斯号咋上去》相关知识。本篇中小编将再为您讲解标题Nodejs 未来会超越 Java 么?es6 generator到底有什么样用。
问题本身没多少意义,但是讨论其优劣势、用途、发展现状是很有意义的,提问的目的更倾向于恐怕是后者。
想多了,还是省省吧。
祸害完前端又想来祸害后端了。
看看人家PHP,作为最好的编程语言,人家就乖乖的,做做网页,不再有非分之想了。
Uriel hates Node.js
Node.js is one of the worst things to happen to the software industry in recent times, a whole generation of programmers are being taught the worst of all ways of doing concurrency, in a system that doesn’t scale either in performance or project size and with one of the languages most plagued by pitfalls ever created.
JavaScript was already painful enough in the browser, why on earth anyone ever thought it was a good idea to use it on the server boggles the mind.
We will be paying the price of this misguided hyped fad for decades to come.
Of all the ways of doing concurrency, callbacks are by far the worst, Twisted was plagued by them and is the main reason why it failed, and that was with a much more sane and reasonable language like Python (stackless Python was a much better alternative and used a model similar to Go’s CSP).
And the sad thing is that there are much better alternatives around with much more sound models and environments, Erlang and Go are the two obvious examples, and that is for the highly specialized situations where you have great concurrency needs, for any other problem anything else will be much better than Node.js, even PHP.
– uriel, in response to Why Node.JS is absolutely terrible, by Hasen el Judy
Even Ryan Dahl hates Node.js
I hate almost all software. It’s unnecessary and complicated at almost every layer. At best I can congratulate someone for quickly and simply solving a problem on top of the shit that they are given. The only software that I like is one that I can easily understand and solves my problems. The amount of complexity I’m willing to tolerate is proportional to the size of the problem being solved.
In the past year I think I have finally come to understand the ideals of Unix: file descriptors and processes orchestrated with C. It’s a beautiful idea. This is not however what we interact with. The complexity was not contained. Instead I deal with DBus and /usr/lib and Boost and ioctls and SMF and signals and volatile variables and prototypal inheritance and C⑨⑨FEATURES_ and dpkg and autoconf.
Those of us who build on top of these systems are adding to the complexity. Not only do you have to understand $LD_LIBRARY_PATH to make your system work but now you have to understand $NODE_PATH too - there’s my little addition to the complexity you must now know! The users - the one who just want to see a webpage - don’t care. They don’t care how we organize /usr, they don’t care about zombie processes, they don’t care about bash tab completion, they don’t care if zlib is dynamically linked or statically linked to Node. There will come a point where the accumulated complexity of our existing systems is greater than the complexity of creating a new one. When that happens all of this shit will be trashed. We can flush boost and glib and autoconf down the toilet and never think of them again.
Those of you who still find it enjoyable to learn the details of, say, a programming language - being able to happily recite off if NaN equals or does not equal null - you just don’t yet understand how utterly fucked the whole thing is. If you think it would be cute to align all of the equals signs in your code, if you spend time configuring your window manager or editor, if put unicode check marks in your test runner, if you add unnecessary hierarchies in your code directories, if you are doing anything beyond just solving the problem - you don’t understand how fucked the whole thing is. No one gives a fuck about the glib object model.
The only thing that matters in software is the experience of the user.
– Ryan Dahl, creator of Node.js, in a controversial post that has since been deleted from Google Plus
Node.js community hates itself
Collaboration not Derision in the Node Community (related: HN thread)
HN上的相关讨论:
“Node.js is one of the worst things to happen to the software industry†(②⓪①②)
如果题主学过①点 python 就不会觉得 generator 没有用了
先简单介绍下 generator
形式上,Generator 函数是①个普通函数,但是有两个特征。①是,function关键字与函数名之间有①个星号;②是,函数体内部使用yield语句,定义不同的内部状态
function* helloWorldGenerator() { yield \'hello\'; yield \'world\'; return \'ending\';}var hw = helloWorldGenerator();
Generator函数的调用方法与普通函数①样,也是在函数名后面加上①对圆括号。不同的是,调用Generator函数后,该函数并不执行,返回的也不是函数运行结果,而是①个指向内部状态的指针对象,我们可以通过调用 next 方法,使得指针移向下①个状态
hw.next()// { value: \'hello\', done: false }hw.next()// { value: \'world\', done: false }hw.next()// { value: \'ending\', done: true }hw.next()// { value: undefined, done: true }
这是基础用法,还有①点不得不介绍:next给函数内变量传值
function* f() { for(var i = ⓪; true; i++) { var reset = yield i; if(reset) { i = -①; } }}var g = f();g.next() // { value: ⓪ · done: false }g.next() // { value: ① · done: false }g.next(true) // { value: ⓪ · done: false }
上面代码先定义了①个可以无限运行的 Generator 函数f,如果next方法没有参数,每次运行到yield语句,变量reset的值总是undefined。当next方法带①个参数true时,变量reset就被重置为这个参数(即true),因此i会等于-① · 下①轮循环就会从-①开始递增。这个功能有很重要的语法意义。Generator 函数从暂停状态到恢复运行,它的上下文状态(context)是不变的。通过next方法的参数,就有办法在 Generator 函数开始运行之后,继续向函数体内部注入值。也就是说,可以在 Generator 函数运行的不同阶段,从外部向内部注入不同的值,从而调整函数行为。这个用处在其用来实现 async/await 至关重要。
简单吧?到次 generator 介绍完毕
下面说说用处
## infinite range & lazy evaluation
for...of循环可以自动遍历Generator函数时生成的Iterator对象,且此时不再需要调用next方法。
function *foo() { yield ①; yield ②; yield ③; yield ④; yield ④+①; //只有在获取第⑤个元素时才会计算 return ⑥;}for (let v of foo()) { console.log(v);}// ① ② ③ ④ ⑤
这里只是①个lazy evaluation例子,同样你可以将这个例子改为获取 ①到无穷 所有的整数。
- async/await
这里的实现原理有点复杂可以参考下阮①峰的ECMAScript ⑥ 入门
答案很多案例参考这篇教材 在此感谢!
点赞加关注,干货持续分享中
编后语:关于《Nodejs 未来会超越 Java 么?es6 generator到底有什么样用》关于知识就介绍到这里,希望本站内容能让您有所收获,如有疑问可跟帖留言,值班小编第一时间回复。 下一篇内容是有关《预算10000不加显示器?想买thinkpad t400》,感兴趣的同学可以点击进去看看。
小鹿湾阅读 惠尔仕健康伙伴 阿淘券 南湖人大 铛铛赚 惠加油卡 oppo通 萤石互联 588qp棋牌官网版 兔牙棋牌3最新版 领跑娱乐棋牌官方版 A6娱乐 唯一棋牌官方版 679棋牌 588qp棋牌旧版本 燕晋麻将 蓝月娱乐棋牌官方版 889棋牌官方版 口袋棋牌2933 虎牙棋牌官网版 太阳棋牌旧版 291娱乐棋牌官网版 济南震东棋牌最新版 盛世棋牌娱乐棋牌 虎牙棋牌手机版 889棋牌4.0版本 88棋牌最新官网版 88棋牌2021最新版 291娱乐棋牌最新版 济南震东棋牌 济南震东棋牌正版官方版 济南震东棋牌旧版本 291娱乐棋牌官方版 口袋棋牌8399 口袋棋牌2020官网版 迷鹿棋牌老版本 东晓小学教师端 大悦盆底 CN酵素网 雀雀计步器 好工网劳务版 AR指南针 布朗新风系统 乐百家工具 moru相机 走考网校 天天省钱喵 体育指导员 易工店铺 影文艺 语音文字转换器