Any tips?

E

eli m

I am coming to C++ from python. Do you guys have any tips for me? Examples: How to learn it effectively, what not to do, etc.
 
I

Ian Collins

eli said:
I am coming to C++ from python. Do you guys have any tips for me?
Examples: How to learn it effectively, what not to do, etc.

Don't use trial and error!

Find a decent book, there have been several recent threads covering
recommendation here.

Posting here with problems is fine.

Do try and clean up the mess that appalling google interface makes of
your posts and quotes!

See http://www.netmeister.org/news/learn2quote.html
 
S

Saeed Amrollahi

I am coming to C++ from python. Do you guys have any tips for me? Examples: How to learn it effectively, what not to do, etc.

Hi
1. At first you should understand the common property
between C++ and Python is both are programming languages, period.
They are so different with each other with different idioms/styles.
While Python is dynamic programming language, C++ is type-safe static language.
Static type checking, type safety and increasing relay on compiler are among
major characteristics of C++
2. You should never learn "Modern" C++ with a book that was written before
1997. My recommendations:
1) Andrew Koenig & Barbara Moo. Accelerated C++, Addison-Wesley, 2000.
2) Bjarne Stroustrup. Programming: Principles and Practice in C++,
Addison-Wesley, 2009.
3) Bjarne Stroustrup. The C++ Programming Language, Addison-Wesley,
2013. (Coming soon)
4) Stanley Lippman, Josee Lajoie & Barbara Moo. C++ Primer, 2012.
5) Bjarne Stroustrup. The C++ Programming Language, Addison-Wesley,
special edition, 2000.
At this time, the point is: use C++98 or C++11, the books
1, 2 and 5 are based on C++98 and 3 and 4 based on C++11.
of course there other good books. I believe the book #1 and #2
are really good. #1 is concise and #2 is very detailed about
programming not C++.
3. If you would like use C++ effectively as you mentioned
you have to use C++ as C++, not as "C with some stuffs".
In Modern C++, you should use standard library at first
place: use string rather than C-style char. string, use vector
and array (C++11) rather than C-Style arrays and a lot of
generic algorithms in STL part of C++ standard library.
4. Use modern C++ programming environment.
My recommendation:
- Visual Studio 2012, Visual Studio 2010 (Windows)
- Code::Blocks (Linux/Ubuntu)
5. There are plenty of resources about C++ on Net, but
honestly just a small fraction of them is really good.
My recommendations:
- http://www.parashift.com/c++-faq
- http://www.isocpp.org/
- http://www.stroustrup.com
- The Videos on Microsoft Channel 9
by Stephan T. Lavavej about C++ standard library
Don't forget the comp.lang.c++ and Stack Overflow
(http://stackoverflow.com) are good places to ask question.
Welcome to C++ community with 3,500,000+ members.

Regards,
-- Saeed Amrollahi Boyouki
 
Ö

Öö Tiib

I am coming to C++ from python. Do you guys have any tips for me?

I can give some such tips just to get into feeling. ;)

0) Skim C++ FAQ first and return to it now and then. It is over 20 years
old FAQ, actively updated and most interesting things about C++ are
mentioned in it. http://www.parashift.com/c++-faq/
Do not take it as holy bible. The answers it gives are most popular
for a practical reasons.

1) Learning C++ by trial and error is impossible. Reasons:
* C++ syntax is designed to be laconic. Random row of ASCII characters
does not compile, but getting it to compile with tiny changes is
possible.
* Lot of C++ code that compiles without any compiling errors is illegal
but compiler messages are not required from implementation.
* Lot of C++ code that runs is not defined what it should do but it may
sometimes look that it does exactly what you expect it to do.
* Above is true about usage of standard C++ library as well. It is
library that sometimes has documented that something is undefined but
sometimes the docs just do not say what happens in certain situations.

2) There are only few books that the masters of C++ accept as good. Take
the code examples in those as illustration of particular feature the
paragraph describes. Nothing else. Illustrations are often not meant
to work in real product.

3) Debugging C++ program without special tools is very hard. As one of the
first things learn to use tools that help you to debug the programs you
write.

4) When you write program then do not take over the "undefined" nature of
C++ and its library. Try to write programs where everything what
happens is defined by using only the constructs of C++ that have
defined behavior.

5) Do not expect to learn C++ quickly. If you are bright guy then you will
feel yourself familiar with it in 6 months. Some never learn it despite
they try.

6) Do not hope that C++ code you see in some place of internet is good.
On the contrary, it is usually bad or even terrible.

7) Do not hope that C++ code you may see in C++ library implementation is
good.
* It may contain obscure and illegal constructs that do not work even on
next version of same compiler.
* It will contain names reserved for usage internally in implementations.
* It may contain undefined behaviors that standard allows it to contain.
* It is designed to be efficient on particular compiler and not readable.
 
J

Jorgen Grahn

I am coming to C++ from python. Do you guys have any tips [...] ?

Hi
1. At first you should understand the common property
between C++ and Python is both are programming languages, period.

Yes! Python is a nice language, but knowing it doesn't help you write
C++ code. (Also, trying to write Python in C++ is a bad idea.)

/Jorgen
 
J

James Kanze

I am coming to C++ from python. Do you guys have any tips
for me? Examples: How to learn it effectively, what not to
do, etc.
[...]
2. You should never learn "Modern" C++ with a book that was written before
1997. My recommendations:
1) Andrew Koenig & Barbara Moo. Accelerated C++, Addison-Wesley, 2000.
2) Bjarne Stroustrup. Programming: Principles and Practice in C++,
Addison-Wesley, 2009.
3) Bjarne Stroustrup. The C++ Programming Language, Addison-Wesley,
2013. (Coming soon)
4) Stanley Lippman, Josee Lajoie & Barbara Moo. C++ Primer, 2012.
5) Bjarne Stroustrup. The C++ Programming Language, Addison-Wesley,
special edition, 2000.
At this time, the point is: use C++98 or C++11, the books
1, 2 and 5 are based on C++98 and 3 and 4 based on C++11.
of course there other good books. I believe the book #1 and #2
are really good. #1 is concise and #2 is very detailed about
programming not C++.

The choice between 1 and 2 will depend partially on how much
experience you have programming, in general. If you know no
programming, I would recommend 2, regardless of what language
you ultimately want to program in, because that's what it
teaches. If you're already an experienced programmer, 1 is
a lot shorter, and will still present everything you need to
know that isn't general programming skills.

[...]
4. Use modern C++ programming environment.
My recommendation:
- Visual Studio 2012, Visual Studio 2010 (Windows)
- Code::Blocks (Linux/Ubuntu)

I don't know. I use Visual Studios 2012 (at present) under
Windows, because that's my employers standard; I've always used
vim, bash and makefiles under Unix. And the vim, bash and
makefiles environment is far more productive than the Visual
Studios environment. If you're just starting programming,
something like Visual Studios is probably a pretty good idea, so
you don't have to learn everything at once, just to compile
hello world. But if you are already an experienced programmer,
it's probably worth your while to learn how to use more powerful
tools; there's just so much you can't do in Visual Studios (or
in any of the IDE's I've used under Linux, but I've not tried
any new ones recently).
 
J

James Kanze

No pun intended, but there's actually a book called "Effetive C++",
which is actually quite good. It's not a total beginner's book, as it
assumes that you have at least some knowledge of C++ already, but I would
say that you can actually learn quite a lot on-the-fly while reading the
book and finding out what it's talking about. Probably better than by
reading some beginner's book. (What makes this a better way of learning,
IMO, is that it goes right to the good stuff, rather than spending
hundreds of pages on trivialities and teaching bad habits, like most
beginners' books do.)

That's "Effective C++", by Scott Meyers, and it depends on what
beginners book, but I would suggest the more recent Stroustrup
or the Koenig and Moo first. But I don't think you should
consider yourself qualified to actually develop applications in
C++ until you've also mastered "Effective C++".
 
B

Balog Pal

I don't know. I use Visual Studios 2012 (at present) under
Windows, because that's my employers standard; I've always used
vim, bash and makefiles under Unix. And the vim, bash and
makefiles environment is far more productive than the Visual
Studios environment.

Could you elaborate please? What makes the listed things more
productive? (Or did you meant it for yourself only based on familiar
ground, not in general?)
But if you are already an experienced programmer,
it's probably worth your while to learn how to use more powerful
tools; there's just so much you can't do in Visual Studios (or
in any of the IDE's

Like what?
 
J

Jorgen Grahn

Could you elaborate please? What makes the listed things more
productive? (Or did you meant it for yourself only based on familiar
ground, not in general?)

Hopefully he did, or I'd have to start an Emacs-vs-Vim war ;-)

Unix versus (other) IDEs has been discussed continuously for as long
as I can remember, and it never leads anywhere. It's near impossible
to find someone who knows both worlds well enough to have a useful
general opinion, and if such a person exists she can't prove it to us.

Personally: my workflow combined with a decent Unix environment
doesn't feel limiting. And I don't think it's because my brain is
wired in an unusual way. Can I switch to an IDE and change my
workflow to become even /less/ limited? No idea; it would take years
to find out, and I'm not prepared to make that huge investment with
an uncertain outcome.

Also, I've never seen anyone do anything with an IDE that I couldn't
do as well or better. (That's not proof, because most people seem not
to use their tools efficiently at all, no matter what the tools are.)

/Jorgen
 
I

Ian Collins

Juha said:
One thing about Unix, especially modern Linux distros, is that it has
been kind of designed for development, unlike Windows, which has been
designed as a graphical user interface, with little regard to anything
else.

That comment shouldn't be specific to Linux, most modern UNIX systems
are equally, if not more, developer friendly.
 
I

Ian Collins

Jorgen said:
Hopefully he did, or I'd have to start an Emacs-vs-Vim war ;-)

Unix versus (other) IDEs has been discussed continuously for as long
as I can remember, and it never leads anywhere. It's near impossible
to find someone who knows both worlds well enough to have a useful
general opinion, and if such a person exists she can't prove it to us.

Personally: my workflow combined with a decent Unix environment
doesn't feel limiting. And I don't think it's because my brain is
wired in an unusual way. Can I switch to an IDE and change my
workflow to become even /less/ limited? No idea; it would take years
to find out, and I'm not prepared to make that huge investment with
an uncertain outcome.

Also, I've never seen anyone do anything with an IDE that I couldn't
do as well or better. (That's not proof, because most people seem not
to use their tools efficiently at all, no matter what the tools are.)

As I've posted elsewhere, over the past 30+ years I've used everything
from teletypes to the modern crop of cross-platform IDEs and these days
I do most of my work in NetBeans.

Why? Because it integrates well with the other tools I use and supports
all of my programming languages. It also has built in support for the
C, C++ and PHP unit test frameworks I use. I've even started to like
the background compilation feature, which saves on wasted build time.

If someone sat me down at any of my past setups, I'd still be productive
(well maybe not too productive on the 110baud teletype!), just not as
productive as I am now.
 
J

Jorgen Grahn

Juha Nieminen wrote: ....

That comment shouldn't be specific to Linux, most modern UNIX systems
are equally, if not more, developer friendly.

Apart from the *BSDs, not in the sense that JN meant. Are there
really any left, anyway?

/Jorgen
 
I

Ian Collins

Jorgen said:
Apart from the *BSDs, not in the sense that JN meant. Are there
really any left, anyway?

In my opinion Solaris (and the numerous OpenSolaris derivatives) have
better developer tools than Linux, especially for analysing applications
(and the OS) in a production0n environment.
 
B

Balog Pal

Unix versus (other) IDEs has been discussed continuously for as long
as I can remember, and it never leads anywhere.

I don't agree with that -- I was in several such discussions and learnt
about a plenty of tools and methods I overlooked or was too skeptic to
try harder. Guess I'm not alone with that.

Also I saw many false claims shot down.
It's near impossible
to find someone who knows both worlds well enough to have a useful
general opinion, and if such a person exists she can't prove it to us.

The point is IMO not switching environment right ahead (that is normally
hindered by many factors) bu to converge to a more productive work in
time. (I.e currently I work on windows again, but last times I worked on
linux I always looked around to find some productive environment - just
to get disappointed again and again. Maybe the next time I'm there it
will change due to people answer my questions. ;)
Personally: my workflow combined with a decent Unix environment
doesn't feel limiting. And I don't think it's because my brain is
wired in an unusual way. Can I switch to an IDE and change my
workflow to become even /less/ limited? No idea; it would take years
to find out, and I'm not prepared to make that huge investment with
an uncertain outcome.

I don't get this -- just because I launched an IDE or a multiwindow
smart text editor never stoppped me to run a few terminals, command
lines, tools, whatever if I needed them. I do prefer them being
integrated, but if the integration is handicapped I rather use the
external thing. Or go out for advanced tasks. (As an example: we have a
Git Provider plugin that integrates into VS and is in theory great:
shows status on the solution tree, pending differences with source code
navigation, even an interface channel to access GE and tortoise. But in
practice it uses an old and bad access engine to git (at least it was
the case a year ago) that slows down everything having a big project;
also hashas a tendency to lock git stuff from other tools. So I rather
uninstalled it and just use gitk and git gui in other windows, and
launch GitExtenions time to time, while also run git commands from FAR
manager, and even have a python tool that autmates refreshing the
satellite repos.) If the issue will be fixed eventually, or another
integration emerges, I'll add it to the mix and use less of the
externals, the least used dropping out naturally.
Also, I've never seen anyone do anything with an IDE that I couldn't
do as well or better.

IDE is not supposed to be a silver bullet, but to save time wasted on
switching tools and views. I just HATE to see some piece of info on the
screen ad being forced to select, copy, paste it to some other place,
enriched with some commands instead of being able to just do it on spot.
And in work I have a ton of such activity.
(That's not proof, because most people seem not
to use their tools efficiently at all, no matter what the tools are.)

Yeah, Iwas pretty shocked to observe that with all those supposedly
excellent unix-based tools my colleagues (who were linux guru level)
could not do as much as walking a list of compiler errors with F4 --
instead had to do actions to open the related sources and navigate to
lines. :-((( I thought we left that behind in last century.

And guess we agree that being one pretty frequent activity.
 
J

Jorgen Grahn

On 3/7/2013 9:10 AM, Jorgen Grahn wrote: ....

IDE is not supposed to be a silver bullet, but to save time wasted on
switching tools and views.

The above was just a statement about what I've seen -- not
a statement about what IDEs are good for.
I just HATE to see some piece of info on the
screen ad being forced to select, copy, paste it to some other place,
enriched with some commands instead of being able to just do it on spot.
And in work I have a ton of such activity.

The counter-argument: when I do stuff in a shell I can use any tools I
want, not just the ones the IDE maker thought of. And I can write my
own. I also use the shell history and its search functions (e.g.
Ctrl-R in bash) a lot, so I never have to type the same thing twice.
Yeah, Iwas pretty shocked to observe that with all those supposedly
excellent unix-based tools my colleagues (who were linux guru level)
could not do as much as walking a list of compiler errors with F4 --
instead had to do actions to open the related sources and navigate to
lines. :-((( I thought we left that behind in last century.

Linux "gurus" know that Emacs does this by default. Either they
felt this was unimportant to them, or they were just wannabes.

To me, that shows how hard it is to discuss this. You are shocked by
that, but I on the other hand don't feel a need for such a tool. I
just look at the first few errors, or the one I know is the core one,
and recompile[1].

You can't look at the tool without taking the /workflow/ into account.

/Jorgen

[1] Compilation must be fast, correct and free from noise for this to
work.
 
B

Balog Pal

The above was just a statement about what I've seen -- not
a statement about what IDEs are good for.


The counter-argument: when I do stuff in a shell I can use any tools I
want, not just the ones the IDE maker thought of. And I can write my
own.

Err, I honestly don't see any difference here if we consider IDEs from
real life. I'm not aware of a single one without capability to launch
external commands, record macros, write programs in a full-potential
language with access to anything your OS+ provides, and even if that is
not enough provide extensibility API so you can write your thing "the
provider didn't think about as a plugin. (Or better yet use the plugin
the other guy wrote to cover that topic. ;-)
I also use the shell history and its search functions (e.g.
Ctrl-R in bash) a lot, so I never have to type the same thing twice.

Keeping history of anything is probably the first thing any IDE (or GUI
program) learned.

And as I already said, nothing forbids to have a bash running to
supplement the IDE. While the other way around does not work.
Linux "gurus" know that Emacs does this by default. Either they
felt this was unimportant to them, or they were just wannabes.

I saw only a single guy using Emacs and only part-time. The others were
certainly aware of it and that feature.

OTOH, Emacs, integrated with build system this way is a manifestation of
IDE, so arguments for its usability plays for that team in the
IDE/just-editor matches. :)
To me, that shows how hard it is to discuss this. You are shocked by
that, but I on the other hand don't feel a need for such a tool. I
just look at the first few errors, or the one I know is the core one,
and recompile[1].

I several times considered to use a stopper to measure time wasted this
way. Didn't do it for laziness and thinking social issues. But I read
some cool articles with similar measurements -- that revealed
interesting things. Among them that some activities are completely
missing from people's "subjective" time, and typing commands normally
play there. IOW the waste is well observable from outside only.
You can't look at the tool without taking the /workflow/ into account.

[1] Compilation must be fast, correct and free from noise for this to
work.

It probably fits some workflow when you concentrate on a few-line
change. I'm currently reshaping an old codebase that's over 1MLOC in
size. Would be dead in the water if could not navigate error or search
locations at once anywhere in the ~3300 files.

But even at the smallest scale I never got the idea what is good to type
(or even fetch from history) a filename in the project to open it manually.
 
J

Jorgen Grahn

On Fri, 2013-03-08, Balog Pal wrote: ....
To me, that shows how hard it is to discuss this. You are shocked by
that, but I on the other hand don't feel a need for such a tool. I
just look at the first few errors, or the one I know is the core one,
and recompile[1].
....
It probably fits some workflow when you concentrate on a few-line
change. I'm currently reshaping an old codebase that's over 1MLOC in
size. Would be dead in the water if could not navigate error

I do these tasks too, and I can assure you am not dead in the water!
or search
locations at once anywhere in the ~3300 files.

Did I say I couldn't do that? I don't use IDEs, but I don't write my
code in Notepad, either! This is a vital feature.
But even at the smallest scale I never got the idea what is good to type
(or even fetch from history) a filename in the project to open it manually.

Ok, back to my original comment about the futility of these discussions.
You don't trust me, and I don't trust you. Neither of us is going to
change.

/Jorgen
 
B

Balog Pal

Switching views in a non-IDE is Alt-Tab or equivalent, but I have not yet
found convenient ways to switch views inside an IDE without reaching to
the mouse.

In VS you can bind any key to any command -- built-in or written by you.
Can be even dependent on what kind of document you're in. I'm not sure
if you can re-bind system-wide stuff like alt-tab, I never wanted, as it
is there to switch to outside windows. (I recall how annoying it was
when I worked with virtual machines and alt-tab switched windows inside
the VM when I wanted the next natural desktop window :)
The history of debug launch commands with different command-line
arguments is still missing in my primary IDE

Indeed, though if you have a just a number of variants, in VS you can
add projects that has no content just the debug setting. Then can launch
any easily. Probably it can be covered by a macro too. I have only a few
variants so never bothered with better way.
, after 10+ years. I have
resorted to starting the program from the bash command-line, then
attaching the debugger, but this is cumbersome as well.

From command line you can launch gdb or ddd providing the full command
line for the of the program, so it should not be really more hassle.
+1 for that, having multiple CygWin bash shells running all the time. But
I would not be so sure which one is primary and which is supplement.

Shouldn't matter -- the point is to have everything at fingertip so
activity is used on new work rather than retype incantations or info the
system really knows.
Ironically, this is the only reason I launch our chosen Linux IDE
(CodeBlocks, and I did not choose it) - the only thing which it is good
at is navigating to errors (editing sucks, debugging does not work at
all, compile without attempted recompile of earlier dependencies not
possible, find-in-project-files missing, recently edited windows list
missing (i.e. Alt-W-2 not working), etc.), so the only use is actually to
fix some random compilation errors time after time (usually caused by so-
called "MS language extensions" compiling fine on Windows and failing on
Linux).

A few years ago someone suggested CB, I dropped it after very little try
as hopeless. Too bad, as it looks like something used up much
development time, so could be useful.

I recall my early years -- Borland C++ 3.1 IDE just rocked. Had
practically everything I could imagined at the time, and so many
successors were much bigger but didn't come even close.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top