dtll2016 2015-01-23 15:42
浏览 20
已采纳

多行字符串文字的缩进样式

What is the proposed style for indenting a raw string literal? If I indent it based on its first line, it might not align properly in editors that have a different tab length. For example:

if select == nil {
    select, err = db.Prepare(`select name
                              from table
                              where id=$1`)
    if err != nil {
        return nil, err
    }
}

I have found this question, but I am still unclear: Best practice for long string literals in Go

Should I do it like below?

if select == nil {
    select, err = db.Prepare(`
select name
from table
where id=$1`)
    if err != nil {
        return nil, err
    }
}
  • 写回答

1条回答 默认 最新

  • dtch60248 2015-01-23 15:46
    关注

    Considering both propositions would add newline or spaces to the litteral string, I would favor (even though fmt format the first line):

        select, err = db.Prepare(
         `select name
    from table
    where id=$1`)
    

    As the OP akonsu comments below, it seems consistent with the style of the golang code itself, as seen in src/cmd/go/main.go#L175, which keeps the first line at the level of the opening '('

    var usageTemplate = `Go is a tool for managing Go source code.
    Usage:
    go command [arguments]
    ...
    `
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复