代码重构
做为一个半吊子程序员,一直以来我写程序的第一原则都是先让其跑起来。所以在做一个新软件或者实现一个新功能的时候,为了实现功能,我往往无所不用其极,什么硬编码啊、各种全局变量啊,甚至传说中的GOTO语句,只要能迅速地实现功能,我才不管什么高内聚、低耦合啥的乱七八糟的原则呢。
为什么总是急于让程序或功能模块跑起来呢?我想大致是我不是很自信,有些东西,我不确定以我的能力能否实现,或者说以我所掌握的技术而言,是否具有可实现性。万一我规划了一个不可能的任务,然后按部就班的去规划去实现,最终发现有个无法逾越的高山,那样就悲催了,毕竟时间还是很珍贵的嘛。
(图源:pixabay)
当我看到代码运行起来,我的心里就会无比的踏实。比如说我做的PC收发短信的软件,我看到短信发出去了,或者通过命令行,我可以读出来短信了,这时候我就会确定,我的思路和方向至少是没有错误的,凭我的水平慢慢雕琢是可以实现的。这时候我都会考虑重构一下代码,这样便于自己维护(排除BUG以及添加新功能等)以及为了自己以后阅读(很多时候,自己写的代码过一段时间就看不懂了)
我重构最复杂的一款软件是前公司一款科学计算软件,这个软件因为一些授权的关系有两个版本:V1和V2。我解决V2版本存在的一些BUG,以及做一些优化等等。接手以后,我发现V1和V2版本的代码是混在一起的,通过无处不在的宏定义在编译时编译成两个版本。里边好多变量、类以及函数被V1和V2公用,但是因为V1和V2实现上的差异,一些V1上的函数用在V2上就会导致问题。
我和相关负责人沟通,打算对这款软件进行重构,当然第一步就是把V2版本拆分出来。这个公司是个化工公司,负责人是搞化工出身的,他们认为既然这个软件能跑只是有一些BUG,导致几百个测试用例中有数十个测试用例没法跑或者得出的结果不对,那么我们就针对这些用例逐一解决即可,去动软件的框架风险太大,而且浪费时间。
按他们的思路,我工作了一段时间,发现把自己搞得很累,有时候此处改了就会导致彼处出问题,调试的时候也极其麻烦,有时候调着V2,却发现程序跳进V1的库函数中去,总之身心俱疲。后来在没有人表示支持的情况下,我用了大概三天多,几乎不眠不休,将V2版本独立出来。
原本整套软件C++代码30多万行,我拆出来之后V2只有10万行。拆分之后,再去跑几百个测试用例,好多之前无法通过的用例,一下子都正常了。其它出问题的用例,我也可以很轻松的定位出出问题的地方,解决起来事半功倍。
这些都是很久以前的事啦,之所以又聊到代码重构,是发现我的微信公众号程序越来越复杂啦。然后因为代码太长太滥,导致我添加或者修改一些功能的时候,经常导致出错,比如说少写个括号,少写个;之类的。代码逻辑看起来也比较乱,着实愁人。
于是今天着手重新规划了一下代码,将底层、功能模块、接口等都独立出来,现在看起来好多了,维护起来也很方便。比如我添加一个音乐的功能,只需要短短几段代码就可以实现了,对原来的程序和逻辑不会造成任何影响。
另外公众号添加了关注欢迎语,以及帮助提示等等。
推荐好歌
顺便给大家推荐一首好听的歌
公众号中回复music,就可以看到了
其实说了这么多,主要就是为了继续推广一下公众号啦,我是不是很机智 😀
至于代码重构啥的,我真的讲不出来啥,让一个半吊子程序员讲这个,有点难度,哈哈。
公众号添加方法
方式一:
进入微信通讯录->点击公众号->点右上角加号->搜索steemit,关注即可。方式二:
直接扫描以下二维码:
欢迎大家多提宝贵意见啊。
好牛。O哥威武!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I can't read Chinese but I translated the post online and saw that it was something about programming and code.
I just popped in to say that the image in the thumbnail is awesome - just pulled me in like magic! I thought of putting down my appreciation here. :-)
Good luck and happy Steeming!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
好帖好大分享
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Don't fall...
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
i wish you could post in English and teach us coding man
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @oflyhigh, this post is the second most rewarded post (based on pending payouts) in the last 12 hours written by a Hero account holder (accounts that hold between 10 and 100 Mega Vests). The total number of posts by Hero account holders during this period was 205 and the total pending payments to posts in this category was $3402.47. To see the full list of highest paid posts across all accounts categories, click here.
If you do not wish to receive these messages in future, please reply stop to this comment.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @oflyhigh! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes received
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
no english? how will I understand this?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
great post...thanks for sharing..upvoted
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我也是求快型,但現在看到以前寫的東西,都覺得『天啊這亂七八糟的代碼是我寫的嗎』不管重構多痛苦,還是改不了求快的心態哈哈。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice post
Please upvote my post too
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
已經算是強大的程序員了 !!!!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
cool
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
great post
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
每天推薦的好歌也不同的?😎
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
每周一歌哦
另外我计划改成年度好歌,这样我一年更新一次就可以了:)
其实我原本打算多上传一些歌曲,然后随机推荐
但是我发现微信这个音乐消息其实不是很方便,还要点进去才能播放,一点也不友好
于是就懒得弄了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
年度好歌這個虧你想得出來 ;) 真懶惰 😎
剛剛聽了好歌推薦,不錯的~
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
功能越來越多!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
订阅号功能还是有很多限制的
回头看看有精力的话弄成服务号,有些功能实现起来就方便多了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
有定期美女照發送服務就好了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
哈哈,这个可以有
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
这段时间好羡慕程序员。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
懂了,程序猿的世界充满了痛苦和成就感。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
赞,代码重构都上steemit了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Op!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
looks bavarian ... blue white blue white :-)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @oflyhigh!
Your post was mentioned in the hit parade in the following category:
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
O大就是牛!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thanks great contents 👍🏻
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
神一样的感觉,我什么时候能达到o哥的十分之一呢?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
过奖了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
o哥我不是恭维你,你就是我的梦想呀。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit