Blog

What’s in a name…

28 Aug, 2008
Xebia Background Header Wave

Using descriptive names is a good programming practice. Today I came across an example that does quite the opposite. In Maven 2 you can define a proxy when you are working behind a proxy server, and there is this active flag that sets this proxy to active or inactive…. or at least that is what you expect right?

Here is how you can configure a proxy in your settings.xml

  

      company-proxy
      false
      http
      proxy.company.nl
      8080

You would think this would mark the company-proxy as not active. But reality taught me otherwise. Here is the corresponding Maven code that returns the active proxy:

    public synchronized Proxy getActiveProxy()
    {
        if(activeProxy == null)
        {
            java.util.List proxies = getProxies();
            if ( proxies != null && !proxies.isEmpty() )
            {
                if ( proxies.size() > 1 )
                {
                    for ( java.util.Iterator it = proxies.iterator(); it.hasNext(); )
                    {
                        Proxy proxy = (Proxy) it.next();
                        if ( proxy.isActive() )
                        {
                            activeProxy = proxy;
                            break;
                        }
                    }
                }
                else
                {
                    // If we only have one proxy, use it as the active one.
                    activeProxy = (Proxy) proxies.get( 0 );
                }
            }
        }
        return activeProxy;
    }

So apparently "active" does not mean "active", but actually means "active if there is more than one proxy defined". So I suggest to change the name of the "active" property into something like: activeButIfIAmTheOnlyProxyDefinedInTheListOfProxiesThenIAmAlwaysActive. Or perhaps clear documentation would also be an option if you think the name is too long.
Would have saved me half a day of debugging….
Lars

Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts