Minority Opinions

Not everyone can be mainstream, after all.

Inconvenience Class

leave a comment »

I learned Java in college, and even preferred it over C++ for a while.  Since learning Python, however, I have barely touched it.  That might change if I get GLX working on my LFS box, so I can run the Android SDK, but I’m not exactly looking forward to it.

It’s not just the language that bugs me, though there are plenty of sharp edges to cut yourself on.  No, what really baffles me is the culture that has grown around it, full of excess verbosity.  Public getters and setters that do nothing but get and set a private variable, just in case they might sometime need to do something else.  Factory classes, because you can’t just pass a class.  Thousands of tiny methods that obscure where the real work gets done.  Hundreds of files, because each individual class needs its own.  Deeply nested hierarchies, just in case your code gets used with something that might have a conflicting name.

Case in point:  I once again encountered a place in our PHP codebase where I wanted to do something that had already been done, but by a co-worker trained in the Java tradition.  Fortunately, most of the real logic was contained in a single function, so I was able to extract it into something reasonable.  In the interests of backwards compatibility, I left this behind:

class ImportCFT {
        # Convenience class to make calling the above function harder.

        private $filepath;
        private $filename;
        private $varnames = array();
        private $dump;
        private $dumpkeys;

        function setFilepath($filepath) {
                $this->filepath = $filepath;
        }

        function setFilename($filename) {
                $this->filename = $filename;
        }

        function setVarnames($varnames) {
                $this->varnames = $varnames;
        }

        function getDump() {
                return $this->dump;
        }

        function import() {
                $this->dump = import_cft($this->filepath . $this->filename);
        }
}

No, I don’t know what $varnames was supposed to do, even though it was used by at least one caller.  The original import() did set $dumpkeys as a side effect, but since it didn’t have a getter and contained no useful information, there didn’t seem to be a reason to keep that behavior.

Advertisements

Written by eswald

12 Mar 2013 at 7:35 pm

Posted in Employment, Technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s