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

点击量:48838

原文

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

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

想来还是思考的太简单

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

观点1

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

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

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

观点2

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

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

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

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

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

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

观点3

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

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

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

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

观点4

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

观点5

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

总结下

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

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

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

  1. Thanks on your marvelous posting! I seriously enjoyed reading it, you can be a great author.
    I will make certain to bookmark your blog and will come back at some point.

    I want to encourage you to continue your great writing, have a nice evening!

  2. I am really impressed with your writing skills and also with the layout on your blog.
    Is this a paid theme or did you customize it yourself?

    Anyway keep up the nice quality writing, it is rare to see a nice blog like this one nowadays.

  3. Hello there! This blog post could not be written much better!
    Looking through this article reminds me of my previous roommate!
    He always kept talking about this. I’ll send this post to him.

    Fairly certain he’ll have a good read. I appreciate
    you for sharing!

  4. Very nice post. I just stumbled upon your weblog and wanted to say that I’ve truly enjoyed surfing around your blog posts.
    After all I’ll be subscribing to your rss feed and I
    hope you write again soon!

  5. You’re so awesome! I do not suppose I have read a single thing like
    this before. So wonderful to find somebody with unique thoughts on this subject.
    Seriously.. many thanks for starting this up.
    This website is one thing that’s needed on the web, someone with a little originality!

  6. I’m amazed, I have to admit. Seldom do I encounter a blog that’s equally educative and interesting, and without a doubt,
    you’ve hit the nail on the head. The problem
    is something too few folks are speaking intelligently about.

    I am very happy I found this in my search for something relating to this.

  7. I loved as much as you’ll receive carried out right here.
    The sketch is tasteful, your authored subject
    matter stylish. nonetheless, you command get bought an shakiness over
    that you wish be delivering the following. unwell unquestionably
    come further formerly again as exactly the same nearly a lot often inside case you shield this hike.

  8. Wonderful beat ! I would like to apprentice even as
    you amend your site, how could i subscribe for a blog web site?
    The account helped me a applicable deal. I were a little bit
    familiar of this your broadcast provided vibrant transparent idea

  9. 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 love to have you share some stories/information.
    I know my subscribers would enjoy your work. If you’re even remotely interested, feel
    free to shoot me an e mail.

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

  11. When I initially commented I clicked the “Notify me when new comments are added”
    checkbox and now each time a comment is added I get several e-mails with
    the same comment. Is there any way you can remove me from that service?
    Thanks a lot!

  12. Hello are using WordPress for your blog platform?
    I’m new to the blog world but I’m trying to get started and create my own. Do you require any coding knowledge
    to make your own blog? Any help would be greatly appreciated!

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

  14. You’re so interesting! I don’t suppose I have read through
    something like that before. So wonderful to discover
    someone with genuine thoughts on this subject. Seriously..
    thank you for starting this up. This site
    is one thing that is needed on the web, someone with a
    little originality!

  15. Hello! I just wanted to ask if you ever have any trouble with hackers?
    My last blog (wordpress) was hacked and I ended up losing several weeks of
    hard work due to no data backup. Do you have any methods to prevent hackers?

  16. I am no longer certain where you’re getting your info,
    but great topic. I needs to spend a while studying more or understanding more.
    Thanks for fantastic information I was in search
    of this information for my mission.

  17. You actually make it appear really easy together
    with your presentation but I to find this matter to be really something that I believe I might by
    no means understand. It kind of feels too complex and extremely vast for me.
    I am having a look forward in your subsequent put up, I
    will attempt to get the grasp of it!

  18. Woah! I’m really digging the template/theme of this site.

    It’s simple, yet effective. A lot of times it’s
    tough to get that “perfect balance” between superb usability
    and appearance. I must say that you’ve done a very good
    job with this. Additionally, the blog loads super quick for me on Internet explorer.

    Outstanding Blog!

  19. Its like you read my mind! You seem to know so much about this, like
    you wrote the book in it or something. I think that you can do with a few pics to drive the message home a bit,
    but other than that, this is fantastic blog. A fantastic read.
    I’ll definitely be back.

  20. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four e-mails with the same comment.
    Is there any way you can remove me from that service? Cheers!

  21. Hello, Neat post. There’s a problem with your web site
    in web explorer, could test this? IE still is the marketplace
    chief and a good part of folks will miss your excellent writing
    because of this problem.

发表评论

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

4 − 2 =