是什么阻碍了代码的复用,问题是否应该只解决一次即可?

点击量:56547

原文

哪些是复用?这些居然都是

以前我没注意到中间件是,只觉得复用是狭隘的,复用就是复用自己的代码而已

想来还是思考的太简单

其实复用体现在很多地方,nuget上下一个包,mysql数据库,中间件,
将所有现成的东西集成到自己的项目中的操作,难道不都是复用吗?

观点1

主要的问题在于,如果一个问题你没有去在不同的环境下解决很多遍,

你很难分得清楚,哪个部分是通用的,哪个部分是跟你当前的环境紧密相关的。

所以问题不可能只被解决一次,我们追求的只能是每一次解决的时候花的代价要更少,长远来讲趋向于0。

观点2

因为复用并非无代价,而且代价往往还很高。

阻碍代码重用的最大原因,事实上来自项目自身:复用代码在绝大多数情况下,都不是一个项目的最终目的。

对任何项目来说,唯一绝对存在的目的,是在指定的时间内完成客户给出的需求

从工程上说,任何特性都不是无代价的。复用提供了解决一类问题的灵活性,而灵活性作为一种功能,
同样有代价——正如过多地使用虚函数有性能损失,而过多地使用 interface 则一定程度上降低代码可读性。

不要把自己的需求误以为是用户的需求,这仍然是一个工程问题

我为了所谓的复用,而造成写代码慢了,才是十恶不赦,以快取胜,方能成就大事,而不是磨磨唧唧

观点3

可复用的东西(小到函数,大到框架),一定是从诸多应用场景中抽取出来的,
换句话说,一定要先有场景,在场景达到一定数量一定复杂度之后才能抽象出来可复用的部分,也就是常说的重构

一开始就追求复用性没什么意义,浪费时间不说,更可能假象的场景根本就不存在,或者实际情况超过想象

做开发,成长的几个阶段必不可少
1. 不做设计(新手阶段,能实现就好)         这个阶段过了
2. 过度设计(了解的东西多了,总想追求完美)  这个阶段也稍微实践了一下
3. 简化设计(认知逐渐深入,学会取舍)       这个阶段也有尝试
4. 最优设计(熟练掌握,知道概念适配场景)    这个太难了,最字真的难

其中23两个状态可能会往复多次,最终达到找到一个平衡的位置

观点4

重用的代码,底层的好写,上层的难写。  (真滴对,真的太对了,这一条一下子让我认识到了我现在的困难时在上层的封装,但其实也没到上层吧)

观点5

1. 编写代码时,如果考虑今后的重用,工作量一般是只为当前情况考虑的三倍。
2. 考虑今后的重用」只能靠猜,一般都是错的。
3. 读代码比写代码难,所以那些「只为当前情况考虑的」代码很少在问题稍稍发生变化的时候被改写成更通用的代码。

总结下

最后依然糊涂,但是当我在反思自己写的代码时,还是怕随便动一个方法,而导致被引用的其他地方都报错

我已经实践了复用,并且复用了很多方法和类,但是到最后,我却不敢修改那些复用的方法了,即时是简单的过滤

是什么阻碍了代码的复用,问题是否应该只解决一次即可?》有4,478个想法

  1. Oh my goodness! Amazing article dude! Thank you so much, However I
    am encountering problems with your RSS. I don’t know why I
    am unable to join it. Is there anybody else having similar RSS problems?
    Anyone that knows the solution will you kindly respond?
    Thanks!!

  2. hey there and thank you for your info – I have definitely picked up something new from right here.

    I did however expertise some technical points using this website,
    since I experienced to reload the web site lots of times previous to I could get
    it to load properly. I had been wondering if
    your web hosting is OK? Not that I’m complaining, but sluggish loading instances times will sometimes affect
    your placement in google and could damage your high-quality score if advertising and marketing with Adwords.
    Anyway I’m adding this RSS to my email and could look out for
    a lot more of your respective interesting content. Ensure that you update this again very soon.

    1. Yoou actually make it appear really easy with your presentation but I inn finding
      this mtter to be really one thing that I think
      I would by no means understand. It sort oof feels too complicated
      and extremely wide for me. I’m taking a look ahead tto your
      subsequent put up, I will attemkpt to get the danhgle of it!

  3. An impressive share! I have just forwarded this onto a colleague who
    had been doing a little research on this. And he actually ordered me
    lunch because I stumbled upon it for him… lol.
    So let me reword this…. Thanks for the meal!! But yeah, thanks for spending the time to talk about this issue here on your web page.

    1. Howdy, I do thinhk your blog could possibly be having internet browser compatibility issues.
      When I look at your wweb site iin Safari, it looks ine however, when opening in Internet
      Explorer, it has some overlaqpping issues.

      I merely wanted tto provide you with a quick heads up!
      Other than that, great site!

  4. Good day! I know this is somewhat off topic but I was wondering
    which blog platform are you using for this website?
    I’m getting sick and tired of WordPress because I’ve had
    problems with hackers and I’m looking at alternatives for another platform.

    I would be fantastic if you could point me in the direction of a
    good platform.

  5. Please let me know if you’re looking for a author for your weblog.
    You have some really great articles and I feel I would be a good asset.
    If you ever want to take some of the load off, I’d absolutely love to write some material for your blog in exchange for a link back to mine.
    Please blast me an email if interested. Thanks!

  6. Yes, even with everything that listing down, in the end you ought to sit and compose a complete response, the same way you’d write any essay.
    The goal is always to find a approach to provide a complete response, all while focusing on as small
    a place of investigation as possible. If you say because over and over again, one and only thing your reader is
    going to be aware of is simply because – it will stifle your argument in fact it is on top of their email list of issues you should
    avoid inside your academic work.

  7. Hiya! I know this is kinda off topic nevertheless
    I’d figured I’d ask. Would you be interested in trading links or maybe guest writing a blog post
    or vice-versa? My website addresses a lot of the same topics as yours and I feel we could greatly benefit from each other.
    If you might be interested feel free to send me an e-mail.
    I look forward to hearing from you! Wonderful blog by the way!

  8. Hi, Neat post. There’s a problem together with your web site in internet explorer,
    may check this? IE nonetheless is the marketplace chief and a
    huge element of folks will miss your wonderful writing because of this problem.

  9. I was curious if you ever considered changing the structure
    of your blog? Its very well written; I love what youve got to say.

    But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1
    or two pictures. Maybe you could space it out better?

  10. Look no further for delicious tropical and French-influenced meals, the restaurant at Shawandha Lodge is
    exquisite. Day 1 – Arrive to Quito and spend your day easing into the high altitude conditions.
    The only problem with this was that it was not very practical as the range was rather short meaning people that opted into this were left
    disappointed.

    1. Hello, i think that i saw you visited my website so i came to
      “return the favor”.I am trying to find things to enhance my site!I suppose its ok too use some of your ideas!!

  11. Asking questions are truly pleasant thing if you are not understanding something entirely, however this piece of writing offers fastidious understanding even.

  12. Hey there excellent website! Does running a blog such as this take a great deal of work?
    I’ve virtually no expertise in coding but I was hoping to start my own blog soon.
    Anyhow, should you have any recommendations or techniques for
    new blog owners please share. I know this is off subject but
    I just had to ask. Thanks a lot!

  13. I’m amazed, I must say. Rarely do I encounter a blog that’s equally educative and amusing, and without a doubt,
    you’ve hit the nail on the head. The issue is an issue that too
    few people are speaking intelligently about.

    I’m very happy I came across this during my search for something concerning this.

  14. Do you mind if I quote a few of your articles
    as long as I provide credit and sources back to your webpage?
    My blog is in the very same niche as yours and my visitors would
    certainly benefit from a lot of the information you provide here.
    Please let me know if this alright with you.
    Thank you!

  15. Hello fantastic blog! Does running a blog similar to this take a lot
    of work? I’ve virtually no expertise in programming but I was
    hoping to start my own blog soon. Anyhow, if you have any ideas or tips for new blog owners please share.

    I understand this is off subject however I simply had to ask.
    Cheers!

    1. Oh my goodness! Awesome article dude! Many thanks, However
      I am experiencing issues with your RSS. I don’t know the reason why I can’t join it.

      Is there anyone else getting thhe same RSS issues?
      Anybody who knows the slution can you kindly respond?
      Thanks!!

发表评论

电子邮件地址不会被公开。

7 − 3 =