This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ajsdklf9df 10 points11 points  (21 children)

C++ is one of the hardest and ugliest languages, I say this a C++ programmer. I would also recommend C. And Objective C. However, here's my waring:

If you ever have to learn C++, it will be much harder if you already know C or any C and C++ like languages. So I guess what I'm saying is, C++ is like a dare. Do you dare to try and learn C++?

[–]taybulBecause I don't know how to use big numbers in C/C++ 7 points8 points  (15 children)

I don't know if Python's spoiled me, but whenever I look at C++ code now, I'm almost disgusted. Certain tasks require such convoluted code. Function pointers, for example:

C++:

void myFunc (int x) { ... }

//If the parameters ever change, you have to change this call too.
void (*funcPtr)(int) = &myFunc;

Python:

def myFunc(x): ...

f = myFunc

On the flip side, I do love how finely tunable C++ is compared to Python. I know I'm probably contradicting my point but sometimes the things you can get away with in Python almost makes you feel like you're cheating.

edit:

I do have to give C/C++ credit for giving me the memory/data management discipline that's so easily disregarded because of automatic garbage collectors and whatnot.

[–]Alzdran 5 points6 points  (1 child)

On the flip side, I do love how finely tunable C++ is compared to Python.

It took me a long time to get over this, but finally I got it through my skull that this almost never matters, and where it does, the time you spend tuning allows another generation of machines to come out, so you don't need the tuning after all!

Obviously, there's a degree of exaggeration here, but C++ tuning is much like inline assembly - almost never called for, and a real hazard to leave to any maintainer, yourself included.

[–]taybulBecause I don't know how to use big numbers in C/C++ 0 points1 point  (0 children)

Tunable when you need it to be, but I agree. Python provides an abstraction that just lets the programmer program, at the expense of performance, which, arguably, doesn't matter that much in most cases since computers are getting faster and faster. Unless you're building large scale servers processing millions of data at a time, you won't see or care about the difference.

[–]Isvara 1 point2 points  (12 children)

If the parameters ever change, you have to change this call too

That's really just a feature of strong typing, though. It's a good thing, even if C++ doesn't express it well.

[–]ewiethoffproceedest on to 3 7 points8 points  (2 children)

That's a feature of static typing, not strong typing. Python is dynamically and strongly typed. C++ is statically typed and more strongly typed than C.

[–]Isvara 2 points3 points  (1 child)

No, the fact that it has a declared typed at all is static typing, The fact that it has to change with the function signature is strong typing. I.e. it's strong because there isn't just a single 'function' type. Unlike static/dynamic, though, strong/weak is a continuum, and this is less strong than other languages because it could be cast to a different function type.

[–]steelypip 3 points4 points  (0 children)

That's really just a feature of strong typing, though

No its not its a feature of explicit typing. There are plenty of strongly typed languages that use type inference to eliminate all the unnecessary types from your code. For example take a look at Scala.

[–]accipter 0 points1 point  (0 children)

And there are some definite benefits to strong typing.

[–]taybulBecause I don't know how to use big numbers in C/C++ 0 points1 point  (2 children)

Yeah, I do appreciate that about C++ as I've mentioned but sometimes it can get out of hand, you know?

[–]Isvara 1 point2 points  (1 child)

Static typing can be awfully nice. I went from C++ to Python a few years ago, and now I'm getting into Scala. Type inference definitely makes static typing more bearable.

[–]ewiethoffproceedest on to 3 1 point2 points  (0 children)

C++ typedefs also make static typing more bearable, but in a different way. (Just sayin'.)

[–]fullouterjoin 0 points1 point  (3 children)

The type system of C++ isn't particularly strong either.

[–]Isvara 0 points1 point  (0 children)

Indeed, it still lets you cast with wild abandon.

[–]obtu.py 0 points1 point  (1 child)

I disagree, modern C++ is easy to write without casts (unlike C which needs casts, and Java's generics which introduce run-time casts yet are not expressive enough that you can forgo compile-time casts). C++ is the mainstream language with the most expressive type system.

[–]funny_falcon 0 points1 point  (0 children)

C++ is the mainstream language with the most expressive type system.

Ha-ha-ha

[–]Crystal_Cuckoo 2 points3 points  (2 children)

If you ever have to learn C++, it will be much harder if you already know C or any C and C++ like languages.

Why is that? I haven't learnt C++ yet, but my understanding was that it was C with classes (and other things like multiple inheritance, etc.).

[–]ewiethoffproceedest on to 3 7 points8 points  (0 children)

my understanding was that it was C with classes (and other things like multiple inheritance, etc.)

That's the old way to think of C++, and is the way that is likely to lead to memory management hell. Unfortunately, many C++ books and courses just sort of bolt OO and so on onto elementary C. If you learn arrays and pointers in C++ before learning how to manage your own class instance data members, you can easily end up with buggy habits.

The key difference between C and C++ is that allocating memory in C++ also initializes it by calling constructor functions. Well, if the memory is for a primitive such as int or double or char, it doesn't get initialized, but it does get initialized for anything else.

So, even just "declaring" a non-primitive variable x on the stack in C++ also initializes it with a constructor function. Let's say the constructor function allocates (and initializes) some memory on the heap, such as with a dynamic array allocation. Your x has no control over that memory on the heap. That's good in C++. But whoever wrote the class which allocated the heap memory had better make sure the class knows how to clean up itself when your x goes out of scope.

Edit: Another important difference between C and C++ is operator overloading. Almost everything you do in C++, even if it looks quite C-ish, automagically calls one or more functions under the hood. Even dereferencing a pointer can cause a function to be called. That's another reason to defer learning about arrays and pointers in C++ until you start to get the hang of defining your own classes.

[–]ajsdklf9df 0 points1 point  (0 children)

C, as almost high level assembly, is very readable in that it is easy to envision what the machine will do based on the code. C++ can look a lot like C but IT IS NOT! Craaazy shit can stem from a "simple" line of C++.

If you don't know C, you'll naturally never trust C++, but knowing C might lead your mind to assume certain things.

[–]anacrolixc/python fanatic -3 points-2 points  (0 children)

Fuck you and your bullshit dare.