News for hackers. Stuff that matters.
Re:Why Class? by btilly on Sunday November 24, 2013 @04:41PM (#6791259)
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.

Re:Why Class? by robrenaud on Sunday November 24, 2013 @08:57PM (#6792107)
Re:Why Class? by btilly on Sunday November 24, 2013 @10:54PM (#6792401)
Slip up, yes. You're right, I said the wrong one.

But what's important is not the label, but the principle. :-)

Re:Why Class? by troels on Monday November 25, 2013 @04:33AM (#6793217)
Ah yes. Closures are a poor man's object. Ref: http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
Re:Why Class? by SideburnsOfDoom on Monday November 25, 2013 @06:17AM (#6793473)
Re:Why Class? by troels on Monday November 25, 2013 @08:20AM (#6793874)
Yes. Read the linked mail (Or really just the last paragraph)
Re:Why Class? by nostrademons on Sunday November 24, 2013 @11:06PM (#6792424)
Singletons 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.
Re:Why Class? by lists on Monday November 25, 2013 @08:35AM (#6793937)
As someone self-teaching their way into software engineering, would you be able to suggest any resources aside from Code Complete for these principles?
Re:Why Class? by morkbot on Monday November 25, 2013 @10:39AM (#6794597)
Try "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.

Re:Why Class? by bct on Monday November 25, 2013 @10:29AM (#6794519)
blindhippo: You are hellbanned.