I am having a hard time learning to program What to do?

In summary, learning to program can be difficult, but with the right resources it can be rewarding. If you're starting from scratch, I recommend C++ Primer Plus by Prata. If you're looking to move on from there, I recommend learning a more modern language like Python.
  • #1
thewhills
95
0
I bought a book on C++ that was recommend by a friend and a cheap book on C and I just can't get into it.

It start off ok, but then the throw 50 lines of code at you for even a basic program and I get lost...

I don't know what any of it means and I feel like bashing my head in.

Any suggestions?
 
Technology news on Phys.org
  • #3
C++ is a very involved complex language to learn programming with.

Either start with one specifically designed to teach beginning programming like mal4mac suggested.

Or you can learn a general programming language but pick a more modern easier one, I would recommend python. Python isn't just easy to learn, it is widely used for real programming.
There is a beginners book and examples free at http://diveintopython.org or if you might like http://openbookproject.net/thinkCSpy/index.xhtml it's also free but aimed at more advanced students.

Rememebr there is more to programming than knowing a particular language. Programming is about describing the problem to a computer, once you know the techniques for doing this most languages are pretty similair.
 
Last edited by a moderator:
  • #4
I recommend C++ Primer Plus by Prata. It's an easy book to learn from, and wordy.

The fact is many CS programs start you off with either java or c++, so you might as well learn the syntax. You can learn about variables, pointers, control structures, arrays, array lists, and recursions, starting off with C++. Plus you'll learn how the computer manages the data, a very important part of CS, or "Datatology" as some call it.

The hardest part in the beginning CS courses is coming up with your own algoritms for projects, mapping them out, writing the pseudocode is often the most difficult part. Once that is done you should be able to convert it to the language.

As you go along, do some exercises in the book and try and make a few programs that are a little bit harder than what you're used to. That's a good way to move forward.
 
  • #5
thewhills said:
I bought a book on C++ that was recommend by a friend and a cheap book on C and I just can't get into it.

It start off ok, but then the throw 50 lines of code at you for even a basic program and I get lost...

C and C++ are where you want to start if you're looking to get into serious programming. They're low level enough so that you have to deal with memory management, various data types, and other nitty things. It gives you a very good understanding of how computers work under the covers, but makes you jump through a lot of hoops to do what you might think are simple tasks.

By contrast, things like Perl and Python are very powerful languages. You can do the same tasks with single built-in function calls, rather than writing tons of very detailed instructions. The other benefit to Perl and Python specifically is that they're not compiled. On a personal note, compiling was the thing that drove me away from C (and I guess Java too). So you write it, you run it. Skips the whole compiling phase. Plus, you can do funky things like running new code on the fly with "eval".

For example, if you're programming with an array in C, you have to tell the compiler how big that array is going to be in advance. Oh, and you have to tell it how big each slot in the array is, as well, and what data type is going to be stored there (one and the same, usually). So if you're not sure if you're going to need 10 slots or 5000 slots, you're going to have to either declare the full max right up front, or dynamically allocate new memory on-the-fly as your array grows. In Perl? You don't need to do any of that. Perl's smart enough to handle it for you. Python, too, I assume. Technically, you don't even need to declare the variable (although you should!)-- you just start using it and it's there for you.

The sacrifice is processing speed. If you try and do any intense data processing, like, say, ray-tracing a 3D image or extrapolating out a mathematical formula to billions of iterations, it'll be much faster in C, C++. But 9 times out of 10, you don't care about that for hobby-style programming. Having your programs be easy to build and easy to edit is far more desirable.

Myself, I'm a Perl guy. But Perl may be losing its edge to Python, given that I see more about Python these days than Perl. Maybe because Perl 6 is such a change from Perl 5-- maybe because Perl 6 took so long to release, I dunno. Anyway, I guess I'd have to recommend Python. But Perl's still cool too :)

DaveE
 
Last edited:
  • #6
davee123 makes some really good points. Obviously, it's hard to use arrays especially for basic stuff. I made a bowling score program (all it does is count the score) in C++, completely procedural, and I probably could have done it easier in Python. Plus, I had a roll count that associates a current roll with each frame so I could add in the next two rolls, and I had to use the maximum number of rolls possible for my array. In python, I probably could have made memory management a bit easier.

With variables as well it is easier. For example, I can write x = 100 and it'll probably be an int or x = 100.12 and it will be of a floating-point type. Plus python has built in abilities to handle large numbers. So yes, it is easier.
 
  • #7
OrbitalPower said:
With variables as well it is easier. For example, I can write x = 100 and it'll probably be an int or x = 100.12 and it will be of a floating-point type. Plus python has built in abilities to handle large numbers. So yes, it is easier.

Oh yes-- excellent example. I forget how C/C++ handles it, but if you want to multiply 1000 * 5.25, and assign the value to an integer, it may give you the answer of 5000 rather than 5250, since the floating point "5.25" may get converted to an integer before doing the calculation. I forget all the details, but I remember having issues with things like that. Similarly, a normal "int" is what, 4 bytes? So if you multiply 1,000,000 x 6580 in C, you'll get some wacky answer, because the maximum size of a normal integer is 2^31 (that 1st bit is for the sign).

So in C/C++, you've got to worry about all those things. In your head, doing math is easy-- a number's just a number, and that's more-or-less how Perl and Python handle things. But in C/C++, an integer is different from a short is different from a double is different than a float, etc. So you're bound to run into problems sooner or later, where how you thought about it in your mind turned out to be vastly different than how the compiler interpreted your code.

DaveE
 
  • #8
The real reason I was looking into C an C++ is because I need something versatile and it seems like anything can be done in C++
 
  • #9
C/C++ can also be used everywhere, from 50c washing machine controllers to supercomputers.
But with available libraries Python, Java and C# can also do almost everything (except write an operating system!) but they are more limited in where.
Python and Java will run on almost anything, C# is largely windows only (there is an unofficial Linux clone)
 
  • #10
It's not so much the language, but the complexity of the first programs you try to write. Here it's the training book that makes the difference. Perhaps an online class via some junior college might be good, but that also can vary between classes.

For some, it would help to understand how a computer works. Being able to step through the instructions one at a time while looking at the register and memory content would be useful. A typical debugger comes close to being able to do this, but a learning tool would be better.
 
  • #11
Jeff Reid said:
It's not so much the language, but the complexity of the first programs you try to write. Here it's the training book that makes the difference. Perhaps an online class via some junior college might be good, but that also can vary between classes.

For some, it would help to understand how a computer works. Being able to step through the instructions one at a time while looking at the register and memory content would be useful. A typical debugger comes close to being able to do this, but a learning tool would be better.
I do agree with you. C and C++ language is a power tool. If you have ever leant about the computer structure and assemble language, you will understand that C/C++ useful.

I suggest that you can view some video tutorials on the net, such as youtube, or MIT open cource. I'm not sure where the 50 lines code come from, but I can recall my first c code was "print("hello word");":smile:
 
  • #12
That's some very informative advice there, davee123
 
  • #13
Using C++ to learn programming is a bit like learning to drive with a Formula 1 car!
 
  • #14
javascript?
 
  • #15
A few people have suggested starting off with a simpler language, which I agree with. I really liked learning all of my basic programming concepts in http://en.wikipedia.org/wiki/Logo_(programming_language)" . Whoa, that was a long time ago.

granpa's suggestion of javascript seems like a good idea too.
 
Last edited by a moderator:
  • #16
Every body has given good advice, but I am surprised to see no one mentioned "BASIC" language. It can be learned in a single day. Most of the things that davee123 has written for python and perl, do apply to basic. I'd recommend QBASIC for anybody who is starting with programming.

I'll enlist some of the features of the QBASIC here:

+Ve's
=====
You don't need to compile
No need to define variable size, or simply you could skip defining variables
While you are programming, code examples can quickly be consulted using build in help
Easy serch to looup library functions
QBASIC programs can be executed in MS-EXCEL as macros with no or little modification. (Which is very easy as you don't need to install anything)
Good online help is available like
http://www.petesqbsite.com/
www.qbcafe.net/qbc/english/misc/tutorials/beginner/starting-qbasic-1.html[/URL]

Code can easily be converted to executeable file (.exe)
Run time enviornment requieres no installation/path-setting what so ever.

-Ve's
=====
Slower in speed (Tolerable for hobbey and learning programs)
Not objest oriented.
Working enviornment is dos like.

QBASIC version 4.5 is best and can be googled to download.
 
Last edited by a moderator:
  • #17
Basic used to be the thing but the language that's now available to everyone is JavaScript. It works in any browser and every machine (even a phone) has a browser!
For a beginners course see http://www.grelf.net/jscourse
 
  • #18
it always hard on the first time, start from the easy one . honestly I'm start from batch (.bat) hehe , go to python => Java => and now on C++. Actually I'm just learn python for getting the basic understanding about programming .. , once you get that basic you'll get the fun of programming language
 

1. Why am I having a hard time learning to program?

There can be several reasons why you are struggling with programming. It could be because you are not familiar with the fundamental concepts, your learning style may not be compatible with the programming language, or you may not be dedicating enough time to practice and understand the material. It is important to identify the specific challenges you are facing and address them accordingly.

2. Should I give up if I am having a hard time learning to program?

No, you should not give up. Learning to program can be challenging, but it is a valuable skill that requires patience and dedication. It is normal to struggle when learning something new, and it is important to keep practicing and seeking help when needed. With persistence and determination, you will eventually overcome any obstacles and become a successful programmer.

3. How can I improve my programming skills?

One of the best ways to improve your programming skills is by practicing consistently. Take on small projects and gradually work your way up to more complex ones. You can also join online communities or attend coding workshops to learn from others and gain new insights. Additionally, make sure to review and understand the fundamentals of programming, as they are essential for building a strong foundation.

4. What should I do if I don't understand a programming concept?

If you are struggling to understand a programming concept, don't hesitate to seek help. You can ask your peers, join online forums, or reach out to your instructors for clarification. It is also helpful to break down the concept into smaller parts and practice it with different examples. Sometimes, taking a break and coming back to it with a fresh perspective can also make a difference.

5. How long does it take to become proficient in programming?

The time it takes to become proficient in programming can vary depending on various factors, such as your dedication, learning style, and the complexity of the programming language. Some people may become proficient in a few months, while others may take longer. The key is to stay consistent in your practice and focus on understanding the concepts rather than rushing through them.

Similar threads

  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
2
Replies
69
Views
4K
  • Programming and Computer Science
Replies
1
Views
727
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
12
Replies
397
Views
13K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
8
Views
875
  • Programming and Computer Science
2
Replies
58
Views
3K
  • Programming and Computer Science
2
Replies
49
Views
3K
Back
Top