职场人生(十一):代码不仅是用来运行的,更是用来看的

public static string StringTruncat(string oldStr, int maxLength, string endWith)
    {
        if (string.IsNullOrEmpty(oldStr))
            return oldStr + endWith;
        if (maxLength < 1)
            throw new Exception("返回的字符串长度必须大于[0] ");
        if (oldStr.Length > maxLength)
        {
            string strTmp = oldStr.Substring(0, maxLength);
            if (string.IsNullOrEmpty(endWith))
                return strTmp;
            else
                return strTmp + endWith;
        }
        return oldStr;
    }   
   
 ///   <summary>   
    ///   将指定字符串按指定长度进行剪切,   
    ///   </summary>   
    ///   <param   name= "oldStr "> 需要截断的字符串 </param>   
    ///   <param   name= "maxLength "> 字符串的最大长度 </param>   
    ///   <param   name= "endWith "> 超过长度的后缀 </param>   
    ///   <returns> 如果超过长度,返回截断后的新字符串加上后缀,否则,返回原字符串 </returns>   
    public static string StringTruncat(string oldStr, int maxLength, string endWith)
    {
        // 原字符串不能为空
        if (string.IsNullOrEmpty(oldStr))
            return oldStr + endWith;
        // 返回的字符串长度必须大于0
        if (maxLength < 1)
            throw new Exception("返回的字符串长度必须大于[0] ");
        // 处理截取
        if (oldStr.Length > maxLength)
        {
            // 截取
            string strTmp = oldStr.Substring(0, maxLength);
            // 加后缀
            if (string.IsNullOrEmpty(endWith))
                return strTmp;
            else
                return strTmp + endWith;
        }
        return oldStr;
    }   

通过两段相同代码容易得出:代码需要注释,这是必须的,不可推卸的责任。有了注释,才能让自己或者接手项目的人,快速的了解代码的功能,毕竟代码是指示机器的,而注释才是人和人间的沟通的标准。

 

即使是自己写的项目,过一个月,让你光看代码也费劲儿,因为代码需要一行一行的读完了,才有条件推断它的功能、逻辑。

 

程序员的跳槽太常见了,难免项目会让别人接手做维护,要是你的代码没有注释,用他的思维捋顺你的支离破碎的想法,他会把你的八辈祖宗都骂了。这不仅会耽误项目进度,浪费不必要的时间,也是道德的缺失。换位思考,你会怎样?

 

不为别人考虑,或者懒得为别人着想,心太窄,只会让自己的路越走越窄,最终无路可走,你只有辞职的份了。

 

站在人的角度,代码不是用来运行的,而是用来看的,用来更好的、高效的沟通,只有这样,你、我、企业、社会才能共同进步。



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值