Added: 3 years ago
From: GoogleTechTalks
Views: 38,144
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:
see all

All Comments (34)

Sign In or Sign Up now to post a comment!
  • Comment removed

  • Comment removed

  • But what if I have a method that, say, gets the current time of day? Even given the exact same input, it will, of course, return different values depending on external conditions. What's wrong with that? It seems perfectly intuitive and testable to me!

  • @Synergy9k

    What are you going to test it against?

  • @Synergy9k Whatever method needs this 'current time of day' should have the time of day passed into it; so that you can run your test with a known time of day. Simply having deep areas of your code pulling various outside values without explicit control is asking for testing trouble.

  • There is a ton of great design information in this talk.

  • @blenderpanzi @magwo

    I think you guys are saying the same thing. :p

    If x == y && f(x) != f(y), f is dependent on global state. If f modifies state, it has a side effect.

  • At 24:10

    again: He wants a functional and sideeffect free language. In haskell you CAN change the order of expressions! Why isn't he saying that he does not like OOP languages but would like to use a functional language?

  • @blenderpanzi

    Actually it's not at all about side effects. Side effects do not present a big problem to testability of code, but global state (global side effects) does.

  • @magwo Well, one of my professor said global state equals side effects, mathematically spoken. I just believed him.

  • @blenderpanzi That is not correct. They are obviously not the same thing IMO. However having a mutable global state makes any code anywhere _potentially_ side effect laden, to an unknown extent, because the state changes can propagate between singletons etc.

    If you do not have global state, the side effects can only happen in the set of objects that you are currently testing in isolation, so they can be expected and checked for correctness.

  • @magwo AFAIK: if x == y && f(x) != f(y) then there is a side effect. Having global state (or just object oriented programming with mutable objects) you get such a situation, because there is a hidden parameter. But maybe I did understand something wrong.

  • @blenderpanzi This is true in a purely functional language. In object-oriented languages with mutable objects, side effects do not really imply global state. Objects are created in local scopes, and if two objects are created equally, you should get the same result from obj1.f(x) as obj2.f(x), as well as obj1.f(y) and obj2.f(y) if x==y. Unless you have global state, like static variables, random generators (that are commonly based on the global variable known as the clock) and so on.

  • @magwo Well from a theoretical point of view there are basically two concepts: functional and logic orientated. So I guess all existing languages have to be described with one of these two (lambda calculus is used as the theoretical background for most programming languages), which explains why my professor said in a theoretical lecture that global state (or even mutable objects) are basically side effects. :)

  • I'm at 8:30 and wonder if he will name the child by its name in this talk and say: SIDEEFFECTS! He wants a sideeffect free language. He should use haskell.

  • God I learned this the hard way at my internship. It DOES drive you crazy...

  • i learned - next time I test a credit card system - I will use charge(1) :)

  • @deathbyaclown

    better use charge(-100) ;-)

  • SECRETLY!

  • static data is ok if it an implementation detail and it doesn't change the interface

  • Please do not interrupt in the future. Hold questions until the end of the presentation.

  • Don't you think that Aspect- Oriented programming is the best solution for complex initialization mechanism with both init and finalization methods to be called.

  • Seriously SFTU and stop interrupting.

  • How does global state differ from state inside an object? Methods using/changing member vars can also silently behave differently upon every invocation.

    I have the impression that this talk really just scratches the surface of a bigger issue: the problem of side-effects.

    For me one conclusion after watching this talk is: code with side effects is harder to test than code without side effects.

    Is the speaker on a secret mission to replace OO with purely functional programming? ;)

  • Side-effects are probably the heart of the matter, and pure functional programming does remedy that.

    But still, what I think the point was is "Inversion of Control"; that objects' relations should be well thought out and explicit. That is, it's very bad to use global state as a means to let objects find its environment (and unlike scheme etc., java has got only the object's state and the global environment).

    Also, there's long been a notion of "mutators"/"inspectors"/etc. kinds of methods.

  • Do you mean dependency inversion? One can perfectly write code without dependency inversion, and still not use global variables/structures. In fact, I don't see much of a relation between the two subjects?

  • Comment removed

  • I used the same term that wikipedia uses, IoC, which also states that "Dependency Injection" (same thing, different name? (of dependency inversion)) is a part of IoC.

    Could you please elaborate? From where does an object get its references if not through the constructor/setters or the global environment in a language like Java?

    Of course, I don't take regular method arguments into consideration now, but that's also a place to where dependencies can be moved.

  • The part about the deceptive API is a good summary of why not to have global (mutable) state in any form. Singleton-ness is a big design decision to make, and should never be enforced by a class. It's better to let the user of the class make that decision.

    It may be tempting to let objects discover their environment through the ether that is the global name space. But objects should only know what you let them know.

    Interesting thought to make a separation of "Value" and "Service" objects.

  • Comment removed

  • Very cool video, really interesting. Are those code review cards put up for download somewhere?

  • Very interesting, brilliant, and simple analysis.

Loading...
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more