V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
fantastM
V2EX  ›  Java

热心翻译了 Google Java Style Guide

  •  2
     
  •   fantastM ·
    fantasticmao · 2020-05-06 12:36:19 +08:00 · 4548 次点击
    这是一个创建于 1422 天前的主题,其中的信息可能已经有所发展或是发生改变。
    对着 https://google.github.io/styleguide/javaguide.html 页面逐字逐句翻译了谷歌的 Java 编程风格指南,译文放在 GitHub 仓库上 https://github.com/fantasticmao/google-java-style-guide-zh_cn

    平时在写代码的时候,自己对缩进、对齐、命名之类的代码规范有些轻微洁癖。看完谷歌的这篇风格指南,便决定尝试把它翻译成中文,方便自己查看也方便大家阅读。不过自身能力有限,目前对翻译质量的要求仅是语句通顺,并且不悖原文。有兴趣一起维护的伙伴可以提 Issues 和 Pull requests 。
    15 条回复    2020-05-06 16:39:00 +08:00
    noreplay
        1
    noreplay  
       2020-05-06 12:46:33 +08:00 via Android
    给热心的楼主大佬点赞
    legiorange
        2
    legiorange  
       2020-05-06 12:58:56 +08:00
    感谢!一直以来没有人去做这件事情。
    chanchan
        3
    chanchan  
       2020-05-06 13:00:12 +08:00 via Android
    我怎么记得有人翻译过了呢
    fantastM
        4
    fantastM  
    OP
       2020-05-06 13:10:02 +08:00
    hantsy
        5
    hantsy  
       2020-05-06 13:11:23 +08:00
    Sun 以前的规范在命名方面规定更细一些。

    Google Java Style Guide 最重要是提供了 Eclipse 和 IDEA 配置文件。

    个人我还是喜欢 4 空格缩进。

    Spring 有专门的项目,来提供统一的 IDEA 配置来规范文件格式。
    aaronysj
        6
    aaronysj  
       2020-05-06 13:19:51 +08:00
    点赞
    luckylo
        7
    luckylo  
       2020-05-06 14:40:10 +08:00 via Android
    @hantsy 大佬,我想做个白嫖怪,请问下 spring 的是哪个项目呀
    fantastM
        8
    fantastM  
    OP
       2020-05-06 14:47:07 +08:00
    @hantsy #5 我倒是知道谷歌还有个类似于 Golang 中 go fmt 命令的项目 https://github.com/google/google-java-format
    hantsy
        9
    hantsy  
       2020-05-06 14:56:05 +08:00
    hantsy
        10
    hantsy  
       2020-05-06 15:00:18 +08:00
    参照 readme, https://github.com/spring-io/spring-javaformat/tree/master/.eclipse 下的 Eclipse 配置可以导入 IDEA,Eclipse 。
    hantsy
        11
    hantsy  
       2020-05-06 15:04:12 +08:00
    Spring Code Style 参照了 Google 版本修改的,https://github.com/spring-projects/spring-framework/wiki/Code-Style
    其中就去掉了 2 spaces Indent 。
    yjxjn
        12
    yjxjn  
       2020-05-06 15:06:03 +08:00
    一直在用阿里巴巴的 codestyle,还有插件,也挺好的。
    astkaasa
        13
    astkaasa  
       2020-05-06 15:34:26 +08:00 via iPhone
    spring 的都是 tab 缩进
    luckylo
        14
    luckylo  
       2020-05-06 16:37:33 +08:00
    @hantsy 感谢
    fantastM
        15
    fantastM  
    OP
       2020-05-06 16:39:00 +08:00
    @hantsy #11 谷歌的风格对代码块要求是缩进 2 个空格 https://google.github.io/styleguide/javaguide.html#s4.2-block-indentation,但是对连续的换行(例如 Stream 的链式调用)要求是缩进 4 个空格 https://google.github.io/styleguide/javaguide.html#s4.5.2-line-wrapping-indent

    其实我自己也是主张 4 个空格的...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4537 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 10:07 · PVG 18:07 · LAX 03:07 · JFK 06:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.