TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Do you prefer tailing or leading comma?

1 点作者 aabbcc12415 个月前
In the js space, people often leave a tailing comma at the end of each line, when writing the elements of an array.<p>I was the practise of using leading comma in Elm, where we put a comma at the beginning of each line, when writing elements of a list.<p>I&#x27;m also using leading comma (and leading and&#x2F;or) when writing sql query.<p>For example:<p><pre><code> select user.id , user.username from user where user.ban_time is null and user.activate_time is not null</code></pre>

4 条评论

compressedgas5 个月前
Trailing in languages which support ending the last item with a comma as this follows the usage of the semicolon.<p><pre><code> [ 1, 2, ] </code></pre> Leading otherwise as no language I can remember supports a leading comma on the first item:<p><pre><code> [ 1 , 2 ] </code></pre> The entire point of this is to avoid needing to edit the prior line when inserting items into an existing lexical list this makes the diffs just:<p><pre><code> + </code></pre> instead of:<p><pre><code> - + + </code></pre> If you don&#x27;t care about how your line diffs look, don&#x27;t bother. Just auto-format your code instead.
dsq5 个月前
For me leading commas make stuff easier to debug, you don&#x27;t have to worry about the commas when you comment out the line on the select statement.
vouaobrasil5 个月前
Leading comma seems more intuitive because it immediately signals the end of an entry next to the entry.
solardev5 个月前
I just hit format code and let the IDE or formatter worry about it.