为什么switch语句的怪缩进? [英] Why the strange indentation on switch statements?

查看:1823
本文介绍了为什么switch语句的怪缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么恕我直言缺少案例的压痕 - 关键字switch语句中考虑好作风

Why is the imho missing indentation of the "case" - keywords in a switch statement considered good style?

无案例关键字的缩进似乎是在大约每IDE默认格式化选项:

no indentation of the "case" keyword seems to be the default formatting option in about every IDE:

switch (i){
case 0:
    break;
case 1:
    break;
}

而我觉得这种形式更直观的:

while i find this format more intuitive:

switch (i){
    case 0:
        break;
    case 1:
        break;
}

有没有这背后一些逻辑,那逃避我?

Is there some logic behind this, that eludes me?

推荐答案

的情况下,在逻辑上是标签。很多人把标签的同时缩进层次,因为它们是在块。在我看来,这种方式更容易通过文字阅读。

The cases are logically labels. Many people put labels at the same indentation level as the block they are in. In my opinion, that way it's easier to read through the text.

我和你可以滚动时间线进行比较。你必须在时间线上本身标记,而不是缩进到内容。然后,您可以快速地指出哪里标签/标志物,无需从基线移动你的眼睛了。

I compare it with a timeline you can scroll through. You have markers on the time line itself, not indented into the content. You can then quickly point out where labels/markers are, without moving your eye away from the base-line.

这篇关于为什么switch语句的怪缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆