Java Forum / General / June 2004
Translator tools?
Gerry Murphy - 17 Jun 2004 20:41 GMT I was about to throw in the towel on this project I've inherited. It's about 5,000 Java files, totally undocumented and uncommented.
I asked and looked for tools that would help me make sense of this mess, so far to no avail.
Now the owner of the company is willing to consider redoing it in C++. ( In my opinion there was no good reason for the previous software engineer to write this in Java. It's a pretty straightforward Windows desktop app that would be much easier to understand and maintain had it been written in VC++. There's some evidence he chose Java just so he could get some experience with it,)
Anyhow, I'm not rewriting this by hand. I came across the following in Bruce Eckel's 'Thinking In Java', "I've even heard it suggested that you start with Java, to gain the short development time, then use a tool and support libraries to translate your code to C++, if you need faster execution speed."
Has anybody heard of or better still used such translator tools? Even if it only did 80-90% and the rest required manual intervention it might work.
TIA for any advice.
Gerry Murphy
Mike - 17 Jun 2004 20:55 GMT > I was about to throw in the towel on this > project I've inherited. It's about 5,000 [quoted text clipped - 25 lines] > 80-90% and the rest required manual intervention > it might work. Once at the end of a project I had ~50,000 lines of code that needed very specific documentation by the contract. Instead of documenting the code by hand, as my fellow developers in the project did, I learned how to write compilers. At first I was about two weeks behind them and then in one afternoon all my code was documented without any compiler syntax problems, etc.
My suggestion, write a compiler/translator to change the code to what you want.
Mike
Roedy Green - 17 Jun 2004 21:24 GMT > It's a pretty >straightforward Windows desktop app that would >be much easier to understand and maintain had >it been written in VC++. I would say, the opposite. Generally even badly written Java is fairly easy to follow. Even well written C++ requires enormous coding discipline to be readable.
Your problem may be unfamiliarity with Java. Perhaps you could solve the problem by getting the code documented and cleaned up by someone who knows Java.
Perhaps your predecessor took my essay on how to write unmaintainable code to heart. You can do it is any language.
See http://mindprod.com/jgloss/unmain.html
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Gerry Murphy - 17 Jun 2004 23:08 GMT Hi,
I've found your site very useful. And I'm 99% sure that the previous fellow read your unmaintainable code section. I recognize several of the tips. I think this was unprofessional on his part.
My unfamiliarity I readily admit. I've been studying it on my own but this is my first chance to use it in the job. I don't think the owner would go for hiring an outside party to do as you suggest, and I don't have the authority to do it myself. Ultimately, it's not my code.
Thanks for youe help.
Gerry Murphy
> > It's a pretty > >straightforward Windows desktop app that would [quoted text clipped - 13 lines] > > See http://mindprod.com/jgloss/unmain.html Roedy Green - 17 Jun 2004 21:25 GMT > Has anybody heard of or better still used >such translator tools? E God NO! If the code is an unreadable mess now it will be 5 times a bigger mess after translation.
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Sudsy - 17 Jun 2004 22:07 GMT >> Has anybody heard of or better still used >>such translator tools? E > > God NO! If the code is an unreadable mess now it will be 5 times a > bigger mess after translation. I was about to say essentially the same thing but Roedy beat me to the punch. Think about it: if the Java looks like spaghetti to you now, how do you think it's going to look when translated into C++? The NEXT person to come along will be calling for YOUR head on a platter!
Gerry Murphy - 17 Jun 2004 23:10 GMT The issue is that I understand C++ and have lots of tools I've used over the years that would help me clean it up.
Thanks anyway.
Gerry Murphy
> >> Has anybody heard of or better still used > >>such translator tools? E [quoted text clipped - 7 lines] > The NEXT person to come along will be calling for YOUR head on a > platter! Roedy Green - 18 Jun 2004 01:32 GMT >I was about to say essentially the same thing but Roedy beat me to >the punch. Think about it: if the Java looks like spaghetti to you >now, how do you think it's going to look when translated into C++? >The NEXT person to come along will be calling for YOUR head on a >platter! Does the code at least work?
If it works, likely you best bet is to get someone more familiar with Java to document and clean it up for you. Then is suddenly may seem more comprehensible. (Hint, I do this sort of thing on a contract basis.). You need quite different sorts of docs for newbies and for experienced programmers.
I got in to heck of a fight with a guy on a team once because he was FURIOUS with me for documenting every method and parameter with JavaDoc no matter how obvious it was. He prided himself on terse code, and my JavaDoc blew up his line counts.
If the program seriously does not work, your best bet if you have to maintain this, is just to extract a spec from the working program and from crucial bits of the code, and redo it in the C++ you are familiar with.
The docs most often missing are the "forest" docs. It is easy to figure out how a method works, but much harder to see what it is FOR, and how it fits into the big picture.
The most important docs are the "most obvious" docs to the coder -- what a class is FOR. To him the details are the complicated things. To someone coming cold, details are easy to figure out. What's hard is how the whole thing fits together. What is the overall flow.
In cleanup, you just whittle away, working on the most comprehensible bits. It is a bit like a crossword puzzle. Every part you figure out makes some more part clear.
You refactor and clean up code. This makes new levels of meaning shine through.
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Liz - 18 Jun 2004 02:43 GMT > >I was about to say essentially the same thing but Roedy beat me to > >the punch. Think about it: if the Java looks like spaghetti to you [quoted text clipped - 14 lines] > JavaDoc no matter how obvious it was. He prided himself on terse > code, and my JavaDoc blew up his line counts. Then he was not using a proper method of counting lines.
> If the program seriously does not work, your best bet if you have to > maintain this, is just to extract a spec from the working program and [quoted text clipped - 21 lines] > Coaching, problem solving, economical contract programming. > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary. Sudsy - 18 Jun 2004 02:49 GMT <snip everything>
You quoted, in its entirety, a response to a follow-up post and then added a single line. Could we ask you again to please trim your posts? All you need to quote is a paragraph or two, just to provide some context. Pretty please?
Liz - 18 Jun 2004 02:54 GMT sure no problem as long as i can top post
> <snip everything> Pretty please?
Roedy Green - 18 Jun 2004 03:05 GMT >Then he was not using a proper method of counting lines. I offered to write a program to count lines not counting comments, but his view as good code does not need comments, so comments should count.
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Liz - 18 Jun 2004 03:10 GMT > I offered to write a program to count lines not counting comments, but > his view as good code does not need comments, so comments should > count. There are a couple of public tools that will do it.
jcsc and ncsl
Roedy Green - 17 Jun 2004 22:16 GMT > I was about to throw in the towel on this >project I've inherited. It's about 5,000 >Java files, totally undocumented and uncommented. You want a navigator tool to help you get the sense of how the big picture fits together.
You could try on of the more elaborate IDES such as IntelliJ or Eclipse or SlickEdit or Juliet.
See http://mindprod.com/jgloss/ide.html http://mindprod.com/jgloss/slickedit.html http://mindprod.com/jgloss/juliet.html
Eventually you will have even better tools called SCIDs. See http://mindprod.com/projects/scid.html
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Gerry Murphy - 17 Jun 2004 23:17 GMT I've tried a couple of things already, JavaDoc, Doxygen with GraphWiz, JDepend, and I've been trying to figure out NetBeans so I could at least have an IDE. ( Not only is the code undocumented and uncommented, they build it manually with Sun's command line compiler, some antiquted build tools and other compilers and a mind-numbing array of batch files and makefiles. It's enough to make you weep.) Can't get it to compile with NetBeans so far.
Another problem I'm having my be called 'tool-fatigue'. I need to start making progress ASAP, not taking a week or a month to figure out how to get a tool to work. I will take a look at the ones you recommend however.
Thanks,
Gerry Murphy
> > I was about to throw in the towel on this > >project I've inherited. It's about 5,000 [quoted text clipped - 12 lines] > Eventually you will have even better tools called SCIDs. > See http://mindprod.com/projects/scid.html Thomas Kellerer - 17 Jun 2004 22:28 GMT Gerry Murphy schrieb:
> In my opinion there was no good reason for the previous software > engineer to write this in Java. It's a pretty straightforward Windows > desktop app that would be much easier to understand and maintain had it > been written in VC++. Now, this surely is a wrong conclusion. A bad programmer will write horrible code in both languages (and I tend to think that the code will even be more horrible in C++, but then I'm a Java programmer :) )
A well written Java/Swing application is as easily understood as a well written C++ program.
When it comes to documentation, javadoc is a very powerful tool that can lead (if used at all, and used well) to a good documentation also. I don't know if such a thing exists for C++
I would think that this application would be an absolute nightmare to maintain if you automate the transition to C++ (as already mentioned) if it's already a mess. Automatically generated code is *never* maintainable by a human brain.
If I was you I would consider a complete re-engineering/re-coding using your preferred language. I'm pretty sure that's the fastest thing you can do.
Just my 2 cents.
Thomas
Gerry Murphy - 17 Jun 2004 23:20 GMT What you suggest is the only other option I'd consider, but I don't think the owner would go for the time, money and effort involved. If I don't show some progress it's a tossup whether to walk away or wait a bit and get canned.
Thanks,
Gerry Murphy
> Gerry Murphy schrieb: > [quoted text clipped - 25 lines] > > Thomas Sudsy - 18 Jun 2004 00:17 GMT > What you suggest is the only other option I'd consider, > but I don't think the owner would go for the time, money > and effort involved. If I don't show some progress it's > a tossup whether to walk away or wait a bit and get canned. I was going to ask some probing questions, but you've already been candid in your replies. Would it be fair to suggest that the situation is something like this? - you don't have a lot of Java experience - you've "inherited" a project which is a "rats nest" - you'd like to convert the code to a language with which you're more familiar - you're facing unrealistic expectations and pressure from your management
Welcome to the real world! Sorry if that doesn't sound particularly supportive but it's a fair comment. I well recall the times I was "dropped into it", typically at the 11th hour. So look upon this as a personal and professional challenge! You'll have a tough sell in the expectation management area but you seem to already accept one of the possible outcomes (getting axed). You're also heading in the right direction by trying to import the project into an IDE. Try to provide concrete numbers to management on a daily basis, something along the lines of "I've now got 60% of the code imported and syntactically correct". I don't know Netbeans but some people here swear by Eclipse, particularly for refactoring code. I'm sure that there are also tools available which can analyze the existing code for linkages and dependencies but, having never had to do this kind of job myself, will defer to the recommendations of others. Just keep trying to move forward and explain that even the "best of the best" wouldn't fare well faced with atrocious code. Keep the chin up, try not to dump on the original author, and maintain your integrity. That, as much as your programming prowess, will help you through the most trying of times.
David Alex Lamb - 19 Jun 2004 13:13 GMT >When it comes to documentation, javadoc is a very powerful tool that can >lead (if used at all, and used well) to a good documentation also. >I don't know if such a thing exists for C++ Doxygen
JavaDoc may help a bit even with undocumented code -- it can give you the class hierarchy (labeled Tree in the generated docs), which can be a reasonable place to start understanding the old code. A good IDE should be able to do the same, but I don't use one so can't advise.
I've recently been reading a subset of the vast literature on "program understanding" and "reverse engineering" but haven't (yet?) found much about working tools (just research systems). Anyone know of a good survey.
 Signature "Yo' ideas need to be thinked befo' they are say'd" - Ian Lamb, age 3.5 http://www.cs.queensu.ca/~dalamb/ qucis->cs to reply (it's a long story...)
Liz - 17 Jun 2004 23:42 GMT > I was about to throw in the towel on this > project I've inherited. It's about 5,000 [quoted text clipped - 29 lines] > > Gerry Murphy Sounds like you are looking for an excuse to use the "GOTO" ;-)
Why not reverse engineer it from its behaviour and toss the java code.
Thomas Weidenfeller - 18 Jun 2004 08:38 GMT > I was about to throw in the towel on this > project I've inherited. It's about 5,000 > Java files, totally undocumented and uncommented. Well, we only hear your side of the story. In another posting you confessed that you are a C++ guy (maybe Windows-only?). And you also mentioned a beginner's textbook about Java. Could it be that it is not only the previous programmer who is to blame, but that this system is just beyond your area of competence? That you simply don't like it?
You also told us, that you didn't even manage to set up an IDE and get the thing compiled. Which is, hmm, rather interesting, because Java's class naming requirements (public class name must equal file name), and the common way to lay out a package structure in a file system (each package component becomes a directory) makes it fairly trivial to figure out which files make up the source.
And since you also don't have a preprocessor, there are no nasty surprises when compiling code, because there is no conditional compilation (there is inlining of boolean constants, but this is normal Java code).
Oh, and the reason why you tried to set up an IDE was that you didn't like the current build system. Well, it was good enough for that one guy you call incompetent. But you you can't handle it? Something just smells fishy here.
> I asked and looked for tools that would help > me make sense of this mess, so far to no avail. I have my doubts that any tool in the world will help a Java beginner to understand 5000 interacting Java classes. However, if you want to throw money at it, you can waste money by buying such big cannons like Rational Rose or any other tool which supports full round-trip engineering. Then you pump the code through it (if you manage to find it ...), you get a class diagram and other funky things out of it, and then? You will still scratch your head.
You could also have a look at eclipse and the many available plug-ins if there is anything that suits your need, e.g. eclipse's refactoring tools.
> Now the owner of the company is willing to > consider redoing it in C++. Because you told him? The owner is best advised to first get a second opinion from an experienced Java developer.
> ( In my opinion > there was no good reason for the previous software [quoted text clipped - 4 lines] > he chose Java just so he could get some experience > with it,) No comment.
> Has anybody heard of or better still used > such translator tools? Even if it only did > 80-90% and the rest required manual intervention > it might work. I think you are naive to believe that such a translation would help you. The most common thing between Java and C++ is the syntax. Java's class library (usually heavily used in any Java application), and Java's garbage collection are fundamentally different from what you have in C++. As a consequence, a Java program is most likely structured very differently from a C++ program.
And, in case the Java code is really FUBAR, how could such a translation fix these problems? Garbage in, garbage out.
> TIA for any advice. I don't think you want to thank me after this posting.
/Thomas
Andrew Thompson - 18 Jun 2004 09:09 GMT (OP)
>> I asked and looked for tools that would help >> me make sense of this mess, so far to no avail. Has anybody actually mentioned 'JavaDoc' yet?
You do not make that clear in your rather ..vague question.
 Signature Andrew Thompson http://www.PhySci.org/ Open-source software suite http://www.PhySci.org/codes/ Web & IT Help http://www.1point1C.org/ Science & Technology
Gerry Murphy - 18 Jun 2004 11:07 GMT I did mention it in a reply to Roedy Green, you might also have remembered that you yourself mentioned it in comp.lang.java.help. Perhaps you forgot because you were too busy with gratuitous insults. I think I'd be happier if you didn't respond to my posts in future.
> (OP) > >> I asked and looked for tools that would help [quoted text clipped - 4 lines] > You do not make that clear in your rather > ..vague question. Andrew Thompson - 18 Jun 2004 13:35 GMT > I did mention it in a reply to Roedy Green, > you might also have remembered that you > yourself mentioned it in comp.lang.java.help. ahh yes,.. <http://groups.google.com/groups?th=6ac5ef631b675a37> I see you should have not learned much and should still be posting there.. ;-)
> Perhaps you forgot because you were too busy > with gratuitous insults. ..or perhaps I was too busy helping people who deserve help, to recall ..you.
>..I think I'd be happier > if you didn't respond to my posts in future. Sure, if you don't completely slip my mind, again.. ;-)
OTOH, I empower *you* to plonk me. It's your choice, sunshine..
 Signature Andrew Thompson http://www.PhySci.org/ Open-source software suite http://www.PhySci.org/codes/ Web & IT Help http://www.1point1C.org/ Science & Technology
Gerry Murphy - 18 Jun 2004 21:33 GMT > Well, we only hear your side of the story. In another posting you > confessed that you are a C++ guy (maybe Windows-only?). And you also > mentioned a beginner's textbook about Java. Could it be that it is not > only the previous programmer who is to blame, but that this system is > just beyond your area of competence? That you simply don't like it? I've been primarily a C++ guy, mostly windows, occasionally Unix for twenty years. Also several other languages.
> You also told us, that you didn't even manage to set up an IDE and get > the thing compiled. Which is, hmm, rather interesting, because Java's > class naming requirements (public class name must equal file name), and > the common way to lay out a package structure in a file system (each > package component becomes a directory) makes it fairly trivial to figure > out which files make up the source. The code compiles as is with the existing build. And the, "...common way to lay out a package structure in a file system..." you mention has been explicitly violated in this code.
> Oh, and the reason why you tried to set up an IDE was that you didn't > like the current build system. Well, it was good enough for that one guy > you call incompetent. But you you can't handle it? Something just smells > fishy here. Now you're just being nasty. Please point out where I called anyone incompetent?
> > Now the owner of the company is willing to > > consider redoing it in C++. > > Because you told him? The owner is best advised to first get a second > opinion from an experienced Java developer. No, it was his idea actually. You're just full of unwarranted assumptions, aren't you?
> TIA for any advice. > > I don't think you want to thank me after this posting. > > /Thomas Wrong again. Thank you.
Chris Smith - 19 Jun 2004 21:26 GMT Gerry,
Here's my opinion on the matter, for what it's worth.
First of all, while Thomas wrote one of the more insulting replies in this thread, he also managed to be exactly right about at least one thing. So I quote:
Thomas Weidenfeller wrote:
> I think you are naive to believe that such a translation would help you. > The most common thing between Java and C++ is the syntax. Java's class > library (usually heavily used in any Java application), and Java's > garbage collection are fundamentally different from what you have in > C++. As a consequence, a Java program is most likely structured very > differently from a C++ program. This is a very reasonable explanation of what you can expect from a conversion tool. If you were familiar with a language that exhibits wildly different syntax, I could see translating just so you're more comfortable with the resulting code. Java, though, is almost identical to C++ regarding its procedural language features and general syntax. The only major things that differ are exactly those things that you will not be able to translate in an automated way.
I expect if you've really got a bunch of poor code, that it's mostly poor in how it interacts with the core library or other third-party APIs. You're absolutely not going to be able to automate a conversion from a Swing-based application to an MFC application with Visual C++. The means of performing common tasks are just so different from each other that this would be better done as a translation by hand.
If I were you and had a project of this size, I'd start learning Java and try to improve as you go. Write unit tests. Use automatic refactoring support. Make changes that you think should still work and then repeat your unit tests to verify that they do. If you're experienced with C++, you should have a fairly good idea what constitutes good design in an OO environment, so you are qualified to do this. The change across languages, though, just introduces more work and more cleaning up to get done.
And, of course, if you have specific questions we're happy to address them.
 Signature www.designacourse.com The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
Gerry Murphy - 21 Jun 2004 21:49 GMT Hi,
Yes, what you suggest is what I'm doing. I finally sorted out the problems I was having with NetBeans and was able to compile some of the code. Within minutes I discovered packages being imported but never used. Today I ran another tool that discovered lots of dead code.
The translator issue was based on a quote in a book and the only reason I threw it out there was the owner expressed a willingness to have this rewritten in C++, which I wasn't about to do by hand given his timelines.
Until last Friday I felt like Sisyphus, but the boulder wouldn't budge. At least now it's movimg a bit, even if it is uphill. 8-}
Thanks,
Gerry Murphy
> Gerry, > [quoted text clipped - 38 lines] > And, of course, if you have specific questions we're happy to address > them. Thomas Weidenfeller - 22 Jun 2004 09:58 GMT > First of all, while Thomas wrote one of the more insulting replies in > this thread, The OP set the tone of the discussion by throwing wild accusations about this predecessor around. Especially when taking into account that he is a Java beginner. Nothing wrong with being a beginner, but that doesn't really qualify him to judge other people's work, bad mouth them and call them unprofessional.
Ironically, he accused his predecessor to have chosen Java just to learn it, while in some other post he also admitted that he took the job so he could work with Java - presumably to learn it. Now, what is wrong with that picture? When his plan didn't work out because he can't handle the existing code, he panicked, bad mouthed his predecessor and tried to go back to C++. IMHO, it is not the previous programmer who is responsible for the failure of his plan.
/Thomas
Gerry Murphy - 23 Jun 2004 00:38 GMT Wow, where do I begin with this guy? Let's take it point by point:
> > First of all, while Thomas wrote one of the more insulting replies in > > this thread, [quoted text clipped - 4 lines] > really qualify him to judge other people's work, bad mouth them and call > them unprofessional. I asked you to document the insults you alleged. You still haven't.
> Ironically, he accused his predecessor to have chosen Java just to learn > it, while in some other post he also admitted that he took the job so he [quoted text clipped - 3 lines] > back to C++. IMHO, it is not the previous programmer who is responsible > for the failure of his plan. Let me fill you in. The code base originallly WAS C++. It was the opinion of folks who worked with him that he unilaterally made the change for personal reasons, not for any valid engineering reasons. After inspecting his code I tend to concur.
I did take the job to learn Java. Note that in doing so I'm not changing anything. Going back to C++ was merely one option I was considering. Perhaps, "...what is wrong with that picture..." is that the distinction is too subtle for you.
> IMHO, it is not the previous programmer who is responsible > for the failure of his plan. Well, time will tell what your opinion is worth. BTW, I haven't panicked and the rumors of the 'failure of my plan' are greatly exaggerated.
Tim Ward - 18 Jun 2004 10:00 GMT > I was about to throw in the towel on this > project I've inherited. It's about 5,000 > Java files, totally undocumented and uncommented. After automatic translation you would have 5,000 lines of undocumented and uncommented C++ (in fact worse than the original because any such translation process is bound to introduce messy artefacts), yes? This would be better than the original how, exactly?
For such a tiny project I'd just rewrite in C++ from the specification, maybe I'd have a look at the Java code first, maybe I wouldn't. (I wouldn't have given this answer if you'd had 500,000 lines of rubbish Java.)
-- Tim Ward Brett Ward Limited - www.brettward.co.uk
Thomas Kellerer - 18 Jun 2004 10:30 GMT >> I was about to throw in the towel on this >>project I've inherited. It's about 5,000 >>Java files, totally undocumented and uncommented. > > For such a tiny project I'd just rewrite in C++ from the specification, > maybe I'd have a look at the Java code first, maybe I wouldn't. It's not a tiny project. It's 5000 Java *files* not /lines/
Thomas
Tim Ward - 18 Jun 2004 10:41 GMT > >> I was about to throw in the towel on this > >>project I've inherited. It's about 5,000 [quoted text clipped - 4 lines] > > It's not a tiny project. It's 5000 Java *files* not /lines/ Whoops! - so it is, misread that.
-- Tim Ward Brett Ward Limited - www.brettward.co.uk
Roedy Green - 18 Jun 2004 17:59 GMT >It's not a tiny project. It's 5000 Java *files* not /lines/ Good lord. It is astounding someone could keep track of a project in their own head that big without documenting as they went.
Some young hot shot right?
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|