The Clean Code Talks – Don’t Look For Things!

The Clean Code Talks - Don't Look For Things!

Google Tech Talks November 6, 2008 ABSTRACT Clean Code Talk Series Topic: Don’t Look For Things! Speaker: Misko Hevery
Video Rating: 4 / 5

This entry was posted in Google Code Search and tagged , , , , , . Bookmark the permalink.

20 Responses to The Clean Code Talks – Don’t Look For Things!

  1. Andrew James says:

    i came across an alien alphabet see if you can read it. at symbols n codes.

  2. BumblesTheUnicorn says:

    Yeah, I’m not sure why he didn’t just suggesting overloading the constructor so that one takes an Engine directly and the other builds one from a factory. Then you can easily instantiate it in the test as well as avoid having to keep reinstantiating Engines when you actually want to use it for real. It increases the coupling slightly, but might be worth it depending on the application.

  3. h2o2m3n says:

    Loggers are cross cutting concerns, you use ambient context to use them, you can have logger per thread (Thread Local) , you can have a Logger as a singleton (Then you can use service locator.) Essentially, DI fits in here as well.

  4. NashvilEric says:

    assertEquasl(:-)

  5. mikemurko says:

    6:10 I think the reason people code in that way is because they are trying to promote code re-use. They don’t want to have to instantiate EngineFactory a zillion times in their application if they know a car will always need an engine. I know it may not be good DI, but from the angle of code re-use, why is that so bad?

  6. ronnystalker says:

    If House does not require a door why does House ask for a door? According to the Law : “Only ask for what you need”. If you can test House without a door because P{ainting does not need it. It suggests that the “Painting aspect of the House class” ought to be moved elsewhere where it can be tested in isolation.

  7. inzepinz says:

    good talk

  8. kurtdegregorio says:

    cool stuff .. nice i like it =)) thanks for sharing =)) god bless

  9. Divinized says:

    @jessta314

    Exactly what I was going to say. I know a group of people that prefer to dodge NPEs and end up confused when their application behaves oddly.

    I may be naive for it, but I model my code after the Java APIs, they (mostly) don’t check for nulls, and it’s good because most NPEs are caused by coding errors.

  10. flowewritharoma says:

    cool

  11. michaeldeng1981 says:

    if I do outsourcing project, or do a contract project, after delivery I’m done. why should I write unit test. what I care is integration testing and system testing.
    This can explains why contract project has low maintainability in general.

  12. Rico Lelina says:

    How about loggers? Is it ok to have in my class (like most do):

    private static final Logger LOGGER = LoggerFactory.getLogger(MyClass.class);

    Should the logger instance be passed in to?

  13. twistedbydsign99 says:

    11:55 it should definitely be an interface.

  14. Jesse McNelis says:

    @MattCrypto The great thing about nulls is that you instantly knows when the code under test has changed. The null pointer exception you get is a good signal.

  15. magwo says:

    I think it’s mostly considered OK to have globally available loggers, due to one important detail – information flows only to such an object, not from them. You will really never have code that inspects the recently entered log messages, and make decisions based on that data. What one object logs does not affect what other objects do.

  16. 123drums123 says:

    If House does not need Door then maybe you should have an alternative constructor for House object that does not have any arguments? OK, I know… in real application it always needs Door. But removing precondition because we “trust ourselves” is weak… Why do we even have any bugs in code? Why do we review the code others created? There’s no place for such trust – everyone is just a human and sometimes makes mistakes and that is why we need preconditions.

  17. Titousensei says:

    That’s very interesting. But how do you deal with non-essential objects that are possibly needed throughout the code, such as a Logger. Should I pass the global logger to each constructor so that each of their methods can log some messages? Or is it OK to use a singleton in this case?

  18. Exarification says:

    I do not agree with the part 23:54 – 25:24. I think the speaker is incorrect about wanting to test with a null parameter. Symantically speaking, if the house in the constructor states that it needs a door, a test and the rest of the code should always respect this requirement. If in some cases a house doesn’t need a door (like in ‘painthouse’), you could make the method static and pass the needed data as arguments or move the not always needed ‘door’ from the constructor to the specific method.

  19. Jinqiang Zhang says:

    simply good.

  20. kinkokonko says:

    I think you are inventing the point as this is not stated in the talk. The contention stil remains if you use new House(null) and this succeeds but house.getDoor().toString() fails, the code if more fragile. These are Google talks, Bloch = chief architect, and I find these recomendations a bit our of sort. Given you also have Mockito for stubs I think Mitsuko is completely wrong and his ideas seem to come from laziness in developing the tests. test and real code should be of the same standard

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>