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

点击量:48834

原文

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

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

想来还是思考的太简单

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

观点1

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

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

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

观点2

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

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

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

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

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

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

观点3

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

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

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

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

观点4

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

观点5

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

总结下

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

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

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

  1. Good day I am so excited I found your webpage, I really found you by mistake,
    while I was researching on Aol for something else, Anyhow I am here now and
    would just like to say cheers for a tremendous post and a
    all round thrilling blog (I also love the theme/design),
    I don’t have time to read through 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 a lot more, Please do keep up the fantastic job.

  2. You are so awesome! I do not suppose I’ve read a single thing like this before.
    So wonderful to find another person with some unique thoughts on this
    topic. Seriously.. many thanks for starting this up. This site
    is one thing that is required on the internet, someone with a little originality!

  3. Do you mind if I quote a few of your posts as long as I provide credit and sources back to your webpage?
    My website is in the very same niche as yours and my visitors would
    truly benefit from some of the information you provide here.
    Please let me know if this okay with you. Regards!

  4. Greetings from Ohio! I’m bored at work so I decided to browse your
    blog on my iphone during lunch break. I really like the info you provide here
    and can’t wait to take a look when I get home. I’m amazed at how
    quick your blog loaded on my mobile .. I’m not even using WIFI, just 3G ..
    Anyhow, excellent site!

  5. Hmm it seems like your blog ate my first comment (it was extremely long) so I guess
    I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog.
    I too am an aspiring blog writer but I’m still
    new to everything. Do you have any points for novice blog writers?

    I’d really appreciate it.

  6. Greetings from Ohio! I’m bored to tears at work so I decided
    to check out your site on my iphone during lunch break.

    I love the knowledge you present here and can’t wait to take
    a look when I get home. I’m surprised at how
    fast your blog loaded on my phone .. I’m not even using WIFI, just 3G ..
    Anyhow, wonderful site!

  7. I’m extremely inspired together with your writing talents and also with the structure on your blog.
    Is that this a paid theme or did you customize it yourself?
    Either way keep up the excellent high quality writing, it’s uncommon to peer a nice
    blog like this one these days..

  8. Hi would you mind letting me know which hosting company you’re using?
    I’ve loaded your blog in 3 completely different browsers and I must say this blog loads a lot faster then most.
    Can you recommend a good internet hosting provider at a reasonable price?
    Cheers, I appreciate it!

  9. It’s a pity you don’t have a donate button! I’d without a
    doubt donate to this excellent blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will share this site with my Facebook group.

    Chat soon!

  10. I do not know whether it’s just me or if perhaps everyone else experiencing
    problems with your site. It seems like some of the
    text in your posts are running off the screen. Can somebody else please comment
    and let me know if this is happening to them as well?
    This might be a issue with my web browser because I’ve had this happen before.
    Appreciate it

  11. Hey just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Ie.
    I’m not sure if this is a format issue or something to do with web browser
    compatibility but I figured I’d post to let you know. The design look great though!
    Hope you get the problem resolved soon. Kudos

  12. With havin so much content do you ever run into any problems of plagorism or copyright violation? My blog has a lot of completely unique content I’ve
    either authored myself or outsourced but it seems a lot of it is popping
    it up all over the internet without my authorization. Do you know any solutions
    to help reduce content from being stolen? I’d
    truly appreciate it.

  13. I have to express my admiration for your kind-heartedness
    for men who have the need for guidance on in this concern. Your real dedication to
    getting the solution up and down ended up being certainly useful and have surely made somebody
    just like me to achieve their ambitions. Your insightful instruction denotes much
    to me and substantially more to my colleagues.

    Regards; from each one of us. https://www.silicon-wristband.com/?s=3/4 Inc

  14. A person essentially assist to make critically articles I would
    state. This is the very first time I frequented your website page and so far?
    I amazed with the analysis you made to create this actual put up extraordinary.

    Magnificent activity!

发表评论

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

2 × 2 =