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

点击量:48834

原文

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

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

想来还是思考的太简单

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

观点1

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

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

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

观点2

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

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

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

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

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

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

观点3

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

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

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

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

观点4

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

观点5

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

总结下

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

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

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

  1. I do agree with all the ideas you have introduced
    in your post. They’re really convincing and can certainly work.

    Still, the posts are very quick for beginners.
    May just you please prolong them a little from next time?
    Thank you for the post.

  2. It is perfect time to make a few plans for
    the long run and it is time to be happy. I have learn this put up
    and if I may I desire to counsel you some attention-grabbing things or suggestions.

    Maybe you could write next articles relating to this article.

    I want to read even more things about it!

  3. I do not even know the way I ended up right here, however I thought this submit was
    once good. I don’t know who you are however definitely you’re going to a famous blogger if
    you happen to aren’t already. Cheers!

  4. We’re a group of volunteers and starting a new scheme in our community.
    Your web site offered us with valuable information to work on. You’ve done an impressive job and our whole
    community will be thankful to you.

  5. When I initially commented I appear to have clicked on the -Notify me when new comments
    are added- checkbox and from now on each time a comment is added I get
    4 emails with the exact same comment. Perhaps there is an easy method you can remove me from that service?
    Thanks a lot!

  6. Wonderful blog! I found it while surfing around on Yahoo News.
    Do you have any tips on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!

    Thank you

  7. Hey there! This is my 1st comment here so I just wanted
    to give a quick shout out and say I genuinely enjoy reading
    through your articles. Can you suggest any other blogs/websites/forums that deal
    with the same topics? Many thanks!

  8. Pretty! This has been an incredibly wonderful article 是什么阻碍了代码的复用,问题是否应该只解决一次即可?
    | heke . Thanks for providing this info 是什么阻碍了代码的复用,问题是否应该只解决一次即可?
    | heke .

  9. First of all I would like to say superb blog!
    I had a quick question that I’d like to ask if you don’t mind.

    I was curious to know how you center yourself and clear your head prior
    to writing. I’ve had a difficult time clearing my mind in getting my ideas out there.
    I truly do enjoy writing but it just seems like the first 10
    to 15 minutes are usually lost simply just trying to figure out how to begin. Any suggestions or hints?
    Appreciate it!

  10. Today, I went to the beach with my kids. 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
    put 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 totally off topic but I had to tell someone!

  11. Attractive section of content. I just stumbled upon your site and in accession capital to assert that I
    get in fact enjoyed account your blog posts. Any way I’ll be subscribing to your
    augment and even I achievement you access consistently quickly.

  12. Oh my goodness! Amazing article dude! Thanks, However I am having difficulties with your RSS.
    I don’t know why I cannot subscribe to it. Is there anyone else having the
    same RSS problems? Anyone who knows the solution can you kindly respond?
    Thanks!!

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

  14. The spirit of VIAGRA is reduced in men with other medicines
    and others with erectile bluish tinge. Open and direct car insurance generic viagra capresso.
    Viagra loopy loaf fletcher writes sildenafil online lowest.

  15. Heya are using WordPress for your site platform?

    I’m new to the blog world but I’m trying to get started and set up
    my own. Do you need any html coding knowledge to make your own blog?

    Any help would be really appreciated!

  16. Hi, i feel that i saw you visited my website thus i came to return the want?.I am
    trying to to find issues to enhance my website!I suppose its
    ok to make use of some of your ideas!!

  17. Hi would you mind letting me know which webhost you’re
    working with? I’ve loaded your blog in 3 completely different browsers
    and I must say this blog loads a lot quicker then most.
    Can you recommend a good hosting provider at a honest price?
    Cheers, I appreciate it!

  18. An multifocal bomb to the Water and Placenta In FDA exited 18-6 last.
    Irs tax settlement viagra generic friend sayings. The five other ideas approachable in the patient
    were as boots:Overcoming these activities is combined to
    dining room member.

  19. Hi! I understand this is somewhat off-topic but I had to ask.
    Does running a well-established blog like yours require
    a lot of work? I’m completely new to blogging however I do write in my
    journal everyday. I’d like to start a blog so I will be able to share my experience and thoughts online.
    Please let me know if you have any recommendations or
    tips for new aspiring blog owners. Thankyou! http://chilp.it/322644a

发表评论

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

7 − 2 =