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

原文

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

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

想来还是思考的太简单

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

观点1

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

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

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

观点2

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

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

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

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

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

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

观点3

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

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

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

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

观点4

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

观点5

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

总结下

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

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

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

  1. Fantastic beat ! I would like to apprentice while you amend your website, how
    could i subscribe for a blog website? The account aided me a acceptable deal.
    I had been tiny bit acquainted of this your broadcast provided bright clear concept

  2. My husband and i felt absolutely lucky when Jordan managed to complete his reports from the
    ideas he received while using the web page.
    It is now and again perplexing to just continually be giving freely information and facts other folks may have been selling.
    We really fully grasp we’ve got the website owner to thank for this.
    The specific illustrations you’ve made, the straightforward blog menu,
    the relationships you can give support to foster – it’s got many amazing,
    and it is making our son and us do think the theme is awesome, which
    is certainly rather pressing. Thanks for everything!

  3. I’m amazed, I have to admit. Seldom do I
    encounter a blog that’s both equally educative and entertaining,
    and without a doubt, you’ve hit the nail on the head.
    The problem is an issue that too few folks are speaking intelligently
    about. I am very happy that I found this during my hunt for
    something regarding this.

  4. Hello there, I believe your blog may be having internet browser
    compatibility problems. When I take a look at your site in Safari, it looks fine however, when opening in IE,
    it has some overlapping issues. I just wanted
    to provide you with a quick heads up! Aside from that, fantastic blog!

  5. Howdy! This post could not be written any better! Reading this post
    reminds me of my good old room mate! He always kept chatting about
    this. I will forward this write-up to him. Fairly certain he will
    have a good read. Thanks for sharing!

  6. Hello! This post could not be written any better! Reading this post reminds me of my old room mate!
    He always kept chatting about this. I will forward this article
    to him. Pretty sure he will have a good read. Thanks for sharing!

  7. Do you mind if I quote a couple of your articles as
    long as I provide credit and sources back to your blog? My website is in the very same area of interest 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.
    Thanks a lot!

  8. If you’ve difficulty in opening or turning the dispenser the wrong way up, the web page now offers a tipper which will help
    disperse the medication to suit your needs in your hand or perhaps a small cup.
    At least consume less meat and dramatically increase your usage of fruits,
    vegetables, and whole grains. Actually, some individuals utilize this property of
    vitamin C to assist relieve their constipation, but
    additionally to vitamin C, this usually needs a
    high-fiber diet and adequate fluid intake.

  9. Howdy! This post could not be written any better! Reading this post reminds me of my
    good old room mate! He always kept chatting about this.
    I will forward this page to him. Fairly certain he will have
    a good read. Thanks for sharing!

  10. Thank you for every other excellent article.
    Where else could anyone get that type of info in such a perfect approach of writing?
    I have a presentation subsequent week, and I’m on the look
    for such information.

  11. Hello! I know this is kinda off topic but I’d figured I’d ask.

    Would you be interested in trading links or maybe guest authoring
    a blog article or vice-versa? My site goes over a lot of the same subjects
    as yours and I think we could greatly benefit from each other.
    If you happen to be interested feel free to send me an e-mail.

    I look forward to hearing from you! Excellent blog by the way!

  12. Do you mind if I quote a couple of your articles as long as
    I provide credit and sources back to your webpage?
    My blog site is in the exact same area of interest as yours and my
    users would certainly benefit from some of the information you provide here.
    Please let me know if this okay with you. Thanks!

  13. Those who consumed lemons, limes, oranges, tomatoes, or
    green peppers failed to show warning signs of scurvy which linked their for the miracle of the vitamin.
    Now, these should not a replacement for a proper balanced diet but to
    ensure you are becoming all your vitamins and minerals.
    Vitamin AWhen looking at cellulite, vitamin A is often a
    friend from the skin.

  14. I have been exploring for a little for any high-quality articles or blog posts on this kind of house .
    Exploring in Yahoo I ultimately stumbled upon this website.

    Studying this information So i’m glad to convey that I’ve an incredibly just
    right uncanny feeling I found out just what I needed.
    I such a lot surely will make sure to don?t overlook this
    website and provides it a glance regularly.

  15. I absolutely love your blog.. Excellent colors & theme.
    Did you make this website yourself? Please reply back as I’m
    wanting to create my own personal blog and would like
    to find out where you got this from or just what the theme is called.
    Thank you!

  16. 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 users would really benefit from a lot of the information you provide
    here. Please let me know if this ok with you. Cheers!

  17. Good day I am so glad I found your website, I really found you by error, while I was looking on Yahoo
    for something else, Nonetheless I am here now and would just like to say kudos for a incredible post and a all round enjoyable blog (I also love the
    theme/design), I don’t have time to read through it all at the moment but I have saved
    it and also added in your RSS feeds, so when I have time I will be
    back to read a lot more, Please do keep up the excellent work.

  18. Thank you, I’ve recently been searching for information about this topic
    for a long time and yours is the best I’ve discovered till now.

    However, what about the bottom line? Are you certain concerning the source?

  19. I have to thank you for the efforts you’ve put in writing this site.

    I am hoping to see the same high-grade blog posts from you
    in the future as well. In truth, your creative writing
    abilities has motivated me to get my own, personal website now
    😉

  20. Thanks for one’s marvelous posting! I seriously enjoyed reading it, you can be a great author.
    I will always bookmark your blog and will eventually come back down the road.
    I want to encourage continue your great job,
    have a nice holiday weekend!

发表评论

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

14 + 14 =