By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

Java or C++?

P: n/a
Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
Jun 27 '08 #1
Share this Question
Share on Google+
29 Replies


P: n/a
in 342367 20080414 074410 s0****@gmail.com wrote:
>Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
C++ is for masochists. Go for Java.
Jun 27 '08 #2

P: n/a
On Apr 14, 12:21 pm, Bob Martin <bob.mar...@excite.comwrote:
in 342367 20080414 074410 s0s...@gmail.com wrote:
Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
Certainly Java. It's also easier to find Java jobs than C++ jobs.

Jun 27 '08 #3

P: n/a
On Apr 14, 11:44*am, s0s...@gmail.com wrote:
Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
Well if you need an easier transition, go for java. But personally i
would recommend you to go for C/C++. There are a few very solid
reasons for that.
1. You can still use ur python konwledge, integrate python with you
applications, extend python with C/C++ .. and so on. That would not
only benefit you but the whole community.
2. C/C++ is likely to teach you more things in this transition than
java will. You probably know all the good software engineering stuff
and things like that maybe, (which you can still use in python) but
going to C/C++ you can actually delve into systems programming and
things like that. When you do that, again, you can extend python and
contribute to the community.
3. When you get hold of c/c++, there will be lesser friction in you
forever to transition to any other language. I appriciate that you
chose python in the first place since that is what i advocate as
well ... the way i see programming should be taught or taken up is
like :
bash/shell scripting -python/perl -c/c++ -assembly .... (from
there on, given you give enough time to the end parts, you should not
have any difficulty going to C#/Java/VB/Delphi or whatever for some
nice RAD or even production level performance not-so-critical
applications). So if you're intrested in system programming getting to
know how things get done, have a SOLID computing background and give
python what python gave you, go for C/C++.
Jun 27 '08 #4

P: n/a
s0****@gmail.com a écrit :
Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
if it's for educational purpose, then you have absolutely nothing to
learn from Java. On the hi-level languages side, I'd rather recommend
Haskell or OCaml (functional programming) and/or Erlang (concurrent
programming). And if you want to go the 'close to the metal' way, then
better to learn C.

My 2 cents...
Jun 27 '08 #5

P: n/a
On Mon, 14 Apr 2008 00:49:13 -0700, xakee wrote:
Well if you need an easier transition, go for java. But personally i
would recommend you to go for C/C++.
What's that C/C++!? C and C++ are quite different languages.

Ciao,
Marc 'BlackJack' Rintsch
Jun 27 '08 #6

P: n/a
s0****@gmail.com wrote:
Which one do you think will educate me the best?
Advanced javascript might teach you something too, and be very useful at
the same time.
Take a look at the Crockford lessons on Yahoo! Video.
http://video.yahoo.com/watch/111593
http://video.yahoo.com/watch/111594
http://video.yahoo.com/watch/111595
http://video.yahoo.com/watch/111596

http://video.yahoo.com/watch/111585
http://video.yahoo.com/watch/111586
http://video.yahoo.com/watch/111587

Jun 27 '08 #7

P: n/a
On Apr 14, 2:24*am, bdsatish <bdsat...@gmail.comwrote:
On Apr 14, 12:21 pm, Bob Martin <bob.mar...@excite.comwrote:
in 342367 20080414 074410 s0s...@gmail.com wrote:
>Hello, I was hoping to get some opinions on a subject. I've been
>programming Python for almost two years now. Recently I learned Perl,
>but frankly I'm not very comfortable with it. Now I want to move on
>two either Java or C++, but I'm not sure which. Which one do you think
>is a softer transition for a Python programmer? Which one do you think
>will educate me the best?

Certainly Java. It's also easier to find Java jobs than C++ jobs.
Depending on the field, that is.
Jun 27 '08 #8

P: n/a
On Apr 14, 1:44*am, s0s...@gmail.com wrote:
Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
It depends on your reasons for learning either. If you're targeting a
specific job market, find out what is prevelant in that market. And
keep in mind that if it's for a job, you'll also have to get up to
speed on the relevant libraries and frameworks.

If it's educational, I'd recommend C++ just to learn about pointers
and memory management, so you get a better idea of what's going on
under the covers in languages like Java and Python and Ruby and C#.
Jun 27 '08 #9

P: n/a
Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
I can't say from personal experience (it was C, C++, then Python for me)
but I think you'll find Java very annoying, especially if you value
Python for elegance. Both C++ and Java have different philosophy than
Python, but C++ is better designed and more flexible.

As for the 'number of jobs' argument, sure there are more Java jobs but
this is offset by the number of Java programmers.

Cheers,
Greg
Jun 27 '08 #10

P: n/a
On Apr 14, 2:44 am, s0s...@gmail.com wrote:
Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
If you weren't comfortable with Perl my bet is that you'll be less
comfortable with C++ than Java.

It's softer transition to Java than to C++ from just about any
starting point.
Carl Banks
Jun 27 '08 #11

P: n/a
My idea, if you really love Python and never think about erasing it
from your mind, go for C (not C++). A script language plus C can solve
every problem you need to solve. Also Python works pretty fine with C.
I agree mostly with this one. Scripting is very nice when writing an
application especially one that needs to change very often. Plus there
are several toolkits and existing libraries available for Python. I've
used wxPython some with it, and it came in handy for a few applications
that I would have normally written in C++/wxWidgets and have to
recompile every few weeks to suit my needs (data extraction tools/etc)

However there are cases when a compiled language is better, especially
anything that needs to be 'fast' and have a lower overhead. I wouldn't
use Python to create a very graphics intensive game or anything, though
it can be used with pygame/PyOpenGL for some nice simple stuff. Also
everything in Python is an object so it can start to consume memory when
handling very large data sets. And since there is no guarantee of when
garbage collection occurs, simply 'deleting' an item does not ensure it
is completely gone, especially if there are cyclic references, though
that can be handled by using 'gc.collect()'.

I consider C++ just a simplification of C, in the sense that it makes it
easier to do things that would take more work to be done in C. One can
still use C++ without all of the more complicated aspects but still take
advantages of other aspects.

C has the advantage that it does not to anything behind your back. This
is very useful especially for any form of system development or where
you must know exactly what is going on. It is still possible to do
'object oriented' development in C, it just requires some more typing to
set up whatever is needed. Even things like COM for windows can be done
in C, it just requires manually building the 'vtable' so to speak.
Also, C seems to avoid the use of temporaries where as C++ can use them
in conversions and assignments automatically if needed.

C++ makes some of it easier by doing certain things for you. Take a
string object for example. In C, assignment would only do a memory copy
operation:

String a, b;
b = a;

The statement 'b = a' would only copy the memory and pointers from 'b'
to 'a' which means they would both point to the same buffer. To avoid
this, a copy constructor or assignment operator can be implemented when
using C++. The same in C would be something like:

String_Assign(&b, &a); /* instead of b = a */

Then if a structure contains objects, more work is needed. For example,
in C:

typedef struct Name
{
String honorary;
String first;
String middle;
String last;
String lineage;
} Name;

void Name_Create(Name* name)
{
String_Create(&name->honorary);
String_Create(&name->first);
String_Create(&name->middle);
String_Create(&name->last);
String_Create(&name->lineage);
}

void Name_Assign(Name* self, Name* other)
{
String_Assign(&self->honorary, &other->honorary);
String_Assign(&self->first, &other->first);
String_Assign(&self->middle, &other->middle);
String_Assign(&self->last, &other->last);
String_Assign(&self->lineage, &other->lineage);
}

Name p1, p2;
Name_Create(&p1);
Name_Create(&p2);
Name_Assign(&p2, &p1);

But in C++, this is no problem:

Name p1, p2;
p2 = p1;

This will automatically call the constructors of any contained objects
to initialize the string. The implicit assignment operator
automatically performs the assignment of any contained objects.
Destruction is also automatic. When 'p1' goes out of scope, during the
destructor the destructor for all contained objects is called.

And if you want more control you can implement the default and copy
constructors, destructor, and assignment operator, and tell them to do
what you want. Just beware because the explicit constructors only calls
default constructors of any parent classes (even the copy constructor)
unless an initializer list is used, and an explicit assignment will not
automatically do assignment of parent classes.

Neither C nor C++ is really better, it depends on the what needs to be
done. C does only what it is told, and also has easier external linkage
since there is no name mangling. C++ does a lot of the needed stuff
automatically, but explicit constructors and assignment operators can
still be declared to control them, and frequently doing the same thing
in C++ takes fewer lines of code than in C.

As for Java, I think it is 'overly-used' in some areas, especially in
embedded development. I attended NC State and during orientation this
representative was talking about a small little robotic device and how
it had a full Java VM inside it and it only took '6 minutes to boot'.
Some claim it is for portability that Java is so good in embedded
devices. But still, if the program is moved to another device, it may
still need to be changed and recompiled if the new devices has different
IO pins, timers, interrupts, etc. Most chips have a C
compiler/translator available, and the same program could have been
written in C, compiled directly to the machine code needed for the
device, 'booted' immediately, and not needed a Java VM as well. If
portability to other devices is desired then an abstract layer could be
created in the program and the device/hardware specific code could be
seperated to that layer seperatly from the rest of the program.

Well, all of that is just my opinion though, not meant to offend anyone.


Jun 27 '08 #12

P: n/a
in 342436 20080414 160208 =?UTF-8?B?R3J6ZWdvcnogU8WCb2Rrb3dpY3o=?= <je*****@wp.plwrote:
>Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
I can't say from personal experience (it was C, C++, then Python for me)
but I think you'll find Java very annoying, especially if you value
Python for elegance. Both C++ and Java have different philosophy than
Python, but C++ is better designed and more flexible.
You must be joking - better designed? C++ was a botch to an already poor
language.

Personally I find Java very satisfying to write.
Jun 27 '08 #13

P: n/a
Brian: Impressive!
This is the most balanced, well-informed and interesting reply to this
debate. I would like to make some comments even so.

I have tried all languages, and consider myself agnostic. However, I
would like to roughly repeat what James Gosling (Java inventor) said
at a lecture I attended: Java is nice because you can work in Java
everywhere now - from embedded to desktops to supercomputers and
servers. And, I would like to make my own comment: Java is the
language I have tried which gives you the most help as a developer.
For every crash, there is a complete and useful stack trace. Using
Eclipse, you can auto-generate much of the 'boilerplate' code which is
claimed to make Java boring to write (get, set, constructors...). It
also more or less tells you how to fix small bugs - ';' and } missing
for example. Even python is less helpful; concider "Unexpected indent"
or the very informative "incorrect syntax" when you forget a ) or a : .

C (or C++) for learning to talk to the metal,
Java or Python for object orientation,
Java will give you the most help,
Python gets you started quickly,
C++ is the hardest to understand in every detail,
but C bogs you down with administrative stuff (try converting an int
to a string; I found myself googling for an hour!).

I tried this infamous "extending in C" and I would forget that until
you know both C and python a bit more... Also, extending python in C++
or Java is possible - I didn't manage C++ yet, and Java I didn't try.
Cheers!
Paul.
Den 15. april. 2008 kl. 05.46 skrev Brian Vanderburg II:
>My idea, if you really love Python and never think about erasing it
from your mind, go for C (not C++). A script language plus C can
solve
every problem you need to solve. Also Python works pretty fine with
C.
I agree mostly with this one. Scripting is very nice when writing an
application especially one that needs to change very often. Plus
there
are several toolkits and existing libraries available for Python.
I've
used wxPython some with it, and it came in handy for a few
applications
that I would have normally written in C++/wxWidgets and have to
recompile every few weeks to suit my needs (data extraction tools/etc)

However there are cases when a compiled language is better, especially
anything that needs to be 'fast' and have a lower overhead. I
wouldn't
use Python to create a very graphics intensive game or anything,
though
it can be used with pygame/PyOpenGL for some nice simple stuff. Also
everything in Python is an object so it can start to consume memory
when
handling very large data sets. And since there is no guarantee of
when
garbage collection occurs, simply 'deleting' an item does not ensure
it
is completely gone, especially if there are cyclic references, though
that can be handled by using 'gc.collect()'.

I consider C++ just a simplification of C, in the sense that it
makes it
easier to do things that would take more work to be done in C. One
can
still use C++ without all of the more complicated aspects but still
take
advantages of other aspects.

C has the advantage that it does not to anything behind your back.
This
is very useful especially for any form of system development or where
you must know exactly what is going on. It is still possible to do
'object oriented' development in C, it just requires some more
typing to
set up whatever is needed. Even things like COM for windows can be
done
in C, it just requires manually building the 'vtable' so to speak.
Also, C seems to avoid the use of temporaries where as C++ can use
them
in conversions and assignments automatically if needed.

C++ makes some of it easier by doing certain things for you. Take a
string object for example. In C, assignment would only do a memory
copy
operation:

String a, b;
b = a;

The statement 'b = a' would only copy the memory and pointers from 'b'
to 'a' which means they would both point to the same buffer. To avoid
this, a copy constructor or assignment operator can be implemented
when
using C++. The same in C would be something like:

String_Assign(&b, &a); /* instead of b = a */

Then if a structure contains objects, more work is needed. For
example,
in C:

typedef struct Name
{
String honorary;
String first;
String middle;
String last;
String lineage;
} Name;

void Name_Create(Name* name)
{
String_Create(&name->honorary);
String_Create(&name->first);
String_Create(&name->middle);
String_Create(&name->last);
String_Create(&name->lineage);
}

void Name_Assign(Name* self, Name* other)
{
String_Assign(&self->honorary, &other->honorary);
String_Assign(&self->first, &other->first);
String_Assign(&self->middle, &other->middle);
String_Assign(&self->last, &other->last);
String_Assign(&self->lineage, &other->lineage);
}

Name p1, p2;
Name_Create(&p1);
Name_Create(&p2);
Name_Assign(&p2, &p1);

But in C++, this is no problem:

Name p1, p2;
p2 = p1;

This will automatically call the constructors of any contained objects
to initialize the string. The implicit assignment operator
automatically performs the assignment of any contained objects.
Destruction is also automatic. When 'p1' goes out of scope, during
the
destructor the destructor for all contained objects is called.

And if you want more control you can implement the default and copy
constructors, destructor, and assignment operator, and tell them to do
what you want. Just beware because the explicit constructors only
calls
default constructors of any parent classes (even the copy constructor)
unless an initializer list is used, and an explicit assignment will
not
automatically do assignment of parent classes.

Neither C nor C++ is really better, it depends on the what needs to be
done. C does only what it is told, and also has easier external
linkage
since there is no name mangling. C++ does a lot of the needed stuff
automatically, but explicit constructors and assignment operators can
still be declared to control them, and frequently doing the same thing
in C++ takes fewer lines of code than in C.

As for Java, I think it is 'overly-used' in some areas, especially in
embedded development. I attended NC State and during orientation this
representative was talking about a small little robotic device and how
it had a full Java VM inside it and it only took '6 minutes to boot'.
Some claim it is for portability that Java is so good in embedded
devices. But still, if the program is moved to another device, it may
still need to be changed and recompiled if the new devices has
different
IO pins, timers, interrupts, etc. Most chips have a C
compiler/translator available, and the same program could have been
written in C, compiled directly to the machine code needed for the
device, 'booted' immediately, and not needed a Java VM as well. If
portability to other devices is desired then an abstract layer could
be
created in the program and the device/hardware specific code could be
seperated to that layer seperatly from the rest of the program.

Well, all of that is just my opinion though, not meant to offend
anyone.


--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #14

P: n/a
On 15 ÁÐÒ, 07:46, Brian Vanderburg II <BrianVanderbu...@aim.com>
wrote:
[...]
C has the advantage that it does not to anything behind your back. This
is very useful especially for any form of system development or where
you must know exactly what is going on. It is still possible to do
'object oriented' development in C, it just requires some more typing to
set up whatever is needed. Even things like COM for windows can be done
in C, it just requires manually building the 'vtable' so to speak.
Also, C seems to avoid the use of temporaries where as C++ can use them
in conversions and assignments automatically if needed.
Great point. It's also possible to do Python object-oriented
programming in C. 'PyMethodDefs' are the same 'vtables'. I've found
that Python/C API is not that hard, the problem is a lack of good
tutorials and false assumptions that ctypes or SWIG are somehow
better. After `#include Python.h` C becomes very Python friendly.
Jun 27 '08 #15

P: n/a
What is the role or position of C# in this context ?
If I remember well, some people have said that C# is an improved
C++ or Java.
e
--
Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991
================================================== ======================
Jun 27 '08 #16

P: n/a
egbert wrote:
What is the role or position of C# in this context ?
If I remember well, some people have said that C# is an improved
C++ or Java.
e
I think C# is in a great position, and might be recommended. C# has the
added advantage of being able to very easily work with IronPython. Thus
if you want to develop with .NET you can easily wield the beauty of
python with C# for speed or library routines.

Of course Jython does the same for Java, although it's way behind in
development these days.

Slick python integration is one area where C# and Java would beat out
C++. Sure there's Boost::Python, but the learning curve is kind of
steep. Installation, even, is difficult. Python's C API is very simple
and C-like, so if one chooses to use primarily a C/Python combination
(typically what I do these days), it works well, but not quite as easy
as IronPython and C#.

Diving into the debate, I personally think all programmers, and
especially computer science people, should be proficient in C. You
should be able to write thousands of lines of C code, use dynamic memory
allocation, data structures, etc, and have very few resource leaks if
you choose your tools wisely (glib for C ought to be standard!). This
is to give you a background and low-level understanding. However you're
not likely to program in C professionally unless you are into systems
programming, or are affiliated with core, low-level things like library
development, or embedded systems.

As for C++ and Java, I've found that good C++ programmers can *easily*
move to Java when they want/need to. The reverse is *not typically
true*. Java lends itself to too many bad habits that kill would-be C++
programmers, particular in regards to resource management and things
like destruction after scope. I think that is a critical thing that
people forget sometimes. Similarly people proficient in Unix and Linux
computers, both use and development on, can much more easily move to
Windows than the other way around.

A good programmer should be able to pick up new languages and paradigms
fairly easily, and become fluent in just a few weeks. For me it's
typically one week, although learning frameworks and toolkits is more
difficult (Java frameworks). A good exercise might be to pick up one
new language per year and do something major with it (say 4000-10000
loc). Choose a new genre like web programming to explore. Whatever.
Next time a little pet project comes up, try a new language or a new
toolkit. Try some shell-scripting in scsh using scheme.
Jun 27 '08 #17

P: n/a
On Apr 15, 3:07*am, Paul Anton Letnes <paul.anton.let...@gmail.com>
wrote:

but C bogs you down with administrative stuff (try converting an int *
to a string; I found myself googling for an hour!).
It took an hour to find sprintf()?
Jun 27 '08 #18

P: n/a
On Apr 15, 11:55*am, egbert <egbert.bouw...@hccnet.nlwrote:
What is the role or position of C# in this context ?
If I remember well, some people have said that C# is an improved
C++ or Java.
C# is more similar to Java than C++. Neither is very similar to C++,
except in some cosmetic syntactic ways. Personally, that would be my
last choice. C++ is the most portable of the three, and the only non-
proprietary one (like Python).
Jun 27 '08 #19

P: n/a
You must be joking - better designed? C++ was a botch to an already poor
language.
Although I'm relatively new to the concept that C++ is too difficult to
use, I would concede that with certain mindset and priorities Java may
be a valid choice. Not so if one is willing to expand knowledge about
programming and find a complement for Python.

Where I can't agree is that C is a poor language. You may prefer Unix
was written in Pascal but C is still an excellent language, if no longer
'general-purpose.'

C++ continues its philosophy of granting as much control as possible to
the programmer. Whether it's a good or bad thing is debatable and
depends on purpose for which you're using it.
Personally I find Java very satisfying to write.
Bing.
Jun 27 '08 #20

P: n/a
Well, if you're new - first find the function, then how to use it,
this funny %d5 (or something, don't remember) syntax - it's hard
compared to:
cout << 5 or similar stream tricks, or just 5 + "" in Java, or just
str(5) in Python. Anyway, small tasks are very hard for C newbies.


Den 15. april. 2008 kl. 19.35 skrev lb*******@yahoo.com:
On Apr 15, 3:07 am, Paul Anton Letnes <paul.anton.let...@gmail.com>
wrote:

>but C bogs you down with administrative stuff (try converting an int
to a string; I found myself googling for an hour!).

It took an hour to find sprintf()?
--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #21

P: n/a
On Apr 15, 1:46 pm, Brian Vanderburg II <BrianVanderbu...@aim.com>
wrote:
This will automatically call the constructors of any contained objects
to initialize the string. The implicit assignment operator
automatically performs the assignment of any contained objects.
Destruction is also automatic. When 'p1' goes out of scope, during the
destructor the destructor for all contained objects is called.
Yeah, C++ does try to be helpful, and all of those automatic copy
constructor, assignment operator and destructor implementations screw
up royally when confronted with pointers (and being able to use
pointers is basically the whole reason for bothering to write anything
in C or C++ in the first place). Code which relies on these default
method implementations is almost certain to be rife with memory leaks
and double-free bugs. So instead of being a convenience, they become a
painfully easy way of writing code that silently does some very, very
wrong things.

Other things like methods (including destructors!) being non-virtual
by default also make C++ code annoyingly easy to get wrong (without it
obviously looking wrong).

The whole design of C++ is riddled with premature optimisation of
speed and memory usage in the default settings, instead of choosing
safe defaults and providing concise ways of allowing the programmer to
say "I know optimisation X is safe here, please use it".

And the result? Any serious project in the language has to adopt it's
own techniques for avoiding all those traps, and those techniques are
likely to eliminate any supposed optimisations provided by the choices
of the C++ committee, while filling a code base with boilerplate that
only exists for the purpose of working around defects in the language
design (Scott Meyers has written at length about the worst of these
issues, far more clearly and eloquently than I ever could [1]).

That said, C++ code has one *huge* benefit over ordinary C code, which
is scope-controlled deletion of objects, and the associated Resource-
Acquisition-Is-Initialisation model. Even without using exceptions
(although those are handy as well), RAII is an excellent way of
guaranteeing that memory is freed, files are closed, or other
resources are released when a block of code is finished. RAII was
actually one of the inspirations behind the final form of PEP 343's
with statement.

Cheers,
Nick.

[1]http://www.amazon.com/Effective-Specific-Addison-Wesley-
Professional-Computing/dp/0201924889
Jun 27 '08 #22

P: n/a
On Apr 14, 11:44*am, s0s...@gmail.com wrote:
Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?
The movement from knowing no programming language to knowing one is
invariably a much larger one than the shift from one to two (see
http://en.wikipedia.org/wiki/Diminishing_returns). That is you are
likely to get much less from this shift than what you got from python
two years ago.

So before you make this shift do ask yourself: have you got the best
of what python has to offer? I taught python in the univ for a number
of years and I would always tell my students that the library
reference gave a better conspectus of modern day computer science/IT
than anything else I knew of. [That not too many of them listened is
another matter :-) ]
Then python has a lot of advanced (new) stuff: generators and
generator expressions, comprehensions, lambdas and functional
programming, descriptors and protocols....

That said you can of course choose your second language to optimize
your learning (where optimize could be minimize or maximize!)

One language that is promising (and under active development) is curl.
(http://www.curl.com)
It is targeted to be
like C++ in efficiency (native compiler not VM or interpreter)
like C#/Java in its OOP with gc style
like Javascript in supporting dynamic rich web apps
in addition to replacing HTML
Jun 27 '08 #23

P: n/a
On Mon, 21 Apr 2008 06:14:08 -0700 (PDT), NickC <nc******@gmail.comwrote:
On Apr 15, 1:46 pm, Brian Vanderburg II <BrianVanderbu...@aim.com>
wrote:
>This will automatically call the constructors of any contained objects
to initialize the string. The implicit assignment operator
automatically performs the assignment of any contained objects.
Destruction is also automatic. When 'p1' goes out of scope, during the
destructor the destructor for all contained objects is called.

Yeah, C++ does try to be helpful, and all of those automatic copy
constructor, assignment operator and destructor implementations screw
up royally when confronted with pointers
I think that those are newbie problems. The rules for those three
"default implementations" are simple and match what C does for
structs. Use the standard containers, make a habit of forbidding
copying of objects which make no sense copying, and remember the
"explicit" keyword, and you will rarely have problems with this.
(and being able to use
pointers is basically the whole reason for bothering to write anything
in C or C++ in the first place).
Is it? I rarely use pointers in C++ as anything but a kind of
object reference, and mostly because I am forced to.

I use C++ because it is an expressive language with static typing,
which has access to all the hundreds of libraries with a C API on my
(Unix) machine. And because it is fun to use.

I use Python because it is an expressive language with dynamic typing,
which has access to the most important libraries with a C API on my
(Unix) machine. And because it is fun to use.
Code which relies on these default
method implementations is almost certain to be rife with memory leaks
and double-free bugs. So instead of being a convenience, they become a
painfully easy way of writing code that silently does some very, very
wrong things.
I have worked with old code with those kinds of bugs.

It's simple to check and fix. If a class has pointer members of the
Has-A type, the constructors, operator= and destructor have to handle
them (or be suppressed). If they don't, the code is broken.

If you grasp the concept of invariants, it's hard to get wrong. An
object of type Foo has a number of valid states. You have to make sure
there are no ways to create a Foo which is in an invalid state, or
destroying one without cleaning up its state. The best way is usually
to construct it from members which make similar guarantees, e.g. the
standard containers.
Other things like methods (including destructors!) being non-virtual
by default also make C++ code annoyingly easy to get wrong (without it
obviously looking wrong).
The other side of the coin is that you can write tiny classes in C++
with *no overhead*. If my class Foo can be implemented as an integer,
it doesn't need to be slower or take more space than an integer. It
can have value semantics, live on the stack etc, like an integer.

I assume Java programmers avoid such types, and I assume it decreases
type safety in their programs.

Ok, it could have been the other way around so that there was a
"nonvirtual" keyword ... but on the other hand I use inheritance in
C++ about as often as in Python, i.e. almost never.
The whole design of C++ is riddled with premature optimisation of
speed and memory usage in the default settings, instead of choosing
safe defaults and providing concise ways of allowing the programmer to
say "I know optimisation X is safe here, please use it".
"Premature optimization" is a phrase which is always useful as a
weapon, isn't it?

But yeah, I think we can agree about this, at least: when you program
in both Python and C++, it is painfully obvious that C++ never
sacrifices speed or correctness, and it is painfully obvious that the
programmer pays a price for this. Compare ... maybe, for example, the
C++ standard library's very detailed and general iterator and
algorithm concepts with things like Python's str.split and str.join. A
function which takes a list of strings plus a delimiter and returns a
string would be unthinkable in the C++ standard library.
That said, C++ code has one *huge* benefit over ordinary C code, which
is scope-controlled deletion of objects, and the associated Resource-
Acquisition-Is-Initialisation model.
Yes, RAII is one big advantage over any other language I know of.
Compared to good old C, I can come up with many others.

I was going to say something about C++ versus Java here, but the fact
is I haven't written more than a few pages of Java since it came out.
The language (or the culture around it) seems to want to isolate itself
from the rest of the world -- unlike C++ and Python.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se R'lyeh wgah'nagl fhtagn!
Jun 27 '08 #24

P: n/a

Summarizing the discussion (and giving my opinions), here's an
"algorithm" to find out what language you'll leard next:

1. If you just want to learn another language, with no other
essential concern, learn Ruby.
2. If you want to learn another language to design medium to large
size applications, considering market, jobs, etc., and the speed gains
of static byte-compiled languages, learn Java or C#.
3. If you want to learn another language to design applications with
speed gains, but you want that the transition be as smooth as possible
and don't have market concerns (and with the possibility of taking
another easy step later to reach step 2), learn Groovy (for the JMV)
or Boo (for .NET).
4. If you want to develop applications but, for some special reason,
you require native compilation (like speed requirements, embedded
systems, etc.), learn C++
5. If you want to develop system software, or just learn better how
machines work, or understand better low level implementation aspects
of software, learn C.
6. If you just want to speed-up your python programs or offer some
special, system-specific or optimized behavior to your python
applications, or you just want to complement your python knowledge,
learn C.
On Apr 21, 7:26 pm, Jorgen Grahn <grahn+n...@snipabacken.sewrote:
On Mon, 21 Apr 2008 06:14:08 -0700 (PDT), NickC <ncogh...@gmail.comwrote:
On Apr 15, 1:46 pm, Brian Vanderburg II <BrianVanderbu...@aim.com>
wrote:
This will automatically call the constructors of any contained objects
to initialize the string. The implicit assignment operator
automatically performs the assignment of any contained objects.
Destruction is also automatic. When 'p1' goes out of scope, during the
destructor the destructor for all contained objects is called.
Yeah, C++ does try to be helpful, and all of those automatic copy
constructor, assignment operator and destructor implementations screw
up royally when confronted with pointers

I think that those are newbie problems. The rules for those three
"default implementations" are simple and match what C does for
structs. Use the standard containers, make a habit of forbidding
copying of objects which make no sense copying, and remember the
"explicit" keyword, and you will rarely have problems with this.
(and being able to use
pointers is basically the whole reason for bothering to write anything
in C or C++ in the first place).

Is it? I rarely use pointers in C++ as anything but a kind of
object reference, and mostly because I am forced to.

I use C++ because it is an expressive language with static typing,
which has access to all the hundreds of libraries with a C API on my
(Unix) machine. And because it is fun to use.

I use Python because it is an expressive language with dynamic typing,
which has access to the most important libraries with a C API on my
(Unix) machine. And because it is fun to use.
Code which relies on these default
method implementations is almost certain to be rife with memory leaks
and double-free bugs. So instead of being a convenience, they become a
painfully easy way of writing code that silently does some very, very
wrong things.

I have worked with old code with those kinds of bugs.

It's simple to check and fix. If a class has pointer members of the
Has-A type, the constructors, operator= and destructor have to handle
them (or be suppressed). If they don't, the code is broken.

If you grasp the concept of invariants, it's hard to get wrong. An
object of type Foo has a number of valid states. You have to make sure
there are no ways to create a Foo which is in an invalid state, or
destroying one without cleaning up its state. The best way is usually
to construct it from members which make similar guarantees, e.g. the
standard containers.
Other things like methods (including destructors!) being non-virtual
by default also make C++ code annoyingly easy to get wrong (without it
obviously looking wrong).

The other side of the coin is that you can write tiny classes in C++
with *no overhead*. If my class Foo can be implemented as an integer,
it doesn't need to be slower or take more space than an integer. It
can have value semantics, live on the stack etc, like an integer.

I assume Java programmers avoid such types, and I assume it decreases
type safety in their programs.

Ok, it could have been the other way around so that there was a
"nonvirtual" keyword ... but on the other hand I use inheritance in
C++ about as often as in Python, i.e. almost never.
The whole design of C++ is riddled with premature optimisation of
speed and memory usage in the default settings, instead of choosing
safe defaults and providing concise ways of allowing the programmer to
say "I know optimisation X is safe here, please use it".

"Premature optimization" is a phrase which is always useful as a
weapon, isn't it?

But yeah, I think we can agree about this, at least: when you program
in both Python and C++, it is painfully obvious that C++ never
sacrifices speed or correctness, and it is painfully obvious that the
programmer pays a price for this. Compare ... maybe, for example, the
C++ standard library's very detailed and general iterator and
algorithm concepts with things like Python's str.split and str.join. A
function which takes a list of strings plus a delimiter and returns a
string would be unthinkable in the C++ standard library.
That said, C++ code has one *huge* benefit over ordinary C code, which
is scope-controlled deletion of objects, and the associated Resource-
Acquisition-Is-Initialisation model.

Yes, RAII is one big advantage over any other language I know of.
Compared to good old C, I can come up with many others.

I was going to say something about C++ versus Java here, but the fact
is I haven't written more than a few pages of Java since it came out.
The language (or the culture around it) seems to want to isolate itself
from the rest of the world -- unlike C++ and Python.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se R'lyeh wgah'nagl fhtagn!
Jun 27 '08 #25

P: n/a
On Apr 21, 5:26 pm, Jorgen Grahn <grahn+n...@snipabacken.sewrote:
On Mon, 21 Apr 2008 06:14:08 -0700 (PDT), NickC <ncogh...@gmail.comwrote:
On Apr 15, 1:46 pm, Brian Vanderburg II <BrianVanderbu...@aim.com>
wrote:
This will automatically call the constructors of any contained objects
to initialize the string. The implicit assignment operator
automatically performs the assignment of any contained objects.
Destruction is also automatic. When 'p1' goes out of scope, during the
destructor the destructor for all contained objects is called.
Yeah, C++ does try to be helpful, and all of those automatic copy
constructor, assignment operator and destructor implementations screw
up royally when confronted with pointers

I think that those are newbie problems. The rules for those three
"default implementations" are simple and match what C does for
structs. Use the standard containers, make a habit of forbidding
copying of objects which make no sense copying, and remember the
"explicit" keyword, and you will rarely have problems with this.
Yes, but why should you have to remember? Wouldn't it be less error-
prone to make objects uncopyable and constructors explicit unless
stated otherwise? (Yes, default implementations for structs had to
match C, but "class" was a new keyword.)
Other things like methods (including destructors!) being non-virtual
by default also make C++ code annoyingly easy to get wrong (without it
obviously looking wrong).

The other side of the coin is that you can write tiny classes in C++
with *no overhead*. If my class Foo can be implemented as an integer,
it doesn't need to be slower or take more space than an integer. It
can have value semantics, live on the stack etc, like an integer.

I assume Java programmers avoid such types, and I assume it decreases
type safety in their programs.
I haven't written in Java since version 1.3, so maybe things have
changed. But last time I checked, if you want tiny value-semantics
types in Java, you're stuck with the built-in ones. One of my biggest
gripes about that language.
Jun 27 '08 #26

P: n/a
hdante a écrit :
Summarizing the discussion (and giving my opinions), here's an
"algorithm" to find out what language you'll leard next:

1. If you just want to learn another language, with no other
essential concern, learn Ruby.
2. If you want to learn another language to design medium to large
size applications, considering market, jobs, etc., and the speed gains
of static byte-compiled languages, learn Java or C#.
3. If you want to learn another language to design applications with
speed gains, but you want that the transition be as smooth as possible
and don't have market concerns (and with the possibility of taking
another easy step later to reach step 2), learn Groovy (for the JMV)
or Boo (for .NET).
4. If you want to develop applications but, for some special reason,
you require native compilation (like speed requirements, embedded
systems, etc.), learn C++
5. If you want to develop system software, or just learn better how
machines work, or understand better low level implementation aspects
of software, learn C.
6. If you just want to speed-up your python programs or offer some
special, system-specific or optimized behavior to your python
applications, or you just want to complement your python knowledge,
learn C.
And if you really want to actually *learn* something, learn a functional
language.

Jun 27 '08 #27

P: n/a
hdante wrote:
6. If you just want to speed-up your python programs or offer some
special, system-specific or optimized behavior to your python
applications, or you just want to complement your python knowledge,
learn C.
"Learn C", ok, but then go and use Cython instead.

Stefan
Jun 27 '08 #28

P: n/a
Bob Martin wrote:
in 342367 20080414 074410 s0****@gmail.com wrote:
>Hello, I was hoping to get some opinions on a subject. I've been
programming Python for almost two years now. Recently I learned Perl,
but frankly I'm not very comfortable with it. Now I want to move on
two (sic) either Java or C++, but I'm not sure which. Which one do you think
is a softer transition for a Python programmer? Which one do you think
will educate me the best?

C++ is for masochists. Go for Java.
Definitely Java. And I have ten years of C++ experience.

C++ is the only major language that has hiding without safety.
That was a mistake.

Perl is useful because it runs everywhere; you'll be able to run
your Perl program on just about any commercial web hosting service.
Other than that, there's not much good to be said for it.

Java is a generally good language fighting to get out from under
a mountain of mediocre libraries.

John Nagle
Jun 27 '08 #29

P: n/a
On Apr 21, 3:14 pm, NickC <ncogh...@gmail.comwrote:
On Apr 15, 1:46 pm, Brian Vanderburg II <BrianVanderbu...@aim.com>
wrote:
[...]
Yeah, C++ does try to be helpful, and all of those automatic copy
constructor, assignment operator and destructor implementations screw
up royally when confronted with pointers (and being able to use
pointers is basically the whole reason for bothering to write anything
in C or C++ in the first place). Code which relies on these default
method implementations is almost certain to be rife with memory leaks
and double-free bugs. So instead of being a convenience, they become a
painfully easy way of writing code that silently does some very, very
wrong things.
When a class includes a pointer data member, there is no single, right
way to handle it. C++ automatically generated member functions are
defined so as to be consistent in dealing with *values*. Any C++
programmer that hasn't learnt this simple fact, shouldn't be trusted
with any programming language. Python and especially Java will only
make it harder to spot the mess he is making.
Other things like methods (including destructors!) being non-virtual
by default also make C++ code annoyingly easy to get wrong (without it
obviously looking wrong).
I can see how that might be confusing for programmer coming from
Python, but it's more natural for those coming from C.
The whole design of C++ is riddled with premature optimisation of
speed and memory usage in the default settings, instead of choosing
safe defaults and providing concise ways of allowing the programmer to
say "I know optimisation X is safe here, please use it".
I absolutely agree.
And the result? Any serious project in the language has to adopt it's
own techniques for avoiding all those traps, and those techniques are
likely to eliminate any supposed optimisations provided by the choices
of the C++ committee, while filling a code base with boilerplate that
only exists for the purpose of working around defects in the language
design (Scott Meyers has written at length about the worst of these
issues, far more clearly and eloquently than I ever could [1]).
Did you give up on C++ in the early nineties? Things have changed a
lot since then. Many standard/commonly accepted solutions to the
problems you mention can be found in the C++ standard library and in
Boost (http://boost.org). With std::vector and boost::shared_ptr you
can go an extremely long way without giving pointers any special
considerations.

Cheers,
Nicola Musatti
Jun 27 '08 #30

This discussion thread is closed

Replies have been disabled for this discussion.