cda...@gmail.com writes:
> On Wednesday, March 6, 2019 at 1:57:47 PM UTC-8, Jorgen Grahn wrote:
> > On Wed, 2019-03-06,
cda...@gmail.com wrote:
> > > Are than any decent books meant for inexperienced C++ programs who
> > > need to rewrite Java code in C++? More to the point, I need to
> > > rewrite a few thousand lines of Java code for the Android Platform
> > > to the C++ equivalent on a Microsoft tablet.
> >
> > Do you mean C++ books for Java programmers?
> >
>
> I think C++ for Java programmers might be what I'm look for since I like to
> believe that I'm somewhat versed in imperative programming languages..
You will actually find it easier to learn C++ if you put everything you know
about Java out of your mind.
Despite C++'s deceptively similar syntax, in many ways C++ is fundamentally
different from Java. It is quite common for someone with a Java background
to look at some C++ code that looks almost Java and think it does the same
thing. It does not, and this only causes constant confusion, and common
programming errors that the Java developer will not understand.
> Ideally I'd just like to just change the syntax. Ie, I really don't want to
> have to rewrite the core algorithms.
It is almost a certainty that you will have to. C++ is not Java. Java is
managed code. C++ is not. Java will take care of creating, baby-sitting, and
destroying all of your objects, after the last reference to each object goes
out of scope, and the object becomes subject to garbage collection.
There's nothing of that sort in C++. In C++ you have complete responsibility
for figuring out when objects are no longer needed, and must be destroyed.
Guess wrong one way, and your running program eats all available RAM in a
few seconds. Guess wrong the other way, and you get random crashes in some
completely different part of the code which has nothing wrong with it,
leaving you to wonder WTF is happening.
C++ is not Java. To correctly use C++ for anything beyond "Hello world!" you
need to fully understand C++'s fundamental scoping rules, and actually
understand how objects get created, when they should be created, and when
they should be destroyed. As a Java coder, this is something that you have
never learned, and you simply don't know because Java always did this for
you, by itself. But now you must learn all of this in order to write C++
code that doesn't nuke itself from high orbit, all the time. And you must
learn this 100% correctly. No margin for error, whatsoever. Otherwise your
code will simply not work.
So, no, it is unlikely that you will be able to simply take Java code that
does anything more complicated than printing "Hello world!", and just
replace it with equivalent C++ syntax.