各位企业项目开发中代码的注释需要写英文注释吗?

有些公司因为内码问题,在编码规范中强制规定部分语言的注释只允许用英文。
但是好像大部分日常写代码时 我们用的还是中文注释。

我现在想满满养成英文注释的习惯,但是不知道以后在公司中该准售怎样的一个准则。
比如:

  • 参数注释需要英文吗?
  • 方法的注释需要使用英文吗?
  • 打印日志需要用英文吗?
  • 代码中的print可以打印英文吗?如果需要用中文,是否可以将参数用英文?
  • 等等,或者各位的大佬们在其他地方还有以下注意的事项,也可以告诉我一哈~

我的注释:
(部分代码)

class Bayes():
    def __init__(self, 
    absPath:dict(type = str, help="Directory of the current file") = os.path.dirname(os.path.abspath(__file__)),
    ):
        self.absPath = absPath

    #contain all documents and list without duplicate words
    def createVocabList(self, 
    dataSet:dict(type="", help = "the source data"),
    )->dict(type=list, help = "Deduplicated list"):
        vocabSet=set([]) #creat an empty set,'set' is a list without duplicate words
        for document in dataSet:
            vocabSet=vocabSet|set(document) #create an union of two sets
        return list(vocabSet)

    #determine if a term appears in the documents
    def setOfWords2Vec(self, 
    vocabList = dict(type="", help="a glossary "), 
    inputSet = dict(type="", help="The word you want to detect"), 
    )->dict(type="", help="Word vector"):
        returnVec = [0]*len(vocabList)
        for word in inputSet:
            if word in vocabList:
                returnVec[vocabList.index(word)] = 1
            else:
                print("单词: %s 不在我的词汇里面!" % word)#Returns a document vector indicating whether a word has appeared 1/0 in the input document
        return returnVec
文章!!首发于我的博客Stray_Camel(^U^)ノ~YO
Jason990420
最佳答案

注释

  • 代码更新时,也请更新注释.
  • 注释要是一个完整的句子;第一个字除非是变量名,否则应该要大写;每个句子结束要有句点;两个句子之间应该要有两个空格.
  • 英文书写请依循 "Strunk and White" (英文写作指南).
  • 除非很确定代码不会被其他语言国家的人来读,否则请以英文来书写.
  • 区块注释中的段落使用一个 # 的空行来分隔.
  • 行注释少用,使用时,至少空两个空格,# 后加一个空格,语意明显的就不用说明

PEP 8 程序代码的编写风格指南

4年前 评论
讨论数量: 2
Jason990420

注释

  • 代码更新时,也请更新注释.
  • 注释要是一个完整的句子;第一个字除非是变量名,否则应该要大写;每个句子结束要有句点;两个句子之间应该要有两个空格.
  • 英文书写请依循 "Strunk and White" (英文写作指南).
  • 除非很确定代码不会被其他语言国家的人来读,否则请以英文来书写.
  • 区块注释中的段落使用一个 # 的空行来分隔.
  • 行注释少用,使用时,至少空两个空格,# 后加一个空格,语意明显的就不用说明

PEP 8 程序代码的编写风格指南

4年前 评论

建议中文, 除非你英文水平很高,不然得不偿失

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!