PR中得到的教训

总结

Mentor给我的PR comment真的是无价之宝,多看看,特别感谢我导师,认真细心严谨有耐心的一位程序媛,希望每次写代码前看看PR的东西,多感受一下自己的问题,尽量少一点PR的comment,快一点合并的速度,给别人少点麻烦,给自己多点效率,最重要的是,代码是程序员的脸面,所以多学多写写的好看写的精致才是真的。整理的1380PR是我问题最多的一次,第一次写前端,感谢我mentor,之后的pr希望问题逐渐减少。
每次提交pr前必须看这个PR找找自己问题

SCSS

必须用格式化工具

extra line 结尾

起名一定形象,className,id之类的,不仅是给你看,后来的人要立马能看懂,写干净耐看的代码

颜色用16进制或者rgba这样在不同浏览器上差异很小,不要用string指示

代码

被反复用的代码,或者一长串的变量请用一个变量代替来使用它,这叫做优美

const status=this.props.user.info.status;

写灵活,不因为当前所给的条件局限

举例:给一个数组,根据数组里的值+条件判断生成表格,不要硬写,动态生成
mentor评价

Try not to hard code line 53 ~ 76. Use map to generate the tr dynamically. This way if there’s any change in services we don’t need to change the code.

改动:
写了一个函数,用map遍历数组,写灵活了。其他情况也大同小异

不要在构造函数里用props赋值,因为你不能保证props的属性就位,赋值总是要首先确保value exists.(js)

don’t assign anything from props in construction.

感觉我mentor强调了很多次

  1. it is dangerous to assign state value from props in constructor!!! you can’t guarantee the fuelUserInfo is retrieved at this point. Even if we want to assign value from props, make sure the value exists first.
  2. we don’t need to create states for these two values. Prefer turning these two lines as two functions that call at the beginning of render()

这一段注释真的很多内容
1.赋值谨慎
2. 给一个值分配state,有必要吗?如果他只在一个函数内用,我觉得没必要。

注释尽可能少,简单,英文

还是减少冗余,比如A || B出现了很多次,那就直接给他写成一个变量

这也减少了不必要的计算

seems like A is always ‘or’ with B. Might want to have a const variable on top to determine the boolean only once.

容器组件vs UI组件 各有位置

Didn’t see this before. No need for mapDispatchToProps & connect to actions. This is done in Container Component and can be passed in as props to UI Component!
These two files are for presentational components. We should only set connection in container component.

中英双语的停顿,格式,优美

“users,please” => “users, please”

中英双语起名一疙瘩一起

提炼出重复的地方,比如中英双语

变量名尽可能的明显有指代性,多推敲,减少注释更容易让人看懂

the code is clear enough, no need the comment
起名注意:instead of adding comment, a better way is to define a good variable.
起名要反复推敲,要清晰一下子能看懂+看整篇代码的起名风格

变量放进他该放的地方

比如一个变量我在if里才用,这是他的范围。那我写在外面就是不美的

inside the if block as that’s the only place where the variable is used.

有的地方适当封装成函数,优美

之前我写一长串在一个函数,这样不优美,改良

xxx()
xxxx()
render(){
const a=this.xxx();
const b=this.xxxx();
......
}

一下子优美多了!!!相比我写的,就很糟粕

能局部绝不全局

比如state这个,我在用的时候明明他只在一个函数里用,我设置成state就是浪费,不优美
!!!这个千万注意

种种情况面面俱到

should not make any assumption about what a default info is like. Keep info as empty initially. Let’s remove this default info.

遗留地方添加//TODO

调用lodash的函数

不要老自己想着写,自己的代码和lodash封装的高效的代码,心里没点数吗?要好看优雅的代码

建立pr

标题+module/project

被说太多次了。。。

带图片,图文并茂显示完成度和遗留问题

前后端

检测数据有没有

might want to check the returned “desc” to see if it is “success” before dispathcing

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值