| Main > Everything Else |
| C++ programing |
| << < (4/7) > >> |
| jbox:
And, to save you a few grey hairs one day, sooner or later you'll have a method which returns an array that looks like this: int[] wrong() { int[20] bob; ... return bob; } and it wont work. In my experience this is probably one of the most annoying errors in C/C++ for beginners because it looks sensible, it often appears to work fine for people over several runs, and then when they finally realise something is wrong they usually look in the wrong place. And the tricky part is trying to explain *why* it's wrong to people who don't know what a "stack" or a "heap" has to do with getting their code to do what it looks like it should do. For the record the correct code should be: int *right() { int *bob; bob = new int[20]; ... return bob; } Almost all of the other things you will screw up are usually obvious *where* you screwed up even if you don't know why, while this one is just one of those lovely little "gotchas" waiting to catch the unwary... |
| Grasshopper:
Jbox's example illustrates one of the problems I have with C++ as a language - its mix of high level and low level concepts. C was originally intended to be a sort of portable assembler for Linux. It's an excellent language (possibly the best) but to use it effectively you have to have some idea of what's going on behind the scenes. C++ is essentially C with OOP extensions added on. There are a few minor differences but 95% of C code seems to run on a C++ compiler without modification. The problem is that Object Orientated Programming is a high level concept that doesn't really fit in with C's get-under-the-hood philosophy. Because of this design mismatch C++ ended up being a messy over-large language with a lot of murky areas. Thanks to poor design C++ is, in my opinion, an unnecessarily hard language to learn. If Stroustrup (sp?) had designed an OOP language from scratch instead of basing it on C he would have ended up with a smaller, cleaner, and more tightly defined language. It was also a missed opportunity for C enthusiasts. There was definitely room for an improved C but C++ wasn't it. Having said that, C++ is still the best OOP language to learn simply because it's so widely used. It's also very powerful once you get past the steep learning curve. |
| Chris:
The problem with learning C first is that you do things in C and C++ in such dramatically different ways that you need to "un-learn" some stuff to go to C++. |
| CCM:
--- Quote from: Grasshopper on December 28, 2006, 06:59:19 am --- C was originally intended to be a sort of portable assembler for Linux. It's an excellent language (possibly the best) but to use it effectively you have to have some idea of what's going on behind the scenes. --- End quote --- C has been around much longer than Linux. It was developed for Unix back in the early 70's. |
| ChadTower:
C was also designed for writing system software, i.e. the operating system and hardware level binaries. It was not written to be "user friendly". I dramatically disagree that you have to "unlearn" anything to move from one language to another. Ever. All concepts do not apply or work optimally in all languages but in 15 years of coding I have never intentionally unlearned anything I have used. C is procedural (often specifically structural like Pascal or Ada). C++ is procedural or object oriented (in a generic manner, again like Ada). The point behind the way C++ works is to provide abstraction from the mechanics of the compiler and preprocessor while still providing most of the system level functionality of C (that a more fully abstracted language like Java doesn't provide). The abstraction is what makes it difficult for a beginner to write advanced C++ since it's not providing the stack/pointer and memory management for you yet you don't always have to do those things yourself like in C. When/where you need to do those things, and when/where you do not, can be confusing and ambiguous for quite some time to a beginner (jbox's example is a perfect one for this). |
| Navigation |
| Message Index |
| Next page |
| Previous page |