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

点击量:56007

原文

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

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

想来还是思考的太简单

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

观点1

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

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

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

观点2

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

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

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

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

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

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

观点3

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

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

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

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

观点4

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

观点5

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

总结下

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

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

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

  1. Wow that was odd. I just wrote an really long comment but after I clicked submit my comment didn’t appear.
    Grrrr… well I’m not writing all that over again. Anyway,
    just wanted to say excellent blog!

  2. you’re in reality a good webmaster. The website loading speed is incredible.
    It seems that you’re doing any unique trick. Moreover, The contents are masterwork.

    you’ve done a magnificent job on this subject!

  3. I think this is among the most significant information for me.
    And i’m glad reading your article. But want to remark on some general things,
    The web site style is perfect, the articles is really great
    D. Good job, cheers

  4. hey there and thank you for your info – I have certainly picked up
    something new from right here. I did however expertise a few technical points using this web site, as I
    experienced to reload the website many times previous to I could
    get it to load properly. I had been wondering if your hosting is OK?
    Not that I’m complaining, but sluggish loading instances
    times will very frequently affect your placement in google and can damage your
    high-quality score if ads and marketing with Adwords. Anyway I’m adding this RSS to my
    email and can look out for much more of your respective exciting content.
    Ensure that you update this again very soon.

  5. I’m impressed, I have to admit. Seldom do I come across a blog that’s both educative and engaging,
    and without a doubt, you have hit the nail on the head.
    The problem is an issue that not enough men and women are speaking intelligently about.
    Now i’m very happy I found this in my search for something concerning this.

  6. You are so cool! I do not think I’ve truly read through
    anything like that before. So wonderful to discover
    another person with a few original thoughts on this subject matter.

    Really.. thank you for starting this up. This site is
    something that’s needed on the internet, someone with
    some originality!

  7. Thank you for the auspicious writeup. It in fact was
    a amusement account it. Look advanced to far added agreeable from you!
    By the way, how could we communicate?

  8. After exploring a number of the blog articles on your
    blog, I seriously like your technique of blogging. I saved it to my bookmark webpage list and will be checking back soon. Please check out my web site as well and tell me what you think.

  9. Howdy! This is kind of off topic but I need some guidance from
    an established blog. Is it very hard to set up your own blog?
    I’m not very techincal but I can figure things out pretty
    fast. I’m thinking about setting up my own but I’m not
    sure where to begin. Do you have any points or suggestions?
    Thanks

  10. My spouse and I absolutely love your blog and find nearly
    all of your post’s to be exactly what I’m looking for.
    Does one offer guest writers to write content available for you?
    I wouldn’t mind writing a post or elaborating on a number of the subjects you write about here.
    Again, awesome site!

  11. Magnificent goods from you, man. I’ve understand your stuff previous to and you
    are just extremely wonderful. I really like what you’ve acquired here,
    really like what you’re saying and the way in which you say it.
    You make it entertaining and you still care for to keep it wise.

    I can’t wait to read much more from you.
    This is actually a great site.

  12. Hi there would you mind stating which blog platform you’re using?
    I’m going to start my own blog soon but I’m having a hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking
    for something unique. P.S Apologies for
    being off-topic but I had to ask!

  13. Superb post but I was wanting to know if you
    could write a litte more on this subject? I’d be very grateful if you could elaborate
    a little bit more. Cheers!

  14. Hello, I think your site might be having browser compatibility issues.
    When I look at your website in Opera, it looks fine but when opening in Internet Explorer, it has some
    overlapping. I just wanted to give you a quick heads up!
    Other then that, excellent blog!

  15. Definitely imagine that which you said. Your favourite justification appeared to be on the internet the simplest factor to have in mind
    of. I say to you, I definitely get irked even as
    other people think about concerns that they just don’t recognize about.
    You managed to hit the nail upon the top and also defined
    out the whole thing with no need side-effects , people could take a
    signal. Will likely be again to get more. Thank you

  16. Its like you learn my thoughts! You seem to grasp so much approximately
    this, such as you wrote the guide in it or
    something. I think that you simply could do with a few
    % to power the message house a little bit, but instead of that, this is
    magnificent blog. A great read. I’ll definitely be back.

  17. I’m not sure exactly why but this site is loading very slow
    for me. Is anyone else having this problem or is it a problem on my end?

    I’ll check back later and see if the problem still exists.

  18. Hello, i think that i saw you visited my site so i came to
    go back the choose?.I am attempting to find things to improve my web site!I suppose its adequate to
    make use of a few of your ideas!!

  19. Pretty component to content. I simply stumbled upon your web site and in accession capital to assert that I get in fact loved account your weblog posts.
    Anyway I’ll be subscribing to your augment and even I success you get admission to persistently quickly.

  20. Hi, Neat post. There’s an issue with your site in web explorer, may check this?
    IE still is the marketplace leader and a good part of other folks will
    miss your excellent writing due to this problem.

  21. Hey there would you mind stating which blog platform you’re
    working with? I’m going to start my own blog
    in the near future but I’m having a hard time choosing between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most blogs
    and I’m looking for something completely unique.
    P.S Sorry for getting off-topic but I had to ask!

  22. Hi! This is kind of off topic but I need some help from an established blog.
    Is it tough to set up your own blog? I’m not very techincal but I can figure things out pretty quick.
    I’m thinking about setting up my own but I’m not sure where
    to start. Do you have any points or suggestions? With thanks

发表评论

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

16 − 10 =