Jumping straight into C++ without programming knowledge

In summary, the conversation discusses the possibility of learning C++ as a first programming language and the potential struggles that may come with it. It also mentions the advantages of using other languages like Java or C# and suggests using programs like Eclipse or Netbeans for development. There is also a brief discussion on the differences between C++ and C and the potential issues with pointers and memory allocation. Finally, there is a question about the relevance and accuracy of tutorial guides from 2004.
  • #1
member 392791
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.
 
Technology news on Phys.org
  • #2
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.
 
  • #3
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.
 
  • #4
jedishrfu said:
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.
 
  • #5
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
 
  • #6
jedishrfu said:
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).

justsomeguy said:
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.
jedishrfu said:
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.
 
  • #7
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?
 
  • #8
Mark44 said:
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:
Code:
int n;

scanf("%d", &n):

becomes
Code:
int n;
cin >> n;

You rarely have to touch pointers or any of the C standard library when writing pure c++.
 
  • #9
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.
 
  • #10
jedishrfu said:
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.
 
  • #11
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.
 
  • #12
jedishrfu said:
Real world C++ programs do use pointers and dynamic memory allocation as a fundamental part of their operation

jedishrfu said:
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.
 
  • #13
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
 
  • #14
justsomeguy said:
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?
 
  • #15
coalquay404 said:
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.
 
  • #16
Woopydalan said:
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. Langauge tutorials don't really have a shelf life, as long as the links still work that is.
 
  • #17
justsomeguy said:
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.
 
  • #18
coalquay404 said:
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.

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


And of course you can pass in parameters to the constructor.
Code:
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().
 
  • #19
The real issue here is not the language (C++) but instead the class itself and the progression from the simplest of programs to more complex ones as students progress through the class, and how well the instructor and the textbooks explain what is going on (how these programs work).

One issue is some students will want to know how a computer actually works internally, rather than just accept how everything works from a language (like C++) perspective. Those students may later decide to learn the basics of assembly programming, but I don't think this requires taking a full semester class on assembly programming unless there's really an interest in this (and if the school even offers such a class).
 
  • #20
justsomeguy said:
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.

Code:
int main()
{
  CSomething foo;
  foo.dostuff();
  return 0;
}
You meant the stack, not the heap. The stack is used for passing parameters, returning results, and for local variables. The heap is used for memory that is allocated dynamically (new/delete in C++, malloc/free in C).

Strictly speaking, there is no stack or heap in C++, or in C for that matter. The stack and heap are how many, but not all, operating systems model memory.

C and C++ have three types of storage:
  • Automatic storage. Your CSomething foo is an automatic variable. In most systems, these live on the stack.
  • Dynamic storage. Objects allocated with new and deallocated with delete have dynamic storage. In most systems, these dynamic objects live on the heap.
  • Static storage. Objects defined at file scope, static class members, and static local variables have static scope. The memory for these objects is created by the compiler; it's part of the executable. Non-primitive static objects (instances of some class or union) are constructed before main starts and destructed after main finishes.

This last bit is called RAII is a central concept in C++
RAII is a very important concept. The acronym stands for the rather meaningless "resource allocation is initialization." Put simply, it means "Put away your toys. All of them." Allocated memory is but one of many resources that need to be "put away". Connections to I/O devices, connections to other computers, other processes also need to be "put away" when the thing that created those connections is done playing with them.

The RAII concept addresses all resources, not just allocated memory. A class that allocates resources for an instance of that class should ensure that those resources are properly "put away" when that class instance goes out of scope. This places a heavier development burden on the author of a class but significant reduces the burden on a user of that class. RAII goes a long ways to solving the memory leak problem, along with a host of other resource-related problems as well.
 
  • #21
You're right of course D_H, my flub on heap/stack. I was trying to not get too deep into just what RAII means in order to answer the question.
 
  • #22
D H said:
Strictly speaking, there is no stack or heap in C++, or in C for that matter. The stack and heap are how many, but not all, operating systems model memory.
What about _alloca() (dynamic allocation from stack, that is freed when a function returns to higher level)?

I'm wondering if we're getting off topic from the original post which was asking if an introduction to programming class using C++ is a good idea. I think once the student gets into this class, either these aspects of programming will be explained, or the OP can ask questions here.
 
  • #23
rcgldr said:
What about _alloca() (dynamic allocation from stack, that is freed when a function returns to higher level)?
alloca is a non-standard function. It is not part of the C or C++ standard. It's not POSIX, While it is available on many machines, several discourage its use.

There is zero need for alloca in C++. Use std::auto_ptr (C++03), boost::scoped_ptr (Boost), or std::unique_ptr (C++11) instead.


I'm wondering if we're getting off topic from the original post which was asking if an introduction to programming class using C++ is a good idea. I think once the student gets into this class, either these aspects of programming will be explained, or the OP can ask questions here.
Perhaps. The original question was answered quite readily (no problem), then we got dragged into the inevitable language holy wars, and now we're getting down in the technical weeds.
 
  • #24
For my part, I did not mean to start a 'holy war'. I use a lot of languages for different purposes, there aren't many I don't like or can't find a good use for from time to time. I just intended that you can (and people often do) write useful C++ code without ever touching an implicit pointer. I don't think that pointers are "bad" by any stretch of the imagination or even that you shouldn't use them in C++ when they are the best option, just that you don't ever really *need* to.
 
  • #25
To get back to the OP's question, the key thing is the structure of the course, not the language it uses.

What you should be learning on a first course IMO is programming. To do any practical work, you have to use some computer language, but it doesn't really matter what language it is.

On the other hand, a lot of books, courses, and web tutorials don't teach programming, they teach a programming language. That's fine if you already know how to program and just need to learn another language, but it's a bad way to start.
 
  • #26
Learning C++ is not that bad IMO.

If you understand the state and flow-control in any language (I know I harp on about these two things in many posts), then no matter if its a web-platform, a mobile platform, a normal PC platform, a micro-controller or embedded system, or anything else, then you'll pick up everything you need to know quickly.

Just learn the flow-control and how the language implements that as well as how the language and the code changes the state-space, how its accessed, and issues regarding its access and you'll be good to go.
 
  • #27
If you go this route, play special attention to the lessons on pointers and memory management, linked lists, structures and the like. You'll sink or swim by whether you learn these topics thoroughly. I almost want to say that a lot depends on the quality of the teacher or textbook. Expect to do a lot of work to learn these foundational topics, but if you do learn them, all other programming later should be easier.
 

What is C++ and can I learn it without any prior programming knowledge?

C++ is a high-level, general-purpose programming language that is widely used in various industries, including software development, game development, and scientific research. While it is possible to learn C++ without any prior programming knowledge, it may be more challenging and require more time and effort.

Is C++ a difficult programming language to learn?

C++ can be a challenging language to learn, especially for beginners without any prior programming experience. It has a steep learning curve and requires a strong understanding of programming concepts like data types, functions, and control structures.

Do I need to have a strong mathematical background to learn C++?

While a strong mathematical background can be helpful in understanding certain concepts in C++, it is not a requirement to learn the language. C++ is a versatile language that can be used for a wide range of applications, so having a strong mathematical background is not necessary.

What resources are available for learning C++ without any prior programming knowledge?

There are many resources available for learning C++ without any prior programming knowledge, such as online tutorials, books, and courses. It is important to choose a resource that suits your learning style and pace and to practice regularly to become proficient in the language.

What are some potential challenges I may face when jumping straight into C++ without any programming knowledge?

Some potential challenges you may face when learning C++ without any programming knowledge include understanding complex syntax, grasping fundamental programming concepts, and debugging errors. It is important to be patient and persistent and to seek help from more experienced programmers when needed.

Similar threads

  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
2
Replies
69
Views
4K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
21
Views
1K
  • Programming and Computer Science
Replies
5
Views
5K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
30
Views
4K
  • Programming and Computer Science
Replies
14
Views
30K
Back
Top