Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

The Clean Code Talks - "Global State and Singletons"

Loading...

Sign in or sign up now!
38,155
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Nov 18, 2008

Google Tech Talks
November 13, 2008

ABSTRACT

The Clean Code Talk Series

Speaker: Misko Hevery

Category:

People & Blogs

Tags:

License:

Standard YouTube License

  • likes, 10 dislikes

Link to this comment:

Share to:

Top Comments

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

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

see all

All Comments (34)

Sign In or Sign Up now to post a comment!
  • @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.

  • @Synergy9k

    What are you going to test it against?

  • 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!

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

  • @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. :)

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

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