33 points · by nickb · 18y ago · 37 comments
http://en.wikipedia.org/wiki/Interpreter_pattern
From what I can tell, using this is a pretty clear sign you should be using a language with macros...
"the Singleton "pattern" encourages you to forget everything you know about OO design, since OO is hard, and procedural is easy."
Why, oh why, are we encouraging people to use OO 100% of the time, when it's admittedly harder than the alternatives? (I'm looking at you, Java.) Methinks the bandwagon continues to play on, even after two decades...
I had never heard anyone suggest anything like that before, I think some developers think OOP is "the way forward." I spent many months trying to force my mind to think in an OOP manner, now I don't even bother. Occasionally I find a place where it does work, but it's definitely not a magical bullet.
UI -> Domain Model -> Persistence
Most people know of the 2nd one. The 1st one is just as big an impedance mismatch!
Most of the ways of doing UIs are not OO. If UIs were OO in a given environment, then naive developers following the path of least resistance starting from the GUI "hello world" would naturally build an OO application.
Are there any environments like that? Is Rails one such environment?
Compare Norvig (1998): "Design Patterns in Dylan or Lisp: 16 of 23 patterns are either invisible or simpler". http://norvig.com/design-patterns/
What do you gain from making a game a singleton?
And actually, for my last little prototype (now that I think about it), I didn't make it a singleton, I just had a single public instance of it.
Question retracted.
(I've been making do with custom interactor classes that perform object sharing by using linked-list of class instances with a custom "mapper" and though it works great it's really hard to explain to anyone).
Also - any books you guys would recommend as an alternative to Design Patterns?
Ever learn MVC? Might be a good place to start.
So your question is "How do I write good controllers?"
It's kinda hard for me to give you specific advice without a model and a set of behaviors to traverse. I guess "do good things" and "don't do stupid things" is about it. Singletons are not evil, but, like, gotos, I'd try to avoid them if at all possible.
In my experience, once you've matured the model enough for it to be code, you're automatically thinking in terms that leads to good design. Singletons pop out when you start with a small piece of the problem and try to bludgeon whatever you've got into a solution. These problems arise when you start to design from the bottom-up and use functional paradigms instead of OO paradigms. Nothing wrong with that, but for good code you should really pick one or the other and stick with it.
I still haven't decided what that means about me as a programmer.
Of course, if you're using more succinct programming languages, it may be much faster and accurate to write a line or two of the actual code to show what you mean, rather than remembering all those names of the patterns.
This comment entitles the bearer to one (1) Hacker News Bonus Point.
Don't spend it all in once place.
AVL Trees are EVIL
...and that's all we had to learn about them. He had us implement red/black trees and splay trees instead. To this day, I have no idea how threaded AVL trees work. But if that's OK with Dan Weld, it's OK with me. "
Thank goodness it wasn't: "LISP is EVIL". Or replace lisp by anything useful and generally misunderstood.
the thing is, you can't just read a book about design patterns (any book, no matter how well written) and know when to apply them. You'll have to try it, make mistakes, learn from them, make mistakes in the opposite direction and so forth.
People should build some personal throwaway projects and cram in every design pattern they know. That should at least get them started on the learn/mistake cycle. At least it did so for me. Though in my last project I was totally abusing the factory pattern while all the while chanting "I shall not use patterns when they are not necessary" :blush:
One might say that only stupid speakers make simple grammatical errors. Or they might be beginners in a second language. I hope and expect to always be a beginner in something in my life, whether it's a new computer or human language, a new craft, or some other new way of thinking.
By the way, Peter Norvig says that in Dylan or Lisp, 16 of 23 patterns are either invisible or simpler.
That's from the "Design Patterns in Dylan or Lisp" slide from his Design Patterns presentation at: