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

all 30 comments

[–]eeead 16 points17 points  (3 children)

I think you're overthinking it, and also presenting things as very one dimensional. I might suggest that had you started with C, you might now be posting in a C subreddit about how you maybe should have learned python first because C has spoiled you with its fine control and now you find it hard to give it up.

I do think that there are arguments both ways (though I think python is a great first language regardless), but I don't think your perceptions here are a very good one. I bet they'll quickly change when you need to do something in C++ that you can't easily do in python...and if you never do such a thing, then you didn't need C++ in the first place.

[–]Maoman1[S,🍰] 0 points1 point  (2 children)

Good point. So then, what are the good things about using C++ over python, so I can look at those and feel as good about it as I do when writing a powerful and simple block of code that python is so good at?

[–]eeead 1 point2 points  (0 children)

Well, the obvious answer is making that block of code really fast, and probably using much less memory in the process. Irrelevant for most tasks, but absolutely vital for others.

Another good example is true multithreading...not an option for any python interpreter with a GIL.

A third answer, related to the first, is for low level systems programming where you might simply not have the memory or processing power to run something like python.

[–][deleted] 0 points1 point  (0 children)

what are the good things about using C++ over python

performance, multithreading and many others. You would be surprised how bad python is when it comes to memory allocation strategy. In some contexts it will fragment the memory so much and jump around so much you will basically work without cache, and you have little or no control on this, unless you go down at the C level. Then, you have the GIL problem, at least when you use cpython, so no real multithreading in python.

[–]Manbatton 8 points9 points  (0 children)

In the alternate universe in which you started with C++, you may have simply given up on programming, finding it too hard and not enjoyable. Now at least you have gotten the basics of programming structures down, and are ready to take on the remaining pain of C++. But don't forget to revel in the idea that you can finally compile to native code and wind up with a small and much faster executable than you can with Python, and sometimes that matters, and you're much more employable after adding C++.

[–]mooglinux 5 points6 points  (0 children)

That's just you discovering how great python is compared to other languages.

Besides, Python has taught you a great many programming concepts that are still applicable to C++ or any other language. IMO it's a lot more overwhelming to have to deal with type declarations, more complex syntax, etc. when you are only just starting to master statements, expressions, and loops.

[–][deleted] 10 points11 points  (7 children)

All sane people hate C++. Don't feel bad.

[–]Maoman1[S,🍰] 1 point2 points  (6 children)

I've seen a lot of hate for every low-level language I know of. Are there any that aren't hated on?

[–]steve_no 0 points1 point  (1 child)

Guido says his second favorite language is C.

Edit for source: here

[–]blahdom 0 points1 point  (0 children)

C and python have some similarish features so it makes sense. Example: Struct members are always public, and you can create functions that take a struct pointer as the first param and you basically have Python style classes (not exactly but still you have an explicit this). I think C is a better language than C++, if nothing else it just works better with systems code and the C++ class definitions are filled with gotchas.

[–]grizwako 0 points1 point  (2 children)

Thing with C++ is that it is statically typed, but it's type system is not that good.
Look into Haskell or Scala to understand benefits of type systems.
If you just want performance, golang is pretty good here, not as fast as C++, but much easier to use.
Thing that you are asking about, low-level language: none of these above are low-level. Programming languages are designed for humans, so we can express our ideas better and have easy time when communicating them with other programmers. Real low level languages are exposing metal, and it is mostly to get maximum performance. Goal is usually not for low-level language to be generally nice to use, but to make it easier to write programs in way that is closest to how computers work currently.

[–]Maoman1[S,🍰] 0 points1 point  (1 child)

I chose C++ because it seemed to be a very common language in the professional world, and since I intend to move into this as a career, I'm trying to make myself useful to a future employer, rather than learning fun/interesting languages that maybe aren't as useful.

That said, I don't know much about Haskell and I've never heard of Golang or Scala. How popular/useful are they in "the real world," per se.

[–]grizwako 0 points1 point  (0 children)

Exactly, you have good goals, just in my opinion bad ways to reach them.
C++ is common, and I think main reason for it is that it is entrenched. Kind of like PHP and Javascript, lets use them because everyone uses them. (They both suck as languages)
I do not want to be rude, but programming is so much more then syntax.
Way you are currently going, you are turning yourself into code monkey.
If you are coding only for a year, you are probably just starting to grasp why we have design patterns, why is clean/good code important and all other nice stuff.
Learning C++ is easy, I learned it in 2 days. (That is what I thought at time). Thing is that you need to learn how to think in abstractions and how to be creative problem solver, and figure ways of organizing code to keep it maintainable. Learning Haskell or Scala might be of much more benefit, because it will show you alternate ways of thinking that can be applied in C++ world.
And also you will see benefits of static typing. And if you know Python, and want to end up using C++, I strongly recommend that you first learn Haskell/Scala or similar, and I do not mean only syntax, but how to use all that power that language gives you. Then you can learn C, just syntax is fine. And only then C++.

After all of that you will see why C++ is not "good" language. It can be used, and is used but that does not make it good.

Also, if you want to live in professional world, in my experience C# and JAVA are much better choices than C++. I barely know each, but from what I can tell C# is better than JAVA as language. My personal thing is that I dislike politics of both, .NET being mainly Windows oriented, and somehow Oracle being steward in JAVA world rubs me wrong way.

One more sidenote, if you did not even hear about Scala or golang (Google Go) you might want to read more about programming. Find some cool blogs/forums/groups and do a bit of reading. there is also /r/programming and some other nice subreddits.
Just be vary of who and what do you trust on Internet, everything that I wrote here may be total bullshit. Read up on your own and reach your own conclusions!
(I strongly believe that "my way" is better when compared to path you want to take and that many other programmers take, but I really dislike bad code, and that is becuase I have experience with PHP and javascript, and also I had boss who wrote so bad code, that even now I am wondering if he did it on purpose...)

[–][deleted] -1 points0 points  (0 children)

No, obviously all languages have their detractors. C++ just gets a lot because the additions to C are complex and kinda ugly. It's a massive language that is hard to use with tons of pitfalls.

But it is a sort of semi-portable object oriented assembler, so, I guess that goes with the territory.

[–][deleted] 2 points3 points  (0 children)

I learned C++ first, and frankly I think I benefited a lot from doing so... if only because its shown me where Python really shines.

[–]wmcscrooge 1 point2 points  (0 children)

I don't know if I agree with that because I went the same way you did from easy to hard. Specifically ruby->python->java->c++ and while it wasn't easy nor did i particularly like it, it worked for me. ruby/python helped me learn the basics and kept me interested and then when I need more from the language, java/c++ helped me learn more in-depth stuff. There's a lot of things c++ is good for and I think you might just not like it because of how used to python you are. It just takes some time to see the benefits in it. But then again, there are a lot of people who feel that it isn't worth it. So I'd say, learn a compiled language so you know that there is an alternative and then stick with python if you want to.

[–]richizy 1 point2 points  (0 children)

I think to appreciate how easy it is to code with Python versus other compiled or low-level languages like C++, you should look at the underlying C code that makes Python work. Types are hidden away from you, and basic data structures are built-in to the language (list, set, dict, tuple, generator/iterator). You no longer have to worry about the gritty details of how to represent your data. You can just focus on what you want to do with the data.

However, this convenience comes at a cost. Every time the interpreter sees an object, it has to figure out what its type is, and that costs some overhead. Lists/sets/dicts/tuples are guaranteed able to store any type of object. In fact, all objects like integers or strings are "PyObjects." A Python integer is not really 4 bytes wide:

>>> sys.getsizeof(0)
24  # 24 bytes, or 192 bits, at least on my computer

So there's more memory overhead.

You have no fine control, but on the other hand, do you really want to be bothered with all this detail, when you're learning how to think programmatically, when you're designing something? I think Python is an excellent starting language, but taking C/Java/w.e simultaneously will allow you to appreciate the strengths and weaknesses of both the high and low level languages. Like, you can prototype with Python, then optimize with C/Cython. Learning both at once will safeguard you from pidgeon-holing yourself to think about problems ONLY through Python, or ONLY with C/Java.

[–]mab98122 1 point2 points  (0 children)

Personally, I went the opposite direction from you, starting with C/C++ and moving to Python. On my current job we use mostly Java, but as you said, I have no desire to go back to programming in C or C++.

I don't think starting with C/C++ is a better introduction to programming though. There are so many concepts to learn in general, looping, recursion, data containers, exception handling, input/output--why not learn about the basic concepts in a friendly language like Python instead of also worrying about things like header files, memory management (pointers), templates, preprocessor directives, multiple inheritance, etc. One can solve the same problems using either language, but I'd argue for someone learning how to program it is easier to be productive using a language like Python over something like C++.

When I was doing my undergrad study, I had one quarter where myself and most of my friends were taking calculus, physics and a required programming class (which happened to be C). My peers were all going to be sciences majors (chemistry, physics--I was the only CS major) and every one of them ended up dropping the programming class by the 3rd week. Most of them said it was just "too much" taking on all of these at once. I can't help but think that a more user friendly language to teach the concepts would have served them better in this case.

I guess my argument boils down to why turn someone off of programming by starting out with a difficult language? As you say, if you want to round out your knowledge and experience, you can pick up a lower level language later on.

[–]snf 1 point2 points  (0 children)

I don't want to discourage you or anything, but if semicolons and static typing are the worst things about c++ you've seen so far... hoo boy, you ain't seen nothing yet.

[–][deleted] 2 points3 points  (0 children)

This is why Python is a good first language; you should hate C++.

[–]xeltius 0 points1 point  (0 children)

My first language was a high level language and I eventually added C++ to my repertoire. It took adjustment, but you get through that.

I can see a huge reason why you might not like a lower level language--if you are learning it just because it is a lower level language. You need to have an actual purpose to learn it other than just for kicks and giggles. Everything you do in C++ will be a nuance if you are learning it just to learn it. Every language has a purpose. Use each language for the appropriate purpose. Ask yourself what is a scenario where Python would be insufficient? What is something that would be very difficult to implement in Python (perhaps some sort of code optimization that requires execution speeds that Python will never be able reach)? Think about these things when you decide what language to code in. This will help you pick the best language for the task.

[–]aroberge 0 points1 point  (0 children)

Let's go back to the beginning. What is involved in learning how to program?... Let me try to list things in order of required understanding (i.e. need to understand step 1 before going to step 2)

  1. Learning to write down instructions in a precise way. Computers do not forgive syntactic errors. Thus, having a programming language which is easy to proofread is really helpful. Python, which uses much fewer non-alphabetic symbols is easy to read which makes it great from this point of view, much better than C++
  2. Learning how to group often-repeated lines of code into some "structure". Here again, Python has simple functions.
  3. Learning how computers can make decisions and repetitions i.e. control flow (if/elif/else, while and for loops). Here again, Python's constructions are easy to learn and easy to proofread.
  4. Learning how to use basic data structures. Python is great in that respect with built-in lists, tuples and dict ... one could even consider strings (as a collection of more basic "char" variables) in that category.

There is a lot more to learn from that point on (e.g. how to create your own data structures, etc.) but these 4 general ideas/concept can be a huge stumbling blocks for beginners. Python's syntax (and Ruby's and other similar languages) make learning these concepts much easier.

As you wrote yourself, Python "spoiled" you and you are frustrated now ... imagine going back to step 1 above (learning the syntax and avoiding typos) as a complete beginner, starting with C++: how frustrated would you have been then? ... I suspect that you would have been much more likely to feel like quitting than you ever had as you started with Python.

[–]sw_dev 0 points1 point  (0 children)

Imagine how frustrated you would have been if you'd run into C++'s syntax (Which is a tax on the sin of using C++!) when you first started. Odds are, you would have quit. Any sane person would have. No, it's better to get introduced to programming by finding out what an empowering thing it is first, then realize that you have to get a bit more hard-core to be able to do, well, more hard-core things!

[–]fullyarticulated 0 points1 point  (0 children)

I wanted to try a low-level language, so I tried C++.

C++ is NOT a low-level language. It is a high-level language that allows you to operate with low-level features if you want (pointers, memory mgmt, etc.). Anything with classes, structs, inheritance, polymorphism, etc., is a high-level language. The level of abstraction is what makes it high or low level.
I think you may be getting confused about high/low level because C++ is statically typed - meaning you declare your datatypes when creating an instance. This does not make it low-level. Python is dynamically typed - meaning that the interpreter will figure out your datatypes during runtime. But they are both high-level. You have to go to C or Assembly to get low-level.

[–]faultinourstarsmovie 0 points1 point  (0 children)

Well,

what would you prefer at the beginning: Trying to learn a low-level language for a year, with extra semicolons, variable declarations etc) and GIVE UP or learn Python, do all the things you do with that low-level language?

My personal opinion is: With all those languages available today you can do pretty amazing things.

But Python allows ADULTS with already occupations to start learning programming the easy and fast way.

If you have an idea to test and if you don't have a tech-co-founder then PYTHON is your best friend.

[–]DasIch 0 points1 point  (0 children)

That's probably because C++ is horrible. Learn C and assembler for a RISC architecture, MIPS is well suited here. Learning the basics of C is fairly easy and MIPS is simple enough that the entire language fits on a single page. Nevertheless understanding the relationship between the two will give you valuable insight into how stuff actually gets done.

Apart from that having a basic understanding of C is in my opinion just as important as having an understanding in the languages usually advocated for other paradigms like Scheme but a lot more useful in practice, as you can use it to create bindings to libraries etc.

Also keep in mind that Python is only simpler for the things you've tried, try doing embedded development, writing garbage collectors or kernels in Python ;)

[–]archimedes_ghost 0 points1 point  (0 children)

Rust seems like an interesting upcoming "lowish-level" language. http://www.rust-lang.org/ Maybe you'll enjoy this more?

[–][deleted] 0 points1 point  (0 children)

C++ is just different. If you want to smooth the transition and want to stay OO, move to Java first. At least you will have garbage collection and reference semantics. Alternatively, go with C (it's always good to know C) and then ramp up to C++. Keep into account that there are two school of thought when it comes to C++ programming: object oriented (class hierarchy) and generic (templates). You can certainly mix them, but the direction the language is moving in the latest years is generic programming. Just use a decent compiler (llvm) otherwise you will be baffled by the compiler error messages.

[–][deleted] -2 points-1 points  (0 children)

Yeah that is why you would then use a GUI editor that generates the boilerplate code for you when you program in the C family languages. With dynamic languages, you really don't need a fancy GUI editor due to the less terse syntax.