你怎么看待“文学编程”?

2015-08-12 19:32:27 +08:00
 Feiox

文学编程 wiki

另外,你怎么看待向 Python 这种弱化对符号的运用,转而使用英语单词来作为程序的主要组成部分,例如
yield from
a if b else c
if key in myset:
if var is False
with Abc as abc:
for k,v in itervalue.iteritems() 等。

LZ 的观点是非常喜爱,最近挺流行的 semantic-ui 也是使用了大量非常英语化的词汇。

7371 次点击
所在节点    编程
39 条回复
aivier
2015-08-13 09:13:44 +08:00
其实看到文章开头代码的第一眼,我还以为那是乱码....
cbsw
2015-08-13 09:26:48 +08:00
http://orgmode.org/features.html#sec-8 早就说过 Emacs 是最强大的编辑器,org-mode 8.3.1 前几天已经出来了
CodingMonkey
2015-08-13 09:32:13 +08:00
我觉得没有符号一点都不酷
justjavac
2015-08-13 09:40:34 +08:00
难道楼主没有听说过 perl 吗?

#!/usr/bin/perl

listen(please,please);

open yourself,wide;
join(you,me),
connect(us,together),

tell me.

do something if distressed;

@dawn,dance;

@evening,sing;
read(books,$poems,stories) until peaceful;
study if able;

write me if-you-please;

sort your feelings,reset goals,seek(friends,family,anyone);

do*not*die(like this)
if sin abounds;
keys (hidden),open(locks,doors),tell secrets;
do not, I-beg-you, close them,yet.

accept(yourself,changes),
bind(grief,despair);

require truth,goodness if-you-will,each moment;

select(always),length(of-days)
tcdw
2015-08-13 10:24:45 +08:00
我并不是非常喜欢。
反复的使用一堆英语单词,在编程过程中实在是啰嗦又麻烦,而且至少源代码会消耗大量磁盘空间。
我认为掌握那些符号的使用更实在。
banri
2015-08-13 10:54:39 +08:00
喜欢,毕竟文科狗
Agromania
2015-08-13 11:05:15 +08:00
我更喜欢 a ? b : c
robertlyc
2015-08-13 15:26:48 +08:00
我猜楼主一定不知道DSL
Feiox
2015-08-13 16:07:49 +08:00
@robertlyc 倒不是,我们在项目中使用了很多、各种语意化的自实现的 DSL,因为团队里用的是 Python
@tcdw 额,要写多少代码才会多占用 1M 的空间呢?
@notcome @sinxccc 我知道文学编程,我提问中谈到语意化语法元素的时候,说了 “另外” 然后大家都只聊到了“另外”里的内容 ~ 不过,我到是觉得 TeX 是反语义化的代表 ~
@Agromania 但据说 a if b else c 是很符合英语的风格 ~
robertlyc
2015-08-13 16:14:51 +08:00
@Feiox 错怪lz了 应该说是大部分的答题者不懂
Tomilay
2015-08-13 16:16:18 +08:00
我觉得写Perl的时候才是爽歪歪~~
shawngao
2015-08-13 16:20:57 +08:00
你们咋没人提到Apple Script
kkurs
2015-08-13 16:24:24 +08:00
@notcome
+1, 楼主举得这几个例子根本不是literature programming
Feiox
2015-08-13 16:30:59 +08:00
@robertlyc @kkurs 哈哈,我的错,我错把两个概念相近的问题放在了一起,成功的使大多数人都没有意识到 “另外” 二字后面是另一个问题。。。。。
@robertlyc wiki 上讲到了利用宏,将原始程序掩盖起来,我觉得这和近年来流行的 DSL 很像。我们项目内部也有很多自实现的声明式 DSL 来将业务逻辑分离成 定义 和 操作 两个部分,这和高老说的 “使用WEB编程后,我意识到不必在自顶向下和自底向上之间艰难抉择” 异曲同工。
notcome
2015-08-13 19:29:41 +08:00
@Feiox TeX 是反语义化的代表?哈哈哈兄弟率直我喜欢。我觉得世界上最搞笑的一件事,就是 TeX 的宏系统没有对命令和文本有什么明显的区分,TeX 用户却经常标榜自己是样式与内容分离的典范,哈哈哈。我最喜欢黑 TeX了。

不过可悲的是竟然没有比 TeX 好很多的产品可以用。
notcome
2015-08-13 19:40:23 +08:00
@JamesRuan
> 反例很容易举出来啊,去看看haskell的代码,几乎没有符号(很多还是自己造的运算符,比如>>=这种),可读性很高吗?反之,很多情况下,简洁的符号就可以提高可读性(支持运算符重载的一个作用)。

你能解释一下为什么你说 Haskell 没有符号,却同时说 Haskell 有很多自造的运算符吗?很多常用的代码里(又在黑 parser,逃)我看到的就是 Applicative Monad Arrow 满天飞啊,什么 a *> b <* c 看到萌死掉了。

可读性这个问题其实跟采取哪种方式没有关联,更主要还是看库的设计。就比如 Haskell 吧,它确实符号满天飞,很多初学者看到 Applicative 那套,肯定疯了,觉得故意炫技,不适合工程。可同时我们必须意识到,Haskell 的抽象概念比别的语言要多那么一点,符号虽然多了,但定义的很好,熟悉起来用着一样飞快。

类似的,用自然语言也是一个样子,库本身很重要。要是你遇到个风格自相矛盾的库,肯定会骂人。至于多打几个字,我真不觉得是大问题。
qqqppp9998
2015-08-13 20:37:09 +08:00
个人挺喜欢
RqPS6rhmP3Nyn3Tm
2015-08-13 21:24:37 +08:00
各位不知道莎士比亚语言吗?

The Infamous Hello World Program.

Romeo, a young man with a remarkable patience.
Juliet, a likewise young woman of remarkable grace.
Ophelia, a remarkable woman much in dispute with Hamlet.
Hamlet, the flatterer of Andersen Insulting A/S.


Act I: Hamlet's insults and flattery.

Scene I: The insulting of Romeo.

[Enter Hamlet and Romeo]

Hamlet:
You lying stupidfatherless big smelly half-witted coward!
You are as stupidas the difference between a handsome rich brave
hero and thyself!Speak your mind!

You are as braveas the sum of your fat little stuffed misused dusty
old rotten codpiece and a beautiful fair warm peaceful sunny summer's
day. You are ashealthy as the difference between the sum of the
sweetest reddestrose and my father and yourself! Speak your mind!

You are ascowardly as the sum of yourself and the difference
between a bigmighty proud kingdom and a horse. Speak your mind.

Speak your mind!

[Exit Romeo]

Scene II: The praising of Juliet.

[Enter Juliet]

Hamlet:
Thou art as sweetas the sum of the sum of Romeo and his horse and his
black cat! Speakthy mind!

[Exit Juliet]

Scene III: The praising of Ophelia.

[Enter Ophelia]

Hamlet:
Thou art as lovelyas the product of a large rural town and my amazing
bottomless embroidered purse. Speak thy mind!

Thou art as lovingas the product of the bluest clearest sweetest sky
and the sum of asquirrel and a white horse. Thou art as beautiful as
the difference between Juliet and thyself. Speak thy mind!

[Exeunt Ophelia and Hamlet]


Act II: Behind Hamlet's back.

Scene I: Romeo and Juliet's conversation.

[Enter Romeo and Juliet]

Romeo:
Speak your mind.You are as worried as the sum of yourself and the
difference betweenmy small smooth hamster and my nose. Speak your
mind!

Juliet:
Speak YOUR mind!You are as bad as Hamlet! You are as small as the
difference between the square of the difference between my little pony
and your big hairyhound and the cube of your sorry little
codpiece. Speakyour mind!

[Exit Romeo]

Scene II: Juliet and Ophelia's conversation.

[Enter Ophelia]

Juliet:
Thou art as goodas the quotient between Romeo and the sum of a small
furry animal and aleech. Speak your mind!

Ophelia:
Thou art asdisgusting as the quotient between Romeo and twice the
difference betweena mistletoe and an oozing infected blister! Speak
your mind!

[Exeunt]

此段代码的作用是打印"Hello World!"
endrollex
2015-08-13 22:49:27 +08:00
还是用符号把逻辑和变量分开比较可读
符号的特点就比文字更抽象简洁,而且数学符号很难弃用

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://tanronggui.xyz/t/212756

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX