Sign in to follow this  

From C to ?

This topic is 1426 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I want to move on from C to an object oriented language. (C++, C# or Java)

 

My C knowlege is not that advanced.

But I have learned all the basics of the language. (pointer,arrays, structures, input output files, dynamic memory)

 

I don't plan to move on Java because I am going to learn it along with my university class next year.

 

This leaves me with C++ and C#. I think it's best for me to move on to C++. But there's a big fuss on learning C++  the C way. And because I know C I don't want to start using C in C++. This is something I want to avoid.

 

So I want a book that doesn't learn you to program the C way in C++. I don't care if it's an super introductory book I don't mind. I just want the book to explain well the object oriented concepts and the best way to program in C++.

 

 

 

Thanks smile.png

 

 

Share this post


Link to post
Share on other sites

On Youtube you can find long presentations form Stroustrup where he talks about how not to look at at C++ as C with classes and how to do things the C++11 way. They might sound a bit advanced though.

 

This was the last one I saw: "The Essence of C++: With Examples in C++84, C++98, C++11, and C++14"

Share this post


Link to post
Share on other sites

If your goal is as stated, to learn an object-oriented language then I think C# is the one to choose of the three.

 

Java, as you mention, is something you will learn at university anyway.

 

C++ is an old, large, complex language and has plenty of things in it that don't relate to OO. As I get older I like C++ less and less (or rather I dislike it more and more), the infuriating anachronisms of C++ make it a language I'd advise people to stay away from unless they have no choice.

 

C# is Java-esque, so it will give you an edge when learning Java at uni. But it is actually a much nicer language than Java (and C++, but that's setting a pretty low bar anyway).

 

Another good candidate is Python, btw.

 

If I absolutely had to use a systems language and had my choice of them then I would skip C++ and go straight to Rust or Go.

 

Once you know the C#/Java way of doing things you might actually have a better idea how to approach C++. C-style C++ results in questionable code (unless it was done for a good reason) but C#/Java-style C++ is not a bad place to start and then you can selectively bring in some of the actually-nice C++ features like free-functions, typedefs, better-generics (templates, but don't go overboard with them), deterministic destruction, const, auto, maybe some others. A lot of the C++ language you just want to ignore day-to-day really (javascript's headed that way too).

Share this post


Link to post
Share on other sites

I learned C++ right after C, and I do not regret it.

When I needed Java, it took me two days to be capable enough for the tasks.

I studied C# to code a tool, and even though it took me longer than Java to get the hang of, the learning was also fast and easy enough.

 

But I like to learn languages as I need them. It reinforces the concept that they are the tools; and that I am not their programmer.

The only times where I research new languages that I won't really need (notice I said research, not learn) is when I am evaluating new technologies, what I do from time to time. Still, this research process should never take over two days.

 

And as you said you'll be needing Java, I'd go for it.

 

I guess the best C++ book recommendation I can give you, following what you asked, is C++ for dummies.

Edited by dejaime

Share this post


Link to post
Share on other sites

I wouldn't go on C++ right now. Main problem is that there's no such thing as "C++" to start with. I mean just read this:


On Youtube you can find long presentations form Stroustrup where he talks about how not to look at at C++ as C with classes and how to do things the C++11 way. They might sound a bit advanced though (1).
 
This was the last one I saw: "The Essence of C++: With Examples in C++84, C++98, C++11, and C++14" (2)

Here's what I read "between the lines":

  1. The new, non-broken way. But wait, because the new not-broken way is complex.
  2. 4 versions. Four.

I'd probably go C# right now. Java left me a bitter taste and not in the good way.

Share this post


Link to post
Share on other sites

Guys I am determined to learn C++ and do some serious stuff with it until the end of the year. :P 

 

I will take a look at the books you recommended me.

I already started with C++ Primer as it is the most advanced and will get me quickly moving. (see if I can keep up with it)

 

 

Thanks for your suggestions!

Share this post


Link to post
Share on other sites

I'd probably go C# right now. Java left me a bitter taste and not in the good way.

 

If you want an even more bitter taste, try using C# with Windows Metro... They cut out loads of classes for their core profile and does tend to cause quite a few headaches.

 

Whilst C++ is a perfectly robust language, the only one I have known not to evolve in any radical way (for many years) is C.

 

... Oh wait, you say that there is now <stdbool.h>? C99 is Madness!

Edited by Karsten_

Share this post


Link to post
Share on other sites

 

I'd probably go C# right now. Java left me a bitter taste and not in the good way.

 

If you want an even more bitter taste, try using C# with Windows Metro... They cut out loads of classes for their core profile and does tend to cause quite a few headaches.

 

Whilst C++ is a perfectly robust language, the only one I have known not to evolve in any radical way (for many years) is C.

 

... Oh wait, you say that there is now <stdbool.h>? C99 is Madness!

 

 

There's C11 too, though admittedly I don't use it but have been told it contains mostly atomics/threading stuff and some utilities designed to make writing cross-platform programs useful, such as a standard alignment keywords (read: all major C projects already have platform-independent wrappers for these, especially for platforms which are not going to support C11 anyway - such as MSVC - meaning C11 is pretty much useless all around). Oh well, at least they tried.

Share this post


Link to post
Share on other sites

Yes, admittedly I have never even seen C11 code in the wild.

 

I still dont think MSVC fully supports C99 either which is quite annoying. Microsoft's excuse was that they would rather spend time on C++0x functionality.

Now, as a C++ developer, I agree with this choice. Unfortunately their C++ support is a bit lacking too :/

 

With Microsoft's new direction with C++ (Albeit C++/CX) perhaps we will see them make up a bit of ground here in the near future including in C support.

Edited by Karsten_

Share this post


Link to post
Share on other sites

 


I wouldn't go on C++ right now. Main problem is that there's no such thing as "C++" to start with.

Oh, come on.

I'm so happy that C++ is evolving again, after so many years of standstill. Simply take a modern compiler like MSVC or GCC and take off. There are still some minor restrictions regarding C++11 support, but well, if it's not one thing, it's another.

And regarding different versions: What C# version are you going to learn: 3, 4, 5? And what .net framework: 3.5, 4.0, 4.5?

 

 

Frankly, beyond the move to Generics ( 1.1 -> 2 I believe ), almost everything that changed with the language has basically stayed the same.  It's evolutionary changes, like support for parallel programming.  Simply put though, idiomatic C#2 and C#5 are basically identical.  The same can certainly not be said for C with Class to C++14.

 

 

Ironically, one of the biggest warts in C#/.net IS the existence of non-generic containers.

Share this post


Link to post
Share on other sites

I also love how people complain about C++, C# or Java version issues, and then don't comlain about Perl, Python or Ruby versions issues ... which are absolutely the worst, except most of the history of Perl 5 has been about as stable as C++,C# and Java ... hell, you can just now BARELY get a linux distro that ships with Python 3 (which is at 3.3) because they have a dependency on incompatible Python 2 code.  And ruby, a langauge I actually like, got stuck at 1.8 for more than 2 years after 1.9 was released, and now that 2.0 is released, only 1 major distro ships it.

 

The fact is in my entire C++ history, I had exactly 1 type of code I actually used that wasn't compatible with C++ 11 - related to how it disambiguates names in some cases.  I spent 3 hours fixing my code base, problem gone.

 

Also, in C#, none of my working code has ever failed to work on newer versions, except for 1 change they made with 1.1 as a security fix.

 

Yeah, the Python 2 vs Python 3 thing is driving me nuts. I get that backwards compatibility is a good thing, but it was just so unnecessary to spawn an incomplete 3.x version leaving 80% of the Python community stranded on 2.x because of dependencies. The amount of developer manpower lost on this issue is probably enough to power a small city for several decades, and is a PITA for anyone considering Python as a development platform.

Share this post


Link to post
Share on other sites
sorry for not specifying the array part. i meant the way it is represented in c++11.

int arr[3][4] is so much clearer than std::array <std::array <int, 3>, 4> arr, at least to me.

Share this post


Link to post
Share on other sites

Oh yea, that'd definitely be clunky.

I prefer not to use 2D arrays anyway. happy.png I find it is easier to use 1D array and just do the conversions myself:

std::vector<int> arr(3 * 4);
 
//I can iterating over it as if it's 2D:
for(int y = 0; y < height; ++y)
{
    for(int x = 0; x < width; ++x)
    {
         arr[(y * width) + x] = ...;
    }
}
 
//But I can also iterating as if it's 1D:
for(int i = 0; i < (width*height); ++i)
{
    arr[i] = ...;
}

 

But if you want a clean class to use, you could wrap your "std::array <std::array <int, 3>, 4>" into a new (re-usable) template class: Array2D<int,3,4>, and write one or two quick member functions to make it easier to access the data.

Share this post


Link to post
Share on other sites

sorry for not specifying the array part. i meant the way it is represented in c++11.

int arr[3][4] is so much clearer than std::array <std::array <int, 3>, 4> arr, at least to me.


perhaps this well help you understand why std::array is preferred:

c++11 std::array way:
http://ideone.com/XpP7Zm

c++ array way:
http://ideone.com/ey6aC8

std::array allows you to use the entire suite of std container algorithms, that you can't use with a plain old array, it also includes a handy size field, so no longer do you have to keep track of how many elements you have. there's plenty of other reasons to be using std::array, but being able to use a static array with container algorithms should be enough imo.
 

[spoiler]

#include <iostream>
#include <algorithm>

int main() {
	std::array<int, 5> a = {1,2,3,4,5};
	for(int x : a) std::cout << "a: "<< x << std::endl;
	return 0;
}
    #include <iostream>
     
    int main() {
    const int ALen = 5;
    int A[ALen] = {1,2,3,4,5};
    for(int i=0;i<ALen;i++) std::cout << "a: " << A[i] << std::endl;
    return 0;
    }

[/spoiler]

Edited by slicer4ever

Share this post


Link to post
Share on other sites
Sign in to follow this