学习编写有组织和模块化的程序
我是一名计算机科学专业的学生,我刚刚开始为我的课程编写相对较大的程序(750 - 1500 行之间)。到目前为止,任何合理级别的模块化和面向对象的设计都是可能的。然而,现在我正在为我的作业编写更复杂的代码,我想学习编写更好的代码。
谁能向我指出一些资源的方向,以了解在设计程序架构时要寻找什么样的东西,以便您可以使其尽可能模块化?
I'm a computer science student, and I'm just starting to write relatively larger programs for my coursework (between 750 - 1500 lines). Up until now, it's been possible to get by with any reasonable level of modularization and object oriented design. However, now that I'm writing more complex code for my assignments I'd like to learn to write better code.
Can anyone point me in the direction of some resources for learning about what sort of things to look for when designing your program's architecture so that you can make it as modularized as possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有一件重要的事情可以使开发模块化应用程序甚至稍后将应用程序模块化变得更加容易,那就是 依赖注入。
它允许您的模块与其他所有模块分开工作,因为它接收执行其任务所需的任何数据,而无需了解有关应用程序本身的任何信息。
生成高质量的上下文中立 DI 代码可能需要一些经验,这就是为什么尽快开始思考和试验它很重要。
There is one important thing which will make it easier when developing modular apps, or even turning an app modular at a later point, which is Dependency Injection.
It allows your modules to work separately of everything else, as it receives whatever data it needs to perform its task, without needing to know anything about the application itself.
It may take some experience to produce good quality context-neutral DI code, which is why it's important to begin thinking about and experimenting with it as soon as possible.
在我过去两年读过的大约 20 本书中,Martin Fowler 的《重构》是对我帮助最大的关于面向对象、模式、测试驱动开发和通用软件工程的书。
特别是有关气味的部分可以帮助您了解在开发更复杂的代码时需要避免的内容。
refactoring by martin fowler is the book that has helped me most among the 20 or so books that I have read on oo, patterns, test driven development and general software engineering over the last two years.
particularly the section on smells can help you see what you need to avoid as you are developing more complex code.
阅读 Robert Matin 的简洁代码
Read Clean Code by Robert Matin
这个问题以前曾在这里被问过,答案通常是没有这样的书。原因是没有可以应用于该问题的“规则”——你必须继续经验。我的经验是,您应该编写具有清晰、单向依赖图的多个库,但除此之外,我不想承诺自己。
This question has been asked here before, and the answer has generally been there is no such book. The reason for this is that there are no "rules" that can be applied to the problem - you have to go on experience. My experience is that you should write multiple libraries with a clear, singly directed dependency graph, but beyond that I wouldn't like to commit myself.