Jump to content

Learning C & C++

HaX_VoarTeX

Hi im learning C & C++

as my first language! 

I know it would be easier to start out with something like java or HTML but as a freshmen in high-school thats what we decided to learn or i anyways its a self taught coarse for those whom might be interested and i being the geek that i am decided to jump on it not knowing what I'm getting into so in retrospect  i need help on where to learn this language from and preferably it being simple i would also like to learn any tips and easy tricks i would might want to know to help me face this "intimidating" programming language. :)

Link to comment
Share on other sites

Link to post
Share on other sites

I tried learning C++ as my first language but I've since put that on hold to focus on Lua first. With Lua, I've had a lot more fun learning to program and it's also quite useful for me as I work with some systems that work with embedded Lua scripts for advanced control purposes.

I think it would be much better going for Java/Lua/Python first as that will give you and idea about how programming works and many of the skills are somewhat transferable.

Push-To-Talk is a wonderful thing.

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, HaX_VoarTeX said:

Hi im learning C & C++

as my first language! 

I know it would be easier to start out with something like java or HTML but as a freshmen in high-school thats what we decided to learn or i anyways its a self taught coarse for those whom might be interested and i being the geek that i am decided to jump on it not knowing what I'm getting into so in retrospect  i need help on where to learn this language from and preferably it being simple i would also like to learn any tips and easy tricks i would might want to know to help me face this "intimidating" programming language. :)

I can help if you need. the most important thing to know is that you're just shifting memory around. there are really good tutorials on how to code with c++ on youtube. find a good IDE (I recommend visual studio) and just get into it. 

Link to comment
Share on other sites

Link to post
Share on other sites

honestly C++ is what most computer science courses start off with so i wouldn't say its a bad idea to use C++ as a starting point. if you plan to go to school for computer programming though you may want to learn a different program language than what you will already be taught.if that's the case you may want to learn python as its quite a useful language and is slightly less common than java and C++. 

Link to comment
Share on other sites

Link to post
Share on other sites

start with C, later go to object oriented programming with c++

 

DevC++, Visual Studio or something like that could help. 

 

Anyways where are you from? There are a massive amount of eBooks to learn from out there.

And if you have any questions - http://stackoverflow.com is literally the source for every IT-Dude with coding problems.

 

edit:

Visual Studio is so much functionality for people who only start this with hello world and stuff. Maybe you can also learn how to compile your code with g++ over console

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, HaX_VoarTeX said:

I know it would be easier to start out with something like java or HTML

Sure, but there's nothing wrong with learning C or C++ for your first language either.

8 minutes ago, HaX_VoarTeX said:

any tips and easy tricks i would might want to know to help me face this "intimidating" programming language. :)

It's unclear if you're going to be learning one language or two for this course (the last part of this sentence implies one language but the title suggests two). C and C++ are two separate programming languages. Unless the course requires learning both C and C++, then you'll just want to focus on just one of them.

 

Some people view C++ as C with some extra features and will recommend learning C first and then C++. This approach tends to cause people to learn C++ in a C style (although it depends on the learning material you're using). In my experience, most people these days consider that an outdated view of C++ and recommend treating them as completely different languages and to approach learning them differently. Ultimately we can't know how your course is expecting you to learn these languages (or if it even matters).

 

Some general resources:

StackOverflow: The Definitive C Book Guide and List

StackOverflow: The Definitive C++ Book Guide and List

LearnProgramming Subreddit: C++ FAQ

Pluralsight

Lynda

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, HaX_VoarTeX said:

Hi im learning C & C++

as my first language! 

I know it would be easier to start out with something like java or HTML but as a freshmen in high-school thats what we decided to learn or i anyways its a self taught coarse for those whom might be interested and i being the geek that i am decided to jump on it not knowing what I'm getting into so in retrospect  i need help on where to learn this language from and preferably it being simple i would also like to learn any tips and easy tricks i would might want to know to help me face this "intimidating" programming language. :)

I would also like to mention that i have been progressing along smoothly using cs50.io and cs50 walkthroughs on youtube

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, HaX_VoarTeX said:

Hi im learning C & C++

as my first language! 

I know it would be easier to start out with something like java or HTML but as a freshmen in high-school thats what we decided to learn or i anyways its a self taught coarse for those whom might be interested and i being the geek that i am decided to jump on it not knowing what I'm getting into so in retrospect  i need help on where to learn this language from and preferably it being simple i would also like to learn any tips and easy tricks i would might want to know to help me face this "intimidating" programming language. :)

Some small tips for learning C++:

 

 Learn your basics first:

  1. How the compilation process actually works (compiling each module and linking), how namespaces fit into this, etc. Many ppl skip this step and as a result can't even distinguish between a compiler or linker error, or don't understand why a circular dependency makes your compiler freak out.
  2. Stay away from templates (and meta-programming). Don't get me wrong, templates are awesome, but scary and complicated for the beginner. I've seen lots of ppl give up on C++ because some template meta code blew their mind. You don't need any of that until you're very experienced and by then you'll want and actively seek out templates to solve some problems you'll run into.
  3. Find documentation that teaches the C++11(and up) way of doing things. C++11 Changed a lot of things for the better and C++ has become a much cleaner, even beautiful language (imho). But the old ways of doing things are still in there as not to break existing software. Don't waste your time learning the old ways, there's some Herb Sutter and Stroustrup video's on youtube explaining those changes.
  4. Stick to procedural code if you have no experience with object oriented programming. Many ppl say to start with C and then move to C++ but there's rly no need. You can write procedural code in C++. This way you can make use and learn all of C++'s facilities while still sticking to procedural code.
  5. Variables (automatic, dynamic, static) and their scope/lifetime. Many ppl bash on C++ because it lacks a garbage collector, but it's not a weakness, it's it's biggest strength. C++ offers well defined object lifetime which can (and should) be used to do all the cleanup you'd ever want (not just memory) on YOUR terms, but you need to fully grasp object lifetime. (this is called RAII if you want the buzzword to google for).
  6. Implicit conversions. Many things are converted automatically without explicitly having to ask for it, a array name decays into a pointer for example. Or when comparing a signed and unsigned value the signed value is converted implicitly to unsigned before the comparison is made. Understand such things well as they'll bite you when you don't.
  7. Pointers and references, and along with those: const correctness.
  8. Exceptions and exception safety. Many ppl dislike exceptions and will try to simply tell you not to use them, but that does not fly. First of all, exceptions are a great mechanism to separate code and error handling. Without exceptions, often the actual code that does things is drowned out  by all the error checking and handling code that surrounds it. That's very error prone, ugly, and a hell to maintain. Secondly, other libraries and the STL use exceptions so there's rly no way around them. You'll need to learn how to write exception safe code so you, for example, don't leak resources when someone higher up throws a exception.

Only when you've become good at all this would I move on to object oriented programming and, by extension, polymorphism.

 

Did I mention const correctness? :)

 

Link to comment
Share on other sites

Link to post
Share on other sites

12 minutes ago, Unimportant said:

Some small tips for learning C++:

 

 Learn your basics first:

  1. How the compilation process actually works (compiling each module and linking), how namespaces fit into this, etc. Many ppl skip this step and as a result cant even distinguish between a compiler of linker error, or don't understand why a circular dependency makes your compiler freak out.
  2. Stay away from templates (and meta-programming). Don't get me wrong, templates are awesome, but scary and complicated for the beginner. I've seen lots of ppl give up on C++ because some template meta code blew their mind. You don't need any of that until you're very experienced and by then you'll want and actively seek out templates to solve some problems you'll run into.
  3. Find documentation that teaches the C++11(and up) way of doing things. C++11 Changed a lot of things for the better and C++ has become a much cleaner, even beautiful language (imho). But the old ways of doing things are still in there as not to break existing software. Don't waste your time learning the old ways, there's some Herb Sutter and Stroustrup video's on youtube explaining those changes.
  4. Stick to procedural code if you have no experience with object oriented programming. Many ppl say to start with C and then move to C++ but there's rly no need. You an write procedural code in C++. This way you can make use and learn all of C++'s facilities while still sticking to procedural code.
  5. Variables (automatic, dynamic, static) and their scope/lifetime. Many ppl bash on C++ because it lacks a garbage collector, but it's not a weakness, it's it's biggest strength. C++ offers well defined object lifetime which can (and should) be used to do all the cleanup you'd ever want (not just memory) on YOUR terms, but you need to fully grasp object lifetime. (this is called RAII if you want the buzzword to google for).
  6. Implicit conversions. Many things are converted automatically without explicitly having to ask for it, a array name decays into a pointer for example. Or when comparing a signed and unsigned value the signed value is converted implicitly to unsigned before the comparison is made. Understand such things well as they'll bite you when you don't.
  7. Pointers and references, and along with those: const correctness.
  8. Exceptions and exception safety. Many ppl dislike exceptions and will try to simply tell you not to use them, but that does not fly. First of all, exceptions are great mechanism to separate code and error handling. Without exceptions, often the actual code that does things is drowned out  by all the error checking and handling code that surrounds it. That's very error prone, ugly, and a hell to maintain. Secondly, other libraries and the STL use exceptions so there's rly no way around them. You'll need to learn how to write exception safe code so you, for example, don't leak resources when someone higher up throws a exception.

Only when you've become good at all this would I move on to object oriented programming and, by extension, polymorphism.

 

Did I mention const correctness? :)

 

unimportant=true;

 

Link to comment
Share on other sites

Link to post
Share on other sites

If you do C++ buy "Absolute C++" by "Walter Savitch"

I found that book very very useful with explanations, and code examples. I had to buy that book for my college class, and do some assignments out of it. It was very useful.
 

Link to comment
Share on other sites

Link to post
Share on other sites

I'm gonna add a few points to what @Unimportant said since I don't think he said as much as he could've.

 

2) No, don't stick away from template programming. Sure, it may be scary for a beginner but C++ is a behemoth that should be respected. C++'s templates allow you to create truly beautiful abstractions. Especially with the modern additions to the language such as variadic templates - I cannot even begin to explain the number of possible, beautiful, abstractions you can create with functions that can take a type-safe, arbitrary, number of arguments. From creating beautiful RPC abstractions with std::function to making very nice factory patterns for object construction e.g. std::make_unique as a rather simple example (while we're on the subject, guaranteed copy elision is now actually part of the standard - it was guaranteed by many compilers before this but it's nice to know it's standardised now).

 

3) To truly understand the new additions to the language, such as move semantics, you have to be aware of how things were done before. And all of these Modern C++ resources will actually make reference to how things were done before. I'm not saying you need to pointlessly master how things were done before but I'd struggle to relate the usefulness of the modern feature-set without making keen reference to how things were done before. What tends to happen when people learn C++ is they bypass the important fundamentals and end up writing terrible code. C++ is probably the worst taught programming language on the planet. Even in modern "Hello, World" examples, they forget to mention that nobody, even as part of major organisational standards such as LLVM, does: "using namespace std;" and they also gloss over what std::endl actually does. It's not just a new line.

 

4) I think people should move to OOP when they are ready. Sure, you can write procedural code with C++ but, in reality, if you're making real usage of the STL, you're using objects regardless. Being able to stitch these together into some clever structure is core of C++'s powerful abstractions. What people should really do is learn OOP properly. I can't count the number of developers I've met that don't know what SOLID or GRASP and/or can't list any design patterns. OOP is really powerful and more people should understand how it is implemented in reality to create even more powerful abstractions. Keeping in mind that C++ gives you these things basically for free; a lot of C++'s abstractions are actually optimised away almost completely. Check out Jason Turner's CppCon talk about creating a game w/ C++17 for an old console - he uses that online compiler explorer website to demonstrate how the language absolutely optimises all of these beautiful abstractions away.

 

5) I'm just gonna link what Unimportant said about RAII to a common, modern, example of using RAII for resource cleanup: smart pointers. There's a huge argument that there's not much need to use raw pointers as much as they were used before. It's even better now to check the lifetime of objects with guaranteed copy elision as part of the standard.

 

6) There's a lot more things that are implicit in the language than simple conversions. For example: constructors, binding of rvalue references on const objects to const lvalue references, copy elision, etc. - I also mention another example of implicit actions at the end of my post when I talk about the nuances regarding implicit and explicit declaration of move and copy constructors.

 

People approaching C++ should understand that there's a lot of theory and nuances that go into the language (e.g. a lot of gotchas). For example, if you explicitly declare your move constructor, your implicit copy constructor will be deleted. Also, small nuances that can catch people off guard are things like move semantics in relation to std::string. Since std::string's contents can be optimised via SSO (short string optimisation) - basically, the string will be one the stack with the object (if it's locally allocated), so using std::move to cast this to an rvalue reference won't actually guarantee it is moved. It will still be copied because of this optimisation that many aren't aware of. 

 

I also can't agree more with Unimportant's mention of const correctness. Const correctness is beyond important. A simple example of its important could be in some code that loops through a std::map<int, char> or something like that. If you used a range-based for loop and tried to iterate it with: const std::pair<int, char>&, a copy is going to be made implicitly regardless of the const reference because the key type becomes const when in the context of a std::map. This is one of the nice examples given when people explain the utility of auto - another fantastic feature, anyone interested in polymorphic lambdas?

 

C++ is a beautiful language but I'd be lying if I thought you didn't need to understand all of the concepts from C to truly grasp it (despite what Unimportant said). Sure, you don't need to know the C standard library inside-out but I genuinely don't see how one can truly appreciate and understand C++ without understanding the crucial, inherent, concepts it inherits from C. Lots of C++ books will assume you have basic knowledge of C and some don't. As I've said, I dislike the majority of people teaching C++ since they don't actually know the language all that well. If you want a good book on Modern C++ once you've got the basics down, I can't recommend Effective Modern C++ as a fantastic primer on modern C++. C++ is one of those languages where nobody who knows anything about the language will openly refer to themselves as experts, only other people. The community is also quite torn on what it means to "know" C++. You'll learn a new thing every day in C++. It's a beautiful behemoth, learn to love it and it will love you back.

 

tl;dr - I revised this post after realising I used a lot of terminology that C++ uses but, sadly, C++ is quite involved. Given the size of the language now, I tend to have serious doubts when people claim to know C++. C++ is a huge endeavour to undertake and anyone who thinks otherwise doesn't know the language.

And, if my thought-dreams could be seen,
they'd probably put my head in a guillotine.
But, it's alright, ma, it's life, and life only.

Link to comment
Share on other sites

Link to post
Share on other sites

On 3/17/2017 at 8:47 AM, stmfd sp!, {lr} said:

tl;dr - I revised this post after realising I used a lot of terminology that C++ uses but, sadly, C++ is quite involved. Given the size of the language now, I tend to have serious doubts when people claim to know C++. C++ is a huge endeavour to undertake and anyone who thinks otherwise doesn't know the language.

That is an example of why I'm tempted to agree with @Unimportant on holding off on templates (I specifically mean writing, not using).  Not that that they never should, but there are a lot of mechanics and design principles that should be learned beforehand.

Link to comment
Share on other sites

Link to post
Share on other sites

20 hours ago, Yamoto42 said:

That is an example of why I'm tempted to agree with @Unimportant on holding off on templates (I specifically mean writing, not using).  Not that that they never should, but there are a lot of mechanics and design principles that should be learned beforehand.

I said something very similar to Unimportant. Templates already fall under the "slightly experienced" category. In my opinion, though, templates are badly taught because they always teach these horrible examples that only use primitive types e.g. a template function to find the greater of two values. Beginners find it hard to quantify where they'd actually implement one in the real world. As it stands, I use templates for: factories (variadic forwarding), types (template types), etc. - but I rarely go out of my way to create a template-based solution. Still though, even in C++, there's some hacky type stuff whose behaviour you wish would be inherent and, therefore, compiler imposed when working with templates - e.g. static_assert on types to make sure they're derived types of some base; I wish it possible to do this somewhat implicitly.

 

But yeah, at points in my post I basically said something similar to Unimportant but with less emphasis on: "don't bother at all". Personally, I think if you've done generics in a language like C#, it won't be as difficult to pick up the certain nuances of C++'s templates to implement similar solutions. 

And, if my thought-dreams could be seen,
they'd probably put my head in a guillotine.
But, it's alright, ma, it's life, and life only.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×