InfoQ

InfoQ

Presentation

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Recorded at:
Recorded at

10 Ways to Improve Your Code

Presented by Neal Ford on Apr 15, 2009 Length 00:42:23
Sections
Development,
Architecture & Design
Topics
Java ,
Programming ,
.NET ,
Ruby
Tags
QCon ,
TDD ,
XP ,
QCon San Francisco 2008 ,
Best Practices
The next QCon is in London March 5-9, Join us!
 

How would you like to view the presentation?

In case you are having issues watching this video, please follow these simple steps to help us investigate the issue:
1. Right click on the video player and select Copy log
2. Paste the copied information in an email to video-issue@infoq.com (clicking this link will fill in the default details in most email clients).
Note: in case your email client hasn't automatically picked up the email subject, please include in your email the URL of the video too.
3. Done.
We will investigate the issue and get back to you as soon as possible. Thanks for helping us improve our site!
Summary
In this presentation recorded during QCon SF 2008, Neal Ford, an architect at ThoughtWorks, shows 10 ways to write better code. This is practical advice for developers, but application architects can benefit from it too.

Bio
Neal Ford is a senior application architect at ThoughtWorks. He is the author of the books Developing with Delphi: Object-Oriented Techniques, JBuilder 3 Unleashed, and Art of Java Web Development. He is also the editor and a contributor to No Fluff, Just Stuff Anthology : The 2006 Edition and No Fluff, Just Stuff Anthology Volume 2: The 2007 Edition.

About the conference
QCon is a conference that is organized by the community, for the community.The result is a high quality conference experience where a tremendous amount of attention and investment has gone into having the best content on the most important topics presented by the leaders in our community. QCon is designed with the technical depth and enterprise focus of interest to technical team leads, architects, and project managers.

19 comments

Watch Thread Reply

Excelent !! by Erick Pimienta Posted
Sharing Presentation? by Erick Pimienta Posted
Re: Sharing Presentation? by Erick Pimienta Posted
Re: Sharing Presentation? by Prodis a.k.a. Fernando Hamasak... Posted
Not sure I agree Singleton's are Global Variables. by Porter Woodward Posted
Re: Not sure I agree Singleton's are Global Variables. by Dmitry Tsygankov Posted
Re: Not sure I agree Singleton's are Global Variables. by Pete Kirkham Posted
Re: Not sure I agree Singleton's are Global Variables. by Manjunath Bhat Posted
Re: Not sure I agree Singleton's are Global Variables. by Kevin Wong Posted
Interesting Placement by James Moline Posted
Slide and Presentation Timing issue by Adam Zimmerman Posted
Re: Slide and Presentation Timing issue by jonty davis Posted
Excellent by DSK Chakravarthy Posted
Like all of this except using reflection of private constructors by Declan Whelan Posted
Re: Like all of this except using reflection of private constructors by Stephan Kennedy Posted
Singleton can be useful if used correctly by Jean-Simon LaRochelle Posted
Very Good by Marcio Geovani Jasinski Posted
10 Ways to Improve Your Code;Posted by Neal Ford on Apr 15, 2009 03:14 AM by Pradipta Dash Posted
Thanks by Kamal Mettananda Posted
  1. Back to top

    Excelent !!

    by Erick Pimienta

    Thanks Neal on sharing this 10 points and experience.

  2. Back to top

    Sharing Presentation?

    by Erick Pimienta

    Is this presentation available for sharing? If so where I can download.

  3. Back to top

    Re: Sharing Presentation?

    by Erick Pimienta

  4. Back to top

    Not sure I agree Singleton's are Global Variables.

    by Porter Woodward

    In practice - they are often used as such. In theory - they're not intended as such.

    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.

  5. Back to top

    Interesting Placement

    by James Moline

    I find it funny that #10 under Coporate Code Smells:

    "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.

  6. Back to top

    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...

  7. Back to top

    Re: Not sure I agree Singleton's are Global Variables.

    by Pete Kirkham

    The code example given was the classic singleton anti-pattern - a hardwired, globally accessible single object which cannot be changed. What you seem to be talking about are objects of which there happens to be only one instance in the application (move to a different machine, you get an extra serial port; converting code which assumes a singleton to code which doesn't is a waste of effort).

    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.

  8. Back to top

    Slide and Presentation Timing issue

    by Adam Zimmerman

    I like this presentation and found it confusing by the end with the timing of the slides and the content in the presentation.

    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?

  9. Back to top

    Excellent

    by DSK Chakravarthy

    That is a great work and keen observation from SmallTalk stories. Surprised and unbelievable that these so called modular coding is first identified during 70s and documented by SmallTalk authoers.

    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

  10. Back to top

    Like all of this except using reflection of private constructors

    by Declan Whelan

    Awesome presentation! I do have a quibble though.

    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.

  11. Back to top

    Singleton can be useful if used correctly

    by Jean-Simon LaRochelle

    This is certainly a pattern that can be misused. However, if you keep in mind the dangers of this pattern I think it can be used with good results. The best Singleton is stateless and of course read-only (the main problem of global variables is that they can be modified anywhere any-time so a read-only Singleton is not a store of global variables in the traditional sense). You can find good (constructive) critical analysis of the Singleton pattern on the Web.

  12. Back to top

    Re: Not sure I agree Singleton's are Global Variables.

    by Manjunath Bhat

    Porter, Couldnt agree more with you. You put it very nicely. Singletons should be put to right use, not "abused". That's when it gets messy.

  13. Back to top

    Re: Like all of this except using reflection of private constructors

    by Stephan Kennedy

    I agree with Declan.
    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.

  14. Back to top

    Re: Not sure I agree Singleton's are Global Variables.

    by Kevin Wong

    I think you're misinterpreting his point. He's not saying that there are not cases where there should only be one instance of an object (although if you're unit testing, there aren't), he's saying it's not the object's responsibility to manage its instances.

    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).

  15. Back to top

    Very Good

    by Marcio Geovani Jasinski

    Very nice presentation! Funny and goes smoothly.
    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 ;)

  16. Back to top

    Re: Slide and Presentation Timing issue

    by jonty davis

    Yeah I find this also at the same place, shame as it is such a great presentation, what a help!!

  17. Back to top

    Re: Sharing Presentation?

    by Prodis a.k.a. Fernando Hamasak...

    The link above is wrong.
    The correct presentation can be downloaded in this link:
    qconsf.com/sf2008/file?path=/qcon-sanfran-2008/...

  18. Back to top

    10 Ways to Improve Your Code;Posted by Neal Ford on Apr 15, 2009 03:14 AM

    by Pradipta Dash

    Excellent Presentation & Guide.

  19. Back to top

    Thanks

    by Kamal Mettananda

    Thanks a lot for this nice presentation.

    As most of the others, I also feel bad about the use of reflection on singleton.

Educational Content

Questions for an Enterprise Architect

Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?

Wrap Your SQL Head Around Riak MapReduce

Sean Cribbs explains what Map-Reduce and Riak are, why and how to use Map-Reduce with Riak, and how to convert SQL queries into their Map-Reduce equivalents.

Polyglot Persistence for Java Developers - Moving Out of the Relational Comfort Zone

Chris Richardson shows how he ported a relational database to three NoSQL data stores: Redis, Cassandra and MongoDB.

The Golden Circle – Why How What

Jean Tabaka challenges the audience to reflect on what Agile practices they are employing, how they are using them, ending with the questions “Why have their organization chosen to go Agile?

The Web Platform as a Limitless Pool of Innovation, with Andreas Gal

Andreas talks about the benefits of the Open Web and how it compares to proprietary stacks. He also talks about various projects that push the envelope like Boot to Gecko, Broadway and pdf.js.

Hadoop and NoSQLin a Big Data Environment

Ron Bodkin discusses early adoption of Hadoop, NoSQL and describes MapReduce and related libraries and Frameworks. Other topics include Hive, Pig, multi tenancy, and security in a big data environment

Spring and Platform Interoperability

Stephen Bohlen explains how Spring helps with interoperability between Java and .NET, demoing it with the help of a sample application.

How to Stop Writing Next Year's Unsustainable Piece of Code

Guilherme Silveira mentions some of the turning points in project development that may affect the quality of the code offering advice on avoiding writing crappy code.