On Code Comment

Brian W. Kernighan and Rob Pike have some excellent suggestions for writing comments. They are said best as they appear in "The Practice of Programming," [1]:

  • Don't belabor the obvious. Comments shouldn't report self-evident information such as the fact that i++ has incremented i.

     

  • Don't comment bad code, rewrite it. Comment anything unusual or potentially confusing, but when the comment outweighs the code, the code probably needs fixing.

     

  • Don't contradict the code. Most comments agree with the code when they are written, but as bugs are fixed and the program evolves, the comments are often left in their original form, resulting in disagreement with the code. Whatever the source of disagreement, a comment that contradicts the code is confusing, and many a debugging session has been needlessly protracted because a mistaken comment was taken as truth. When you change code, make sure that the comments are still accurate. Comments should not only agree with code, they should support it.

     

  • Clarify, don't confuse. Comments are supposed to help readers over the hard parts, not create more obstacles.

     

  • When it takes more than a few words to explain what's happening, it's often an indication that code should be rewritten.

     

  • Students are taught that it's important to comment everything. Professional programmers are often required to comment all their code. But the purpose of commenting can be lost in blindly following rules. Comments are meant to help a reader understand parts of the program that are not readily understood from the code itself. As much as possible, write code that is easy to understand; the better you do this, the fewer comments you need. Good code needs fewer comments than bad code.

References

[1] Kernighan, Brian W. and Pike, Rob, The Practice of Programming, Addison Wesley, 1999, pages 23-27.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DROP TABLE IF EXISTS "pisso_account" CASCADE; DROP SEQUENCE IF EXISTS "pisso_account_id_seq" CASCADE; CREATE SEQUENCE "pisso_account_id_seq"; grant select,update on sequence pisso_account_id_seq to lfgiapp; CREATE TABLE "pisso_account" ( "pisso_account_id" number(20) NOT NULL DEFAULT nextval('pisso_account_id_seq'::regclass), "sno" number(20) NOT NULL, "p10" varchar2(32) NOT NULL COLLATE "pg_catalog"."default", "p13" varchar2(100) COLLATE "pg_catalog"."default", "u_name" varchar2(32) COLLATE "pg_catalog"."default", "u_id" varchar2(32) COLLATE "pg_catalog"."default", "parent_group" varchar2(200) COLLATE "pg_catalog"."default", "child_group" varchar2(200) COLLATE "pg_catalog"."default", "branch_group" varchar2(200) COLLATE "pg_catalog"."default", "branch_group_code" varchar2(14) COLLATE "pg_catalog"."default", "begtime" number(11) NOT NULL, "endtime" number(11) NOT NULL, "branch" char(14) NOT NULL, CONSTRAINT "pisso_account_pkey" PRIMARY KEY ("pisso_account_id"), CONSTRAINT "pisso_account_p10_uni" UNIQUE ("p10") ); CREATE UNIQUE INDEX "pisso_account_uni_idx" ON "gi_dingtalk_resp"("sno"); COMMENT ON COLUMN "pisso_account"."pisso_account_id" IS '物理主键'; COMMENT ON COLUMN "pisso_account"."sno" IS '记录行号'; COMMENT ON COLUMN "pisso_account"."p10" IS 'P10账号'; COMMENT ON COLUMN "pisso_account"."p13" IS 'P13账号'; COMMENT ON COLUMN "pisso_account"."u_name" IS '员工姓名'; COMMENT ON COLUMN "pisso_account"."u_id" IS '身份证号'; COMMENT ON COLUMN "pisso_account"."parent_group" IS '总公司名称'; COMMENT ON COLUMN "pisso_account"."child_group" IS '分公司名称'; COMMENT ON COLUMN "pisso_account"."branch_group" IS '中支公司名称'; COMMENT ON COLUMN "pisso_account"."branch_group_code" IS '3级机构代码'; COMMENT ON COLUMN "pisso_account"."begtime" IS '开始日期'; COMMENT ON COLUMN "pisso_account"."endtime" IS '中止日期'; COMMENT ON COLUMN "pisso_account"."branch" IS '分公司代码'; COMMENT ON TABLE "pisso_account" IS 'P13及P10账号信息表'; 这个建表语句有问题吗?
05-30
这个建表语句中存在一些问题: 1. 数据类型:`varchar2` 是 Oracle 数据库特有的数据类型,而在 PostgreSQL 中应该使用 `varchar` 或 `text` 数据类型。 2. 主键:建表语句中的主键约束名 `pisso_account_pkey` 与索引名 `pisso_account_uni_idx` 重名,需要修改其中一个的名称。 3. 索引:建表语句中的索引 `pisso_account_uni_idx` 的表名应该是 `"pisso_account"` 而不是 `"gi_dingtalk_resp"`。 4. 注释:建表语句中的 `COMMENT ON` 语句需要修改,因为其中的表名和列名都是错误的。 以下是修改后的建表语句: ``` DROP TABLE IF EXISTS "pisso_account" CASCADE; DROP SEQUENCE IF EXISTS "pisso_account_id_seq" CASCADE; CREATE SEQUENCE "pisso_account_id_seq"; GRANT SELECT, UPDATE ON SEQUENCE "pisso_account_id_seq" TO lfgiapp; CREATE TABLE "pisso_account" ( "pisso_account_id" serial NOT NULL, "sno" bigint NOT NULL, "p10" varchar(32) NOT NULL, "p13" varchar(100), "u_name" varchar(32), "u_id" varchar(32), "parent_group" varchar(200), "child_group" varchar(200), "branch_group" varchar(200), "branch_group_code" varchar(14), "begtime" integer NOT NULL, "endtime" integer NOT NULL, "branch" char(14) NOT NULL, CONSTRAINT "pisso_account_pk" PRIMARY KEY ("pisso_account_id"), CONSTRAINT "pisso_account_p10_uni" UNIQUE ("p10") ); CREATE UNIQUE INDEX "pisso_account_uni_idx" ON "pisso_account"("sno"); COMMENT ON TABLE "pisso_account" IS 'P13及P10账号信息表'; COMMENT ON COLUMN "pisso_account"."pisso_account_id" IS '物理主键'; COMMENT ON COLUMN "pisso_account"."sno" IS '记录行号'; COMMENT ON COLUMN "pisso_account"."p10" IS 'P10账号'; COMMENT ON COLUMN "pisso_account"."p13" IS 'P13账号'; COMMENT ON COLUMN "pisso_account"."u_name" IS '员工姓名'; COMMENT ON COLUMN "pisso_account"."u_id" IS '身份证号'; COMMENT ON COLUMN "pisso_account"."parent_group" IS '总公司名称'; COMMENT ON COLUMN "pisso_account"."child_group" IS '分公司名称'; COMMENT ON COLUMN "pisso_account"."branch_group" IS '中支公司名称'; COMMENT ON COLUMN "pisso_account"."branch_group_code" IS '3级机构代码'; COMMENT ON COLUMN "pisso_account"."begtime" IS '开始日期'; COMMENT ON COLUMN "pisso_account"."endtime" IS '中止日期'; COMMENT ON COLUMN "pisso_account"."branch" IS '分公司代码'; ``` 注意:由于我不知道该表的具体需求和使用场景,以上修改仅仅是基于语法方面的改进,实际建表时需要根据具体需求进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值