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

点击量:48836

原文

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

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

想来还是思考的太简单

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

观点1

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

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

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

观点2

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

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

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

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

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

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

观点3

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

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

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

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

观点4

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

观点5

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

总结下

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

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

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

  1. I’m extremely impressed with your writing skills as well as with the
    layout on your weblog. Is this a paid theme or did you customize
    it yourself? Anyway keep up the nice quality writing, it’s
    rare to see a nice blog like this one these days.

  2. Its like you read my thoughts! You seem to understand a lot about this, such as you wrote the e-book in it or something.
    I believe that you simply can do with a few % to force the message
    house a bit, however instead of that, this is great blog.
    A fantastic read. I will definitely be back.

  3. Admiring the dedication you put into your site and in depth information you
    provide. It’s nice to come across a blog every once
    in a while that isn’t the same outdated rehashed information. Great read!
    I’ve saved your site and I’m including your RSS
    feeds to my Google account.

  4. People who are addicted to pornography shut themselves far from the surface world.
    When these were finished, the men were motivated to produce a seminal sample.
    Donors need to be needed to report medical issues because they appear or perhaps held personally responsible and liable, anonymous or not.

  5. I really like your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it
    for you? Plz answer back as I’m looking to create my own blog and
    would like to find out where u got this from.

    kudos

  6. This is the perfect website for anyone who really wants to find
    out about this topic. You realize so much its almost tough to argue
    with you (not that I actually will need to…HaHa). You definitely put a fresh spin on a topic which has been written about for ages.
    Wonderful stuff, just excellent!

  7. Hmm it looks like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and
    say, I’m thoroughly enjoying your blog. I too am an aspiring blog blogger
    but I’m still new to the whole thing. Do you have any helpful hints for novice
    blog writers? I’d really appreciate it.

  8. but [cue for newness] bravery, constancy, and resolution [reverse of submission].
    Cross out any irrelevant ones and earn your best to set them in a logical order.
    To ensure that they will will understand the message that you’re hoping to get across, write employing their language and write while considering their degree of comprehension.

  9. Please let me know if you’re looking for a author for
    your site. You have some really great posts and I think I would be a good
    asset. If you ever want to take some of the load off,
    I’d absolutely love to write some content for your
    blog in exchange for a link back to mine. Please blast me an e-mail
    if interested. Thanks!

  10. So should you be expecting a great deal of help, be aware that this
    may not be forthcoming. The goal is usually to find a method to give a complete response,
    all while focusing on as small a location of investigation as possible.
    However, you may also be wondering where you can find good essay writing examples.

  11. Undeniably believe that which you said. Your favorite justification appeared to be on the internet the easiest thing to be aware of.

    I say to you, I definitely get irked while people consider worries
    that they plainly do not know about. You managed to hit the nail upon the top as well as defined
    out the whole thing without having side effect , people can take a signal.
    Will probably be back to get more. Thanks

  12. Very great post. I simply stumbled upon your
    blog and wanted to mention that I’ve really loved browsing your weblog posts.
    After all I’ll be subscribing in your feed and I’m hoping you write once more very soon!

  13. I loved as much as you will receive carried out right here.

    The sketch is tasteful, your authored subject matter stylish.
    nonetheless, you command get bought an edginess over that
    you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same
    nearly very often inside case you shield this increase.

  14. Have you ever thought about publishing an ebook or guest authoring on other websites?
    I have a blog based on the same information you discuss and would really like to
    have you share some stories/information. I know my audience would appreciate your work.
    If you are even remotely interested, feel free
    to send me an e-mail.

  15. Fantastic goods from you, man. I have understand your stuff previous to and you’re
    just extremely magnificent. I really like what you’ve acquired here, certainly like what
    you are saying and the way in which you say it. You make it
    entertaining and you still take care of to keep it wise.
    I can’t wait to read much more from you. This is actually
    a wonderful site.

  16. I was curious if you ever thought of changing the structure
    of your site? 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?

  17. Wow, wonderful weblog format! How long have you ever been running a blog for?
    you made blogging look easy. The whole glance of your site is excellent, let alone the content
    material!

  18. Hi would you mind sharing which blog platform you’re
    working with? I’m going to start my own blog soon but I’m
    having a hard time selecting 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 Apologies for being off-topic but I had
    to ask!

  19. Hi there I am so happy I found your webpage, I really found you by error,
    while I was browsing on Yahoo for something else, Anyways I am
    here now and would just like to say many thanks for a remarkable post and a all round enjoyable blog (I also love the
    theme/design), I don’t have time to read it all at the
    minute but I have bookmarked it and also included your RSS feeds, so when I have
    time I will be back to read more, Please do keep up the superb work.

  20. Hey I know this is off topic but I was wondering if you knew of any widgets
    I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time
    and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and I
    look forward to your new updates.

  21. I was curious if you ever considered changing the layout 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 2 pictures.
    Maybe you could space it out better?

  22. Have you ever thought about publishing an ebook or guest authoring on other websites?

    I have a blog centered on the same subjects you discuss and would love
    to have you share some stories/information. I know my audience would appreciate
    your work. If you’re even remotely interested, feel
    free to send me an e-mail.

  23. Hey! I know this is kind of off topic but I was wondering if you knew where I
    could find a captcha plugin for my comment form? I’m using the same blog platform
    as yours and I’m having problems finding one?
    Thanks a lot!

  24. Hello there! I could have sworn I’ve visited your blog before but after going through some of the articles I realized
    it’s new to me. Anyways, I’m certainly pleased I found it and I’ll
    be bookmarking it and checking back frequently!

  25. Today, I went to the beachfront with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell
    to her ear and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is completely off topic but I
    had to tell someone!

  26. Hey there terrific website! Does running a blog similar to this take a lot of work?

    I’ve absolutely no expertise in codibg but I was hoping to start my own blog soon. Anyhow, if you have any ideas oor techniques for new blog owners please share.
    I understand thnis is off topic however I just needed to ask.
    Appreciate it!

发表评论

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

2 × 4 =