The Artima Developer Community
Sponsored Link

Java Answers Forum
Back to school for class...

4 replies on 1 page. Most recent reply: Feb 20, 2004 2:06 AM by Vincent O'Sullivan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Back to school for class... Posted: Feb 5, 2004 7:30 AM
Reply to this message Reply
Advertisement
...not so much a question as an observation.

I've just started my first paying java work in over two years. While IDs and JDEs are being sorted out they gave me a copy of a class to look, so I pulled it up in TextPad.

First Impressions:
-- The class runs to about 4,000 lines.
-- The largest single method is over 700 lines, another at over 600 lines and the rest progressively smaller.
-- One (small) method returns nothing but updates an object passed to it as a parameter. All the data that affects the update is all contained in said object and pulled out through getters into local variables before being fed back in via a setter in the same object.
-- All class level variables are prefixed m_... ...so are several local variables.

I think I'm going to be busy.

Vince.


Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: Back to school for class... Posted: Feb 5, 2004 8:58 AM
Reply to this message Reply
Something to help you on your way

http://www.refactoring.com/

Best of luck with that.
Adam

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Back to school for class... Posted: Feb 5, 2004 9:49 PM
Reply to this message Reply
> Something to help you on your way
>
> http://www.refactoring.com/
>
> Best of luck with that.
> Adam

Yes indeed. I think Mr Fowler has given me a job for life.

There's lots of this sort of thing...
if (x > 10)
{
    if (x <= 20)
    {
        if (someOtherCondition)
        {
            doA;
            doB;
            doC;
            doD;
        }
        else
        {
            doA;
            doB;
            doC;
            doE;
        }
    }
}
But at least the code works, so I don't have to debug it, too.

Vince.

David Ramsey

Posts: 34
Nickname: dlramsey
Registered: Apr, 2002

Re: Back to school for class... Posted: Feb 6, 2004 9:22 AM
Reply to this message Reply
You'll find this sort of code in shops that had heavy Structured Analysis and Design backgrounds. These shops often did Fortran or C for many years. Later they switched to C++ on PCs and developed code using MS Dev Studio. Now Dev Studio is a powerful tool... if you are well versed in OOAD and OOP. If you're not, you end up thinking you are an OO programmer while you continue writing procedural code.

Then these folks migrate to Java and their failure to have made the paradigm shift to OO is laid bare. What you are seeing is someone treating an object as though it were a C struct. They have business logic scattered across creation and all of it manipulates the object like a struct. However, since someone told them that Java objects use setters and getters and make fields private, they also use setters and getters, resulting in code that just makes you want to cry.

I know. Been there, done that.

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Back to school for class... Posted: Feb 20, 2004 2:06 AM
Reply to this message Reply
mmm unit tests using JUnit. That seems to imply that they're up to speed on some of the latest techniques... or does it? One thing the JUnit documentation emphasises is that, if a test passes then that's all you need to know. Green line and all that. Here's a typical test method (one of hundreds):
    public void testFunctionConstructor() 
    {
        System.out.println( "===testFunction()===" );
        // First a simple create
        Function test = new Function("XXX", 
                 "YYY");
        System.out.println("after constructor");     
        //assert(testMessage.equals( null));
        assert(test.getFunctionCode().equals("XXX"));
        assert(test.getDescription().equals("YYY"));
        System.out.println( test.toString()  );
        System.out.println("after basic tests");
        test.setDescription("ZZZ");     
        assert(test.getDescription().equals("ZZZ"));
        System.out.println("after desc change");
        System.out.println( test.toString()  );
        
        System.out.println( "===after Function constructor test===" );
    }
One test. Three assertions. Seven print statements to provide a running commentary.
Fortunately, the most important thing is that the tests exist!

I know a good maintenance programmer's code is supposed to blend in seamlessly with the existing code base but there are limits.

Flat View: This topic has 4 replies on 1 page
Topic: loop to a paint method Previous Topic   Next Topic Topic: embed netscape browser into a java application

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use