3 ms·
There is a fundamental point here that really bears thinking about. Software design has as a fundamental problem being able to express yourself in a way that i
by btilly 13y ago
There is a fundamental point here that really bears thinking about.
Software design has as a fundamental problem being able to express yourself in a way that is clear and remains clear as things change. Basic principles of good software design, like reducing cohesion, remain good principles no matter what "paradigm" you think you're using. When you change paradigms, be aware that the basic principles remain the same no matter what label you give them. And since design is all about tradeoffs, if you are going to have to violate a principle, you might as well do it in the clearest and most straightforward way possible.
Let me give an example. A singleton is bad for all of the reasons that a global variable is bad. If you need one, I prefer to make it a global variable simply because that is honest about what design principle has been broken. (Unless I want to make it lazy - then it is easier to write with a singleton!)
So learn the principles. Figure out what they look like and are called in your paradigm. Get on with life and solve real problems.
Let me give a concrete example. I learned more about good OO design from the first edition of Code Complete than any other book that I ever read. Even though it was entirely about procedural programming. Because the principles that it discussed, from how to name functions to the value of abstract data types to information hiding, all apply directly to OO. And to functional programming. And to aspect oriented programming. They are truly universal. Learn the principles, they are more important than the labels.
- robrenaud 13y agoMostly agreed, except that cohesion is good, but coupling is bad. http://en.wikipedia.org/wiki/Cohesion_(computer_science) http://en.wikipedia.org/wiki/Cohesion_(computer_science) http://en.wikipedia.org/wiki/Coupling_(computer_science) http://en.wikipedia.org/wiki/Coupling_(computer_science)
- btilly 13y agoSlip up, yes. You're right, I said the wrong one. But what's important is not the label, but the principle. :-)
- deleted 13y ago[deleted]
- nostrademons 13y agoSingletons can be made thread-safe (with difficulty), and you can use complex lazy singletons in C++ code while complex globals gets you into trouble with module initialization order. So there're some very pragmatic reasons to use singletons over globals, even if the same drawbacks apply to both.
- troels 13y agoAh yes. Closures are a poor man's object. Ref: http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
- SideburnsOfDoom 13y agoAnd vice versa: http://stackoverflow.com/questions/2497801/closures-are-poor-mans-objects-and-vice-versa-what-does-this-mean http://stackoverflow.com/questions/2497801/closures-are-poor...
- troels 13y agoYes. Read the linked mail (Or really just the last paragraph)
- lists 13y agoAs someone self-teaching their way into software engineering, would you be able to suggest any resources aside from Code Complete for these principles?
- blindhippo 13y agoRead: The Pragmatic Programmer by Andrew Hunt & David Thomas Code Complete 2 by Steve McConnell Clean Code by James O. Coplien Test Driven Development by Kent Beck (save this for last) These books will teach you how to think and approach coding in a way that will make Object Oriented programming simpler to comprehend. I can't suggest a book that explains basic OOP principals, hopefully some other much smarter person here can. I learned basic OOP through practice and through my education/class - but to be honest the basics are dead simple. It's only when you start getting into the very abstract that OOP starts to get really complicated and that's where the above books will help you.
- bct 13y agoblindhippo: You are hellbanned.
- morkbot 13y agoTry "Clean Code" by Robert C. Martin. But also remember that there's no one proper way of doing these things, it's all heuristics, not laws written in stone.