麻烦哪位截取一下图,让我看看什么才算是优雅的代码,不限语言。

355 天前
 go522000

没有挑剔的意思,单纯想看看了解一下。

比如 redis 的代码,我就觉得这代码相当漂亮,工整,注释也写得好。当然也有人不这么认为,觉得注释太多,觉得好的代码不需要注释等等。

萝卜白菜各有所爱,希望各位截下图或分享一下代码。

1787 次点击
所在节点    问与答
18 条回复
zzNaLOGIC
355 天前
大家都是摸鱼的时候吹牛逼才这么说的,你还当真了
IceBay
355 天前
自己写的时候,好的代码不需要注释。
看别人的代码,该喷为什么不写注释了。
alteremliu
355 天前
Zzyomirog
355 天前
@alteremliu 想到了睡眠排序
tool2d
355 天前
rookie4show
355 天前
编程之美吧
neptuno
355 天前
@Zzyomirog #4 还有猴子排序
likeme
355 天前
有没有 Java 项目看看的
TWorldIsNButThis
355 天前
代数建模
业务与代码同构
LaTero
355 天前
BQN ,APL 之类的语言够不够优雅
zachlhb
355 天前
自己写的代码永远最优雅,别人写的什么玩意
YsHaNg
355 天前
Prime Sieve in APL (2=+⌿0=(⍳X)∘.|⍳X)/⍳X
storyxc
355 天前
linus 在 TED 的一期节目里说了他自己认为有品味的代码:
```
remove_list_entry(entry)
{
// The "indirect" pointer points to the
// *address* of the thing we'll update

indirect = &head;

// Walk the list, looking for the thing that
// points to the entry we want to remove

while ((*indirect) != entry)) {
indirect = &(*indirect)->next;
}

// .. and just remove it
*indirect = entry->next;
}
```

与之相反,不够 good taste 的代码
```
remove_list_entry(entry)
{
prev = NULL;
walk = head;

// Walk the list
while (walk != entry) {
prev = walk;
walk = walk->next;
}

// Remove the entry by updating the
// head or the previous entry
if(!prev) {
head = entry->next;
} else {
prev->next = entry->next;
}
}
```
dingdangnao
355 天前
if error return "OK"
gowl
355 天前
dosomethingcool
354 天前
工作中项目代码最大的问题一般都是注释太少,写需求的时候一哪有那么多时间一行行读别人的代码
cslive
354 天前
if true return true
humpy
354 天前
垠神用 parser combinator 写的 lisp parser:

(:: $open
(@or (@~ "(") (@~ "[")))

(:: $close
(@or (@~ ")") (@~ "]")))

(:: $non-parens
(@and (@! $open) (@! $close)))

(::= $parens 'sexp
(@seq $open (@* $sexp) $close))

(:: $sexp
(@+ (@or $parens $non-parens)))

(:: $program $sexp)

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

https://www.v2ex.com/t/954933

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

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

© 2021 V2EX