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

点击量:48837

原文

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

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

想来还是思考的太简单

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

观点1

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

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

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

观点2

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

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

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

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

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

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

观点3

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

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

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

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

观点4

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

观点5

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

总结下

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

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

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

  1. I loved as much as you’ll receive carried out right here. The sketch is attractive, 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 hike.

  2. Very nice post. I simply stumbled upon your weblog and wanted
    to say that I have truly loved surfing around your blog posts.
    In any case I will be subscribing to your rss
    feed and I am hoping you write once more soon!

  3. I loved as much as you’ll receive carried out right here.
    The sketch is attractive, your authored subject matter stylish.

    nonetheless, you command get bought an nervousness over that you wish be delivering the following.

    unwell unquestionably come more formerly again as exactly the same nearly very often inside case you
    shield this hike.

  4. (iii) You are accountable to your work, so conserve a professional attitude when confronted with your customers.
    The goal is usually to find a strategy to supply a complete response,
    all while focusing on as small an area of investigation as possible.

    Remember that if you’re new at college you’ll only recover
    if you practice, so give your very best on each assignment as you may be giving you better academic ability as a copywriter with each one.

  5. Hello, i read your blog from time to time and i
    own a similar one and i was just wondering if you get a lot
    of spam feedback? If so how do you protect against it, any plugin or anything you
    can advise? I get so much lately it’s driving me mad so any help is very much appreciated.

  6. You actually make it appear really easy together
    with your presentation but I find this topic to be really one thing which I think I’d by no means understand.
    It seems too complex and very extensive for me.

    I’m taking a look forward in your subsequent submit, I will attempt to get the hang of it!

  7. Howdy very nice blog!! Guy .. Excellent .. Wonderful ..
    I’ll bookmark your web site and take the feeds also?
    I am glad to find a lot of helpful information here within the
    post, we need develop extra techniques on this regard, thank
    you for sharing. . . . . .

  8. After looking into a number of the articles on your
    site, I really like your way of writing a blog.
    I saved it to my bookmark website list and will be
    checking back in the near future. Take a look at my website as well and tell me your opinion.

  9. Greetings, I do believe your website may be having web browser compatibility
    issues. Whenever I look at your site in Safari, it looks fine however when opening in IE, it has some overlapping issues.
    I simply wanted to provide you with a quick heads up!
    Besides that, fantastic blog!

  10. Howdy! This post couldn’t be written much better!

    Looking through this article reminds me of my previous
    roommate! He continually kept preaching about this.
    I most certainly will forward this post to him. Pretty sure he’ll
    have a good read. Thanks for sharing!

  11. I do agree with all of the concepts you’ve introduced on your post.
    They are very convincing and will definitely work. Still,
    the posts are very brief for beginners. May just you please
    prolong them a little from subsequent time? Thank
    you for the post.
    https://www.google.pl/maps/place/Poltax+Biuro+rachunkowe+,+Ksi%C4%99gowo%C5%9B%C4%87+Toru%C5%84+Bydgoszcz+W%C5%82oc%C5%82awek+Inowroc%C5%82aw/@53.0850184,18.4815718,11z/data=!4m5!1m2!2m1!1sBiuro+rachunkowe!3m1!1s0x470335322c414565:0xf9401a30e2fb89a2

  12. I’m really enjoying the design and layout of your site.
    It’s a very easy on the eyes which makes it much more pleasant for me to come here and
    visit more often. Did you hire out a designer to create your
    theme? Superb work!

  13. There’s been a lot of changes since I last left a comment about
    my site. I’m starting to add the new features that I’ve wanted to.

    I hope in the next few weeks that all of it will be up and running.

    It’s going to take time and I haven’t had much of it to dedicate to this project.
    I thank you all for visiting my site and I hope you have a great weekend!

发表评论

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

2 × 1 =