由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
相关主题
GOTO (2)C10M除了socket以外,还牵涉其他方面的技巧
setjmp() and longjmp()请教python高手异步编程的问题
How to become a better programmernode.js不可放弃
看了这篇文章关于Javascript Closure就醍醐灌顶了感觉并发模型上go可以秒vertx
有人用过 fiber/Coroutine 做 real time 的数据处理吗?coroutine or thread
Python is easy and not easyyield和goroutine啥区别?
Python Concurrency 主流是用啥C++ 有没有像go routine/channel 一样的库/框架?
Guido on Python AsyncIO (1/23/2014)我是一个线程 (转载)
相关话题的讨论汇总
话题: goto话题: label话题: longjmp话题: 实现话题: setjmp
进入Programming版参与讨论
1 (共1页)
g****t
发帖数: 31659
1
如果有了GOTO语句,能消灭一大半语法糖。
我当初什么coroutine,tail call continuation花了很多时间。
以为有什么新东西。其实就是用没有GOTO语句的办法实现GOTO。
Go language的作者不含糊:
https://golang.org/ref/spec#Goto_statements
object-C有GOTO, swift没有,肯定会催生一堆看着牛X的术语,
什么co-routine,tail call continuation,....
任何一个使用GOTO的pattern,你给用没GOTO的
语言实现了,说不定就能造一个名词
w***g
发帖数: 5958
2
我星宿派威武。请总结几个用goto的pattern看看。

【在 g****t 的大作中提到】
: 如果有了GOTO语句,能消灭一大半语法糖。
: 我当初什么coroutine,tail call continuation花了很多时间。
: 以为有什么新东西。其实就是用没有GOTO语句的办法实现GOTO。
: Go language的作者不含糊:
: https://golang.org/ref/spec#Goto_statements
: object-C有GOTO, swift没有,肯定会催生一堆看着牛X的术语,
: 什么co-routine,tail call continuation,....
: 任何一个使用GOTO的pattern,你给用没GOTO的
: 语言实现了,说不定就能造一个名词

g****t
发帖数: 31659
3
Below is an example:
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
这哥们没发现他这写的里面,goto label的实现是最强壮的。
认为ugly,折腾了这么长的语法糖。理由就是goto不好看。
其实我们硬件接收ADC来的电流电压数据,最后就是汇编
的几个JUMP然后yield之类的函数包起来。都用了几十年了。
当然我们是故意锁死客户,
就是不用ARM,自己写了几个死循环当OS。

我星宿派威武。请总结几个用goto的pattern看看。

【在 w***g 的大作中提到】
: 我星宿派威武。请总结几个用goto的pattern看看。
g****t
发帖数: 31659
4
How to eliminate GOTO/label?
All these games are resulted from below paper:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.119.9119&rep=rep1&type=pdf

【在 g****t 的大作中提到】
: Below is an example:
: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
: 这哥们没发现他这写的里面,goto label的实现是最强壮的。
: 认为ugly,折腾了这么长的语法糖。理由就是goto不好看。
: 其实我们硬件接收ADC来的电流电压数据,最后就是汇编
: 的几个JUMP然后yield之类的函数包起来。都用了几十年了。
: 当然我们是故意锁死客户,
: 就是不用ARM,自己写了几个死循环当OS。
:
: 我星宿派威武。请总结几个用goto的pattern看看。

g****t
发帖数: 31659
5
another example:
https://en.wikipedia.org/wiki/State_pattern
GOTO/label is clearly much better than the "state_pattern".

【在 g****t 的大作中提到】
: How to eliminate GOTO/label?
: All these games are resulted from below paper:
: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.119.9119&rep=rep1&type=pdf

h**********c
发帖数: 4120
6
还有啥longjmp, sigjmp,跳到另外一个程序的空间里,还可以跳到另外一台电脑里。
g****u
发帖数: 252
7
没这事,只能在操统线程内部跳。setjmp longjmp就是动态产生label的goto. c里没有
异常,在call stack 里要直接往回跳几层就只能靠这个。还有coroutine, 用户态线程
等magic也可以用这个实现。

【在 h**********c 的大作中提到】
: 还有啥longjmp, sigjmp,跳到另外一个程序的空间里,还可以跳到另外一台电脑里。
g****t
发帖数: 31659
8
比较起来,GOTO/Label比exceptions, try, finally,generator....
有某方面的优势。
goto/label的语法不可能随时间改变,因为太简单了没什么改变的余地。
这类永远不会变的语法,适合中老年。

没这事,只能在操统线程内部跳。setjmp longjmp就是动态产生label的goto. c里没有

【在 g****u 的大作中提到】
: 没这事,只能在操统线程内部跳。setjmp longjmp就是动态产生label的goto. c里没有
: 异常,在call stack 里要直接往回跳几层就只能靠这个。还有coroutine, 用户态线程
: 等magic也可以用这个实现。

h**********c
发帖数: 4120
9
https://blog.acolyer.org/2015/09/18/buffer-overflows-attacks-and-defenses-
for-the-vulnerability-of-the-decade/
"Likewise a setjmp/longjmp buffer adjacent to an overflowable buffer can
also be overwritten, changing the destination the program jumps to."
This is not my area.

没这事,只能在操统线程内部跳。setjmp longjmp就是动态产生label的goto. c里没有

【在 g****u 的大作中提到】
: 没这事,只能在操统线程内部跳。setjmp longjmp就是动态产生label的goto. c里没有
: 异常,在call stack 里要直接往回跳几层就只能靠这个。还有coroutine, 用户态线程
: 等magic也可以用这个实现。

J*****s
发帖数: 110
10
作者是putty的owner。膜拜一下。
作者说:
PuTTY is a Win32 Telnet and SSH client. The SSH protocol code contains real-
life use of this coroutine trick. As far as I know, this is the worst piece
of C hackery ever seen in serious production code.
哈哈。

【在 g****t 的大作中提到】
: Below is an example:
: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
: 这哥们没发现他这写的里面,goto label的实现是最强壮的。
: 认为ugly,折腾了这么长的语法糖。理由就是goto不好看。
: 其实我们硬件接收ADC来的电流电压数据,最后就是汇编
: 的几个JUMP然后yield之类的函数包起来。都用了几十年了。
: 当然我们是故意锁死客户,
: 就是不用ARM,自己写了几个死循环当OS。
:
: 我星宿派威武。请总结几个用goto的pattern看看。

g****t
发帖数: 31659
11
I seriously believed他对goto那个实现的评价不成立。
"It's still ugly, though. The worst part of it is that the set of labels
must be maintained manually, and must be consistent between the function
body and the initial switch statement. Every time we add a new return
statement, we must invent a new label name and add it to the list in the
switch; every time we remove a return statement, we must remove its
corresponding label. We've just increased our maintenance workload by a
factor of two."
(1)
他那个实现,如果哪天C把switch的标准改了,或者有的芯片
实现的C不包含switch那个trick,不就废了。
用switch case实现goto label,有任何一点好处吗。。。
(2)
label起个名字叫做label0,label1。
他就不能起个名字叫做label_pair_with_returnxxx吗?
(3)
Linux kernal里面,没有1万也得8千goto出现。很多都是状态机类似的东西。

real-
piece

【在 J*****s 的大作中提到】
: 作者是putty的owner。膜拜一下。
: 作者说:
: PuTTY is a Win32 Telnet and SSH client. The SSH protocol code contains real-
: life use of this coroutine trick. As far as I know, this is the worst piece
: of C hackery ever seen in serious production code.
: 哈哈。

s********k
发帖数: 6180
12
embedded system 大把大把的goto

【在 g****t 的大作中提到】
: 如果有了GOTO语句,能消灭一大半语法糖。
: 我当初什么coroutine,tail call continuation花了很多时间。
: 以为有什么新东西。其实就是用没有GOTO语句的办法实现GOTO。
: Go language的作者不含糊:
: https://golang.org/ref/spec#Goto_statements
: object-C有GOTO, swift没有,肯定会催生一堆看着牛X的术语,
: 什么co-routine,tail call continuation,....
: 任何一个使用GOTO的pattern,你给用没GOTO的
: 语言实现了,说不定就能造一个名词

d*******r
发帖数: 3299
13
计算底层模型本来就是 一维数组+Goto语句
所以,你总能用这2个东西模拟所谓"高级逻辑"
比如 if else, function, try catch 之类都是在 程序源码一维数组上做 Goto.
比如 堆栈, 树, hashtable 和其他数据结构,也是一维数组上用Goto 模拟的.
但是"高级逻辑"解决某些问题时候,更符合人类思维习惯, 所以才流行.
任意的 Goto 跳转,主要问题是, 容易破坏人思考问题的上下文边界.
如果注意了这问题,Goto 当然是可以用的.
1 (共1页)
进入Programming版参与讨论
相关主题
我是一个线程 (转载)有人用过 fiber/Coroutine 做 real time 的数据处理吗?
coroutine comes to Java - Project LoomPython is easy and not easy
Typescript是不是实际上反 functional programming 的?Python Concurrency 主流是用啥
vertx 3.5出来了。谁讲讲kotlin coroutine?Guido on Python AsyncIO (1/23/2014)
GOTO (2)C10M除了socket以外,还牵涉其他方面的技巧
setjmp() and longjmp()请教python高手异步编程的问题
How to become a better programmernode.js不可放弃
看了这篇文章关于Javascript Closure就醍醐灌顶了感觉并发模型上go可以秒vertx
相关话题的讨论汇总
话题: goto话题: label话题: longjmp话题: 实现话题: setjmp