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

点击量:56545

原文

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

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

想来还是思考的太简单

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

观点1

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

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

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

观点2

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

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

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

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

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

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

观点3

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

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

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

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

观点4

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

观点5

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

总结下

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

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

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

  1. Greetings! I know this is kinda off topic however , I’d figured I’d ask.
    Would you be interested in exchanging links or maybe guest writing a blog article or vice-versa?
    My website covers a lot of the same topics as yours and I think we could greatly
    benefit from each other. If you’re interested feel free to shoot me an e-mail.
    I look forward to hearing from you! Superb blog by the way!

  2. I’ve been exploring for a little for any high-quality articles or blog posts on this
    kind of area . Exploring in Yahoo I finally stumbled upon this web site.

    Reading this info So i am glad to exhibit that I have an incredibly excellent uncanny feeling I found out exactly what I
    needed. I most for sure will make sure to don?t fail to remember
    this web site and give it a glance regularly.

  3. I think the admin of this site is really working hard in favor of
    his web page, for the reason that here every information is
    quality based material.

  4. I do not even understand how I ended up right here,
    however I assumed this submit used to be great. I do not know who you are but certainly you’re
    going to a well-known blogger in case you aren’t already.
    Cheers!

  5. It’s appropriate time to make some plans for the future and it is time to
    be happy. I have learn this put up and if I may I want to recommend you some fascinating
    things or advice. Maybe you could write next articles relating to
    this article. I wish to read more issues about it!

  6. Hello! This is kind of off topic but I need some guidance
    from an established blog. Is it hard to set up your own blog?
    I’m not very techincal but I can figure things out
    pretty quick. I’m thinking about creating my own but I’m not sure where to start.

    Do you have any ideas or suggestions? Cheers

  7. Do you have a spam problem on this website; I also am a blogger, and I was wanting to know
    your situation; many of us have developed some nice methods and we are looking to trade strategies with other folks, be sure to shoot me an e-mail if interested.

  8. hello!,I really like your writing so a lot! share we keep in touch
    extra about your post on AOL? I require a specialist
    in this area to resolve my problem. May be that is you! Having
    a look forward to look you.

  9. Have you ever thought about writing an e-book or guest
    authoring on other websites? I have a blog based upon on the same topics you
    discuss and would really like to have you share some stories/information.
    I know my audience would enjoy your work. If you are
    even remotely interested, feel free to shoot me an email.

  10. hello!,I love your writing very a lot! share we keep in touch extra approximately your article on AOL?
    I need a specialist in this house to unravel my problem. May
    be that is you! Looking ahead to see you.

  11. It’s really a great and helpful piece of information. I am satisfied that you just shared
    this useful info with us. Please keep us informed like this.

    Thank you for sharing.

  12. Ver Películas Online HD Gratis, Español latino, Subtitulado, Estrenos Online Gratis
    en Repelis y Series Online Gratis en Rexpelis el mejor sitio de peliculas.

  13. Ver Películas Online HD Gratis, Español latino, Subtitulado, Estrenos
    Online Gratis en Repelis y Series Online Gratis en Rexpelis el mejor sitio de peliculas.

  14. Hey, I think your site might be having browser compatibility issues.
    When I look at your blog 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, very good blog!

  15. What i don’t understood is actually how you are not actually much more neatly-liked than you might be right now.
    You’re very intelligent. You already know therefore significantly when it comes to this topic, made
    me individually believe it from so many varied angles.
    Its like women and men are not interested unless it’s one thing to do with Woman gaga!
    Your own stuffs great. All the time deal with it up!

  16. What’s up i am kavin, its my first occasion to commenting anywhere, when i
    read this paragraph i thought i could also make comment due to
    this sensible paragraph.

  17. Hi I am so glad I found your blog, I really found you by mistake, while I was looking on Yahoo for something else, Anyhow I am here now and would just like to say kudos for a marvelous post and a all round entertaining blog (I also love
    the theme/design), I don’t have time to read it all
    at the moment but I have book-marked it and also
    added your RSS feeds, so when I have time I
    will be back to read much more, Please do keep up the superb b.

  18. Obrigado por compartilhar um texto tão informativo !
    Eu enviei isto para um colega de trabalho que estava precisando
    dessa informação!! E ele ficou muito agradecido !! Então me permita
    agradecer… Obrigado por gastar algum tempo para discutir esse importante assunto
    aqui no seu web site . http://www.curtarolo.info/servizi/Menu/menu_redirect.aspx?url=http://thebondexchange.com/ActivityFeed/MyProfile/tabid/61/userId/32030/Default.aspx

发表评论

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

3 + 18 =