Search This Blog

2011-06-09

UNglobal State Programming Environment

A year or two ago I stumbled across a very useful Google Tech Talk on YouTube about global state and Singletons and why they're bad:



It makes a lot of sense and after letting it sink in and experimenting with dependency injection myself I can say that it results in much better designs, whether or not you're writing tests (the video is Java-centric and test-centric, but neither is necessary for it to apply). Thinking about it though popular programming environments do impose a lot of global state that is in my experience regularly accessed without a second thought. When you collaborate with other people it's hard to make them understand how global state and Singletons are bad when to them it's the easy and fast way to get their job done. It's my opinion that a large part of the problem is that programmers are just used to global state from their programming environments. What we need is for languages to be updated and newer languages to be done right in the first place. No more global state in the programming environment. Pass that state into the program's entry point. For example:

// C
int main(const system_t * const system, const int argc, const char * argv[])
{
    fprintf(system->stderr, "This was a triumph.\n");

    return 0;
}

// C++
int main(const System & system, const int argc, const char * const argv[])
{
    system.cerr << "This was a triumph." << std::endl;

    return 0;
}

// C#
private static int Main(System system, string[] args)
{
    system.Error.WriteLine("This was a triumph.");

    return 0;
}

/* Java (albeit, while they're at it, main should return an int in Java too) */
public static void main(System system, String [] args)
{
    system.err.println("This was a triumph.");

    system.exit(0);
}

Etc. Wouldn't that be a wonderful platform to develop on? I certainly think so.

2 comments:

  1. I have figured out some important things through your blog post. One other subject I would like to talk about is that there are plenty of games in the marketplace designed specifically for preschool age kids. They contain pattern acceptance, colors, dogs, and designs. These generally focus on familiarization as opposed to memorization. This makes children and kids occupied without having the experience like they are studying. Thanks node js blog platform

    ReplyDelete
  2. Wow, this is truly an influencing take on this idea. And I’d like you to know that I’m really pleased you shared your feelings and knowledge and I find I am in agreement. I seriously respect the straightforward writing plus the effort and hard work you might have you spend writing this post. Loads of thanks yous for that sturdy work on top of that great luck with your web-site, I am awaiting new subjects in the near future. python for loop

    ReplyDelete