10 Ways to Improve Your Code
Recorded at:
Sharing Presentation?
by
Erick Pimienta
Not sure I agree Singleton's are Global Variables.
by
Porter Woodward
What I mean is that a Singleton can represent a resource of which there is a single instance. Often a logger or file system object, or some I/O port of which there is a single, physical instance of it. A singleton is thus a valuable way to model a real-world behavior.
Saying singletons are bad because they have mixed responsibilities, and are not testable - is the same as saying objects are bad because of the same reasons. Essentially you're dealing with bad singletons - which are also _bad_ objects. When they end up being used as a big library of static utility functions - that's when they're bad. At that point you're not dealing with object oriented code anymore, you've gone over to procedural code.
Properly engineered, and object oriented singletons are fine. Poorly engineered, not object oriented static function libraries are not.
Interesting Placement
by
James Moline
"We invented our own web/persistence/messaging/caching framework because none of the existing ones was good enough"
is immediately followed by
"Question Authority - Some things should not be done just because that is the custom."
Seems a little incongruous.
Re: Not sure I agree Singleton's are Global Variables.
by
Dmitry Tsygankov
a logger or file system object, or some I/O port of which there is a single, physical instance of it.
But file system objects (and, therefore, loggers) are essentially the same old global variables! Global variables are in memory, files are on disk. Are there any other major differences? Both can be accessed by any thread if you have pointers to them (or filenames, or port numbers), locked in some way, concurrent access can lead to deadlocks, modularity can suffer whenever any of those things is used, one always has to access those resources in a certain order etc. An IO port is a global variable of type string, with one thread appending data to the end while another thread removes data from the beginning.
Of course, one has to do something in the end - write to a file or a database or something. But if you try to keep the core of the program clean of those things - you get a more maintainable program in the end. At least that's what I believe in. Some people don't...
Re: Not sure I agree Singleton's are Global Variables.
by
Pete Kirkham
If you hard wire the singleton as in the example, you get problems both in testing and when the singleton assumption is violated. If you create single instances of some types in your configuration, then you don't get these problems. You might say that YAGNI for two serial ports, but you do need it whenever you want to mock the object for tests, so even if there is one object in the domain of your first iteration, making it not a singleton gives an advantage.
Slide and Presentation Timing issue
by
Adam Zimmerman
I think there is a slide and timing issue at about minute 46. Anybody else seeing this? The slide changes to Swing + Ruby when dsl's are being talked about. Then the rest of the presentation is ~1 slide off.
Is this something that can be fixed?
Excellent
by
DSK Chakravarthy
Anyway, is there any possibility to download this presentation and play it offline with our dev folks!!
Apart of all.. thanks for the knowledge share
Like all of this except using reflection of private constructors
by
Declan Whelan
I think creating private constructors and using reflection to invoke them is a questionable practice. Constructors should be appropriately visible and reflection should not be used to bypass language visibility when you have other options. Using reflection makes the code more complex, harder to maintain and limits the effectiveness of refactoring tools. And it still does not guarantee the singleton behaviour because reflection can be used anywhere.
Best to avoid the reflection in this case and make the constructor appropriately visible.
Singleton can be useful if used correctly
by
Jean-Simon LaRochelle
Re: Not sure I agree Singleton's are Global Variables.
by
Manjunath Bhat
Re: Like all of this except using reflection of private constructors
by
Stephan Kennedy
I liked the presentation too, except the bit about using reflection to work around the private constructor.
I would create a public interface for the configuration class and hide the implementation class (which would have a public constructor) by making it visible only within its own package or even within the factory class.
Re: Not sure I agree Singleton's are Global Variables.
by
Kevin Wong
Specifically, I think he's referring to the pattern of a private constructor and a method/field to access the single instance. THAT "Singleton" is evil, indeed. That code using this pattern is horrible to test is solid evidence of excessive coupling, as well as a damning con in its own right.
Manage your object instances in a central place, e.g., DI container (Spring, Guice).
Very Good
by
Marcio Geovani Jasinski
Of course some topic are hard to talk in short time like singleton one...
I think Singleton becomes bad when it's misused and this happen with all languages, paradigms, etc... When someone learn a new language or a new pattern it's quite common start to use it every where and this is a bad programmer behaviour, doesn't mean the pattern/language is bad ;)
Re: Slide and Presentation Timing issue
by
jonty davis
Re: Sharing Presentation?
by
Prodis a.k.a. Fernando Hamasak...
The correct presentation can be downloaded in this link:
qconsf.com/sf2008/file?path=/qcon-sanfran-2008/...
10 Ways to Improve Your Code;Posted by Neal Ford on Apr 15, 2009 03:14 AM
by
Pradipta Dash





Hello stranger!
You need to Register an InfoQ account or Login to post comments. But there's so much more behind being registered.Get the most out of the InfoQ experience.
Tell us what you think