# Jumping straight into C++ without programming knowledge

by Woopydalan
Tags: jumping, knowledge, programming, straight
 P: 746 Hello, I was looking at an Introduction to C++ class I might be taking next semester Description: This course is an introduction to the basic principles of programming using C++ as the development tool. Topics include the structure and design of algorithms, input/output, branching structures, functions, recursion, built-in data types, arrays, structures, les, pointers and elementary operations on linked structures. The object-oriented programming paradigm will be introduced. Topics include encapsulation, polymorphism, libraries, stream, inheritance and abstract data types. Students will design algorithms, write external and internal documentation and design and write source code in C++. As someone with zero knowledge about any programming language, I was curious if it would be ok to start off with C++ without learning one of the easier languages, or will it be a huge struggle? I was going to try to get a head start this winter break and teach myself how to do stuff using the tutorials on this forum.
 P: 166 No problem starting with C++, I did the same thing. Personally I've found the best ways to learn a language are to modify existing code to do something you want it to do, or to write an actual program you want to write from scratch. I never really learned anything beyond how to transcribe stuff when following along with the example programs for beginners. C# or Java may be easier to learn and develop with, and in the long run may be more marketable as well, if that is a concern.
 P: 2,427 Following the java theme, there's groovy a scripting language that is relatively easy to use and that is a superset of java and even interoperates with java quite well. You can start out just writing scripts and then progress into full object oriented classes and programs. Similarly there is Scala, arguably known as a better Java than Java with many advanced programming features that is pushing the new edge of language design. As an aside: C++ is more difficult than java when you get into pointers and memory allocation issues. The base language C was one of my favorite languages but you can easily shoot yourself in the foot and even cause your machine to crash (PC DOS). C++ uses multiple inheritance which has some issues whereas Java uses a single inheritance model with interfaces that is easier to understand and use with less side-effects. In any event whatever language you choose, you should invest some time in learning how to use Eclipse or Netbeans. I use Netbeans primarily because it has all the plugins I tend to use as part of the loaded distribution (plugins for Java and C++ development). Eclipse is also a great choice although you may have to scout around and install some of the more arcane plugins. Lastly, there's BlueJ which is a kind of Eclipse for beginning programmers with just enough features to write java applications.
P: 166

## Jumping straight into C++ without programming knowledge

 Quote by jedishrfu C++ is more difficult than java when you get into pointers and memory allocation issues. The base language C was one of my favorite languages but you can easily shoot yourself in the foot and even cause your machine to crash (PC DOS).
To be clear if you stick to C++ you don't really have these problems. When you start mixing C and C++, usually when writing C++ with a C background, you do. There are a lot of things in C++ that are really a pain to use compared to other languages, but if you're coming from a clean background, I think you'll pick it up faster since you don't know what you're missing. ;)

That said I think learning C is great too. If you don't understand some of the things the compiler is doing for you, when it starts behaving weirdly you may never understand why.
 P: 746 So to start should I just read the tutorials on the top of the forum page? The most programming I did was to have ''Hello World'' typed in the black box
Mentor
P: 20,433
 Quote by jedishrfu C++ is more difficult than java when you get into pointers and memory allocation issues. The base language C was one of my favorite languages but you can easily shoot yourself in the foot and even cause your machine to crash (PC DOS).
 Quote by justsomeguy To be clear if you stick to C++ you don't really have these problems.
I disagree. The problems that jedishrfu described don't come about because of mixing C++ with C - they can appear if you are using pointers incorrectly or are allocating heap memory on the heap that you forget to deallocate when you're done.

If you do very simple programs, then you might not run into these problems, although pointer problems can crop up when you use C standard library I/O. Many of the functions, such as scanf and its variants, can offer some surprises to those who don't understand pointers.
 Quote by jedishrfu When you start mixing C and C++, usually when writing C++ with a C background, you do. There are a lot of things in C++ that are really a pain to use compared to other languages, but if you're coming from a clean background, I think you'll pick it up faster since you don't know what you're missing. ;) That said I think learning C is great too. If you don't understand some of the things the compiler is doing for you, when it starts behaving weirdly you may never understand why.
 P: 746 I noticed the tutorial guides on this page were written back in 2004...is it the case in the world of programming that the stuff that is presented in there is out of date and using other programs in lieu of what they suggest, etc?
P: 166
 Quote by Mark44 I disagree. The problems that jedishrfu described don't come about because of mixing C++ with C - they can appear if you are using pointers incorrectly or are allocating heap memory on the heap that you forget to deallocate when you're done. If you do very simple programs, then you might not run into these problems, although pointer problems can crop up when you use C standard library I/O. Many of the functions, such as scanf and its variants, can offer some surprises to those who don't understand pointers.
You can get by very well coding in C++ without ever touching a pointer or using any stdlib I/O from C is my point. In C++ you don't use scanf, you use the stream operators and related functions. e.g. this:
int n;

scanf("%d", &n):
becomes
int n;
cin >> n;
You rarely have to touch pointers or any of the C standard library when writing pure c++.
 P: 2,427 Real world C++ programs do use pointers and dynamic memory allocation as a fundamental part of their operation whereas in Java you are protected from these issues at the cost of Java garbage collection sometimes interfering with program flow. You can't always get away with avoiding pointers in C++. Another problem with C++ arises from multiple inheritance where say two classes A and B inherit from a third class C the variable x. Now in your program you need to write a new class D that inherits from A and B so when you refer to x which x do you get the D.B.A.x or the D.C.A.x they are both distinct and different. This situation doesn't arise in Java. Don't get me wrong both languages are widely used and programmers need to know both but in general Java is a safer language to use. Its just harder to shoot yourself in the foot with it but I've found ways of doing that.
Mentor
P: 14,243
 Quote by jedishrfu Real world C++ programs do use pointers and dynamic memory allocation as a fundamental part of their operation whereas in Java you are protected from these issues at the cost of Java garbage collection sometimes interfering with program flow. You can't always get away with avoiding pointers in C++. Another problem with C++ arises from multiple inheritance where say two classes A and B inherit from a third class C the variable x. Now in your program you need to write a new class D that inherits from A and B so when you refer to x which x do you get the D.B.A.x or the D.C.A.x they are both distinct and different. This situation doesn't arise in Java. Don't get me wrong both languages are widely used and programmers need to know both but in general Java is a safer language to use. Its just harder to shoot yourself in the foot with it but I've found ways of doing that.
Would you please stop trying to turn this thread into yet another one of those computer languages religious war threads?

Regarding your comments, you are wrong. You can write modern C++ in which the C++ keyword delete is verboten; you have to get a waiver from the powers that be to use it. The C++ standard library provides a number of tools that go a long way toward eliminating the need for delete. With regard to multiple inheritance, there's no problem with multiple inheritance if you don't use it. There's nothing in the language that forces to use multiple inheritance. When you do use it, there are ways to solve the dreaded diamond pattern. Virtual inheritance, for instance. Multiple inheritance is a very useful capability when you need it. Java doesn't have it. IMO, that's a flaw, not a feature.

Back on topic, there's nothing wrong with using C++ as the basis for an introductory computer science class. The goal of any introduction to programming is to teach students how to program. Many of those key concepts are common to C, Fortran, Java, C++, and a host of other languages. Simple I/O. Primitive types. Variables. Looping and conditional statements. Functions. Simple computer science structures such as linked lists. What C++ (and Java and C#) add to the basic procedural oriented programming paradigm is the object oriented programming paradigm. Just touching on that will take a good deal of time. There is no reason to go into multiple inheritance in an introductory class. Or templates, or metaprogramming, or functors, for that matter. An introductory programming class that uses C++ should not cover everything the language has to offer.
 P: 2,427 Sorry, I was responding to an earlier comment about C++ and intended to stop at this juncture. I use these and several other languages on a daily basis for quite a long time and so have some familiarity with them and wanted to set the record straight. If someone asked me to choose I would say Java is better for OO introductory courses.
P: 166
 Quote by jedishrfu Real world C++ programs do use pointers and dynamic memory allocation as a fundamental part of their operation
 Quote by jedishrfu I use these and several other languages on a daily basis for quite a long time and so have some familiarity with them and wanted to set the record straight.
I'm not saying that you *can't* use them, but that you do not have to, not even in "real world" programs. I can't think of a case off the top of my head where your only choice in some situation in C++ is to use a explicit pointer, beyond truisms like calling a stdlib function that requires a pointer, or otherwise hooking into C code. Often times it's easier to use pointers, especially for people coming from a C background, but you can certainly write useful programs in C++ completely devoid of any explicit pointers.

Note I'm not talking about references here, which people often conflate with pointers. The difference can be subtle but is not unimportant, especially in the context of a beginning programmer.
 P: 746 ok, well can I use the tutorials on this forum or are they out of date? You guys are arguing over something I don't even understand
P: 218
 Quote by justsomeguy I'm not saying that you *can't* use them, but that you do not have to, not even in "real world" programs. I can't think of a case off the top of my head where your only choice in some situation in C++ is to use a explicit pointer, beyond truisms like calling a stdlib function that requires a pointer, or otherwise hooking into C code. Often times it's easier to use pointers, especially for people coming from a C background, but you can certainly write useful programs in C++ completely devoid of any explicit pointers. Note I'm not talking about references here, which people often conflate with pointers. The difference can be subtle but is not unimportant, especially in the context of a beginning programmer.
Just out of interest, what do you do when you need to allocate an object on the heap?
P: 166
 Quote by coalquay404 Just out of interest, what do you do when you need to allocate an object on the heap?
Call the constructor for the class. I'm not sure if you're trying to ask something more specific.
P: 166
 Quote by Woopydalan ok, well can I use the tutorials on this forum or are they out of date? You guys are arguing over something I don't even understand
We're done arguing. :)

You can use the tutorials. Language tutorials don't really have a shelf life, as long as the links still work that is.
P: 218
 Quote by justsomeguy Call the constructor for the class. I'm not sure if you're trying to ask something more specific.
I'm asking how you handle creation of objects at runtime without using pointers.
P: 166
 Quote by coalquay404 I'm asking how you handle creation of objects at runtime without using pointers.
Heap objects are instantiated automatically for you by declaration so you don't have to get a pointer to one and then call new, you can just start using it, e.g.

int main()
{
CSomething foo;
foo.dostuff();
return 0;
}

And of course you can pass in parameters to the constructor.
int main()
{
CSomething foo(1,2,3,4);
foo.dostuff();
return 0;
}
This last bit is called RAII is a central concept in C++, though due to its roots in C, you're free to circumvent it at any time by using a pointer and calling new().

 Related Discussions Calculus & Beyond Homework 1 Programming & Computer Science 9 General Math 24 General Math 2 Differential Geometry 5