Why I like C++
-
I have been turning away from .Net lately and looking for alternatives. I don't want to have to rewrite everything when a certain company heads into a different direction once more. My answer is C++. I always liked its flexibility to allow you to do very low level programming just as well as very high level programming. And today I stumbled over this video[^], in which Bjarne Stroustrup answers two simple questions. Now I know why I like C++ so much. Thanks, Bjarne.
I like C++ because it's challenging, powerful, flexible and allows me to get closer to the hardware and yet it still allows me to write elegant code. C++ is like a crude tool that allows the artist to create a master piece.
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia
-
Martin.Cheng wrote:
Can somebody give some advises how to learn C++
Five steps: 1) Learn C, especially how to write functions. A C++ object's methods work very much like C functions. You will be able to use your experience with C here. 2) Learn about object orientation by understanding the concept. The way the concepts are implemented in C++ (or any other language) are secondary at the moment. Begin with understanding what an object actually is: A data structure with attached functions to allow safe manipulation of the data inside that structure. 3) Learn the difference between a class (the definition) and objects (individual instances of a class). That will lead you to learning about the basic lifecycle of an object. Allocation of memory and automatic execution of the constructor when you create a new object with 'new', and automatic execution of the destructor and freeing memory when you destroy an object with 'delete'. Despite their somewhat scary names, constructors and destructors are just functions which are called automatically when you create or destroy objects. It's very important that you learn to use them to initialize or clean up an object. 4) Learn to use encapsulation to divide up the internal state of an object and its external interface. Other objects can only access methods or member variables of an object which you have declared as 'public'. They get no access to the members you declare to be 'private'. This way you can limit how the object's state is altered from the outside and keep it valid at all times. Limitations and restrictions may sound like a bad thing, but in reality they are your best friend. 5) Learn how to use inheritance and how to design class hierarchies. It's a powerful instrument for writing type safe code and avoiding redundancy. It is also an instrument you have to learn to play well, because it can also quickly lead to bad design. Speaking of bad design: C++ allows classes and functions to be 'friends' of other classes. That actually means breaking the encapsulation. Like feeling the need to use 'goto', it's a sign that you should rethink your design.
For Martin Cheng: I would like to add that Points 2,3,4,5 are very, very important if you really want to get the most out of C++ and not fail later down the line. All of the points mentioned are aspects of "object oriented" analysis/design/programming and I would recommend learning this in parellel with C++ from good, well written, and proven sources. Booch, Yourdon, etc. and will almost certainly mean learning UML if you do not already know it depending on what books you pick up. A good design book, & the "patterns" books by the gang of four and martin fowler, are especially handy to understand heirarchies and what C++ gives you above C, but be prepared to criticise and ignore them completely in practice if need be. Finally, try desperately to get "real world" problems and practice, practice, practice. Small things like sorting algorithms, queueing mechanisms, even simple mutex controls, up to practical but low level tasks like neural net engines, file format conversion engines, etc (Concentrating on the core objects underneath the guis/cli). before you know it you will feel that nothing is impossible and nothing outside of your ability... It's a great language. go for it....
-
Oh, It's unbelievable that there are responses for my questions! Thanks for the suggestions, really! Actually, I have got the concepts things about C++, like objects, hierarchies things. I guess I am lack of some projects experiences. Even I got the concepts about it, I have no idea how to use them in programming. It might be the more practices make it perfect. I have to spend much time on it and use C++ times and times. Anyway, thanks a lot! Buy the way, I red effective C++ recently. It talks about STL and boost things. I almost program with BOOST and STL library every day. They are important for the C++, aren't they ?
Martin.Cheng wrote:
Actually, I have got the concepts things about C++, like objects, hierarchies things. I guess I am lack of some projects experiences. Even I got the concepts about it, I have no idea how to use them in programming. It might be the more practices make it perfect.
You have sensed the trouble; lack of experience. If you cannot apply concepts like object orientation, you don't really understand them yet. You should therefore stop saying, "I get the concepts." You should ask questions like, "How do I learn to view a project as a collection of objects?" or "How do I decide which operations are closely enough related to put into a single object?" For the first question, I personally very much like the work of Rebecca Wirfs-Brock (search "Wirfs-Brock" on amazon) on class roles and collaborations. I used Designing Object Oriented Software to teach a team of C developers OOP, but I suspect the more recent titles are also good. For the second question, much as been written on the web on "separation of concerns" and "dependency injection". But as a practical matter of learning, you should start writing module tests for each class you write. Nothing slims down your classes like having to test all the interfaces and import all the dependencies into each test case.
-
I have been turning away from .Net lately and looking for alternatives. I don't want to have to rewrite everything when a certain company heads into a different direction once more. My answer is C++. I always liked its flexibility to allow you to do very low level programming just as well as very high level programming. And today I stumbled over this video[^], in which Bjarne Stroustrup answers two simple questions. Now I know why I like C++ so much. Thanks, Bjarne.
In short, I think there are way better alternatives for .NET developer then C++. Speaking for myself, if I ever was to move away from .NET, it would only be to another "managed" language - Java, Python, Ruby, PHP, etc. Java still scores #1 on Tiobe index after all, and I don't see it changing anytime soon. It feels almost like C# 2.0 ;P so it won't be too hard moving to Java and Android development, I would miss LINQ dearly tho :( . I agree wholeheartedly on the definition of C++ as crude tool which is still perfectly viable to create masterpieces with. The problem is, that it's way too easy to become addicted to comfortable refined tools and become dependent on them. Moving from .NET to C++ feels like moving from comfortable city apartment with electric lights, hot water and other conveniences along with modern city infrastructure to stone cave in a middle of wilderness with only wooden stick in hands :) I know the language, and if asked to write something in C++, I will do it and will try my best to do it good - but I will hate every moment of writing C++ code with a passion. The only "native" language I will ever try is Objective-C (Josh Smith's experience on the matter is quite encouraging), and this is only if someone gives me iMac AND iPhone as a gift, because Apple computers are ridiculosuly overpriced in my country. Android development has one distinct advantage over iOS development tho - if Google does something incredibly stupid and kills Android and/or abandons Java, you can still just go and write Java elsewhere, while Obj-C is neither wanted nor needed by anyone outside of Apple and I have a distinct feeling that people are only using it because it's the only option for iOS developemnt (read: because Apple forces it down their throats ;P ) and they will be happy to forget it when/if Apple ship drowns.
-
In short, I think there are way better alternatives for .NET developer then C++. Speaking for myself, if I ever was to move away from .NET, it would only be to another "managed" language - Java, Python, Ruby, PHP, etc. Java still scores #1 on Tiobe index after all, and I don't see it changing anytime soon. It feels almost like C# 2.0 ;P so it won't be too hard moving to Java and Android development, I would miss LINQ dearly tho :( . I agree wholeheartedly on the definition of C++ as crude tool which is still perfectly viable to create masterpieces with. The problem is, that it's way too easy to become addicted to comfortable refined tools and become dependent on them. Moving from .NET to C++ feels like moving from comfortable city apartment with electric lights, hot water and other conveniences along with modern city infrastructure to stone cave in a middle of wilderness with only wooden stick in hands :) I know the language, and if asked to write something in C++, I will do it and will try my best to do it good - but I will hate every moment of writing C++ code with a passion. The only "native" language I will ever try is Objective-C (Josh Smith's experience on the matter is quite encouraging), and this is only if someone gives me iMac AND iPhone as a gift, because Apple computers are ridiculosuly overpriced in my country. Android development has one distinct advantage over iOS development tho - if Google does something incredibly stupid and kills Android and/or abandons Java, you can still just go and write Java elsewhere, while Obj-C is neither wanted nor needed by anyone outside of Apple and I have a distinct feeling that people are only using it because it's the only option for iOS developemnt (read: because Apple forces it down their throats ;P ) and they will be happy to forget it when/if Apple ship drowns.
MetalNate wrote:
Moving from .NET to C++ feels like moving from comfortable city apartment with electric lights, hot water and other conveniences along with modern city infrastructure to stone cave in a middle of wilderness with only wooden stick in hands
I loved your analogy, it cracked me up :laugh: But I think you may be missing one point. You don't need to move away from .net to use C++. It's just another tool to be used for another job. A lot of you want to do can be accomplished by both, but many tasks are better accomplished with one tool rather than the other. For example, you can't go to managed language if you're designing a kernel-mode driver. Or you can use an unmanaged component for your managed framework to perform performance dependent task. Say you're developing a real time image processing application. Chances are that you'd be better off with C++ (not saying it's the only option). One thing that I love about C++ is how it integrates easily with native hardware instructions, you can even have pure assembly instructions inside a C++ code block :rolleyes: It's so amazing that it's quite rewarding when you see blinking hardware lights just the way you programmed it to. It's a very satisfying experience. I had the opportunity to interface with hardware through C# and .net, but it is not the same thing and you can only go so far. Of course, using C++ to develop a full blown enterprise application with rich UI can be really, really painful. That's why you should always choose the right tool for the job. And I just love when the right tool for the job is C++ :)
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia
-
You may or may not like C++. But you can't just "turn away from .NET to C++". This is like you said "I am turning away from gasoline, since I do not want to depend on all of that oil stuff...". C++ is just a language, .NET is a eco-system of many languages, infrastructure, libraries, tools etc. If you rely on that, the language itself does not matter, but the presence of this infrastructure does.
paul_71 wrote:
you can't just "turn away from .NET to C++".
I disagree. To a significant extent, the world may be divided into projects that choose to live within a humongous infrastructure such as .NET, and projects that stand alone, importing smaller bits of third-party code when they seem relevant. .NET is very much a lifestyle choice. Many C++ projects exist because they have chosen to steer clear. .NET is 10,000 twisty little objects, all alike, and yet all different. Not all parts of .NET are equally well designed, and none of it is brilliant. It's a big infrastructure built by a big team in a big hurry. C++ is around 50 keywords, and a standard library with around 50 template classes. You can get to know all of it. All of C++ compiles to machine code. You can reason about the performance of every bit. The STL is genius, now copied by other popular languages. The people who don't like C++ because it doesn't come with a standard library having 10,000 functions don't get C++ at a fundamental level. C++ is useful because of the extent to which it is stripped down to essentials. You can't write a web browser in 10 lines of C++ code by invoking the WebBrowser object like you can do in .NET. C++ is for the guys who want to implement that WebBrowser object, and who need for it to run at a competitive speed.
-
MetalNate wrote:
Moving from .NET to C++ feels like moving from comfortable city apartment with electric lights, hot water and other conveniences along with modern city infrastructure to stone cave in a middle of wilderness with only wooden stick in hands
I loved your analogy, it cracked me up :laugh: But I think you may be missing one point. You don't need to move away from .net to use C++. It's just another tool to be used for another job. A lot of you want to do can be accomplished by both, but many tasks are better accomplished with one tool rather than the other. For example, you can't go to managed language if you're designing a kernel-mode driver. Or you can use an unmanaged component for your managed framework to perform performance dependent task. Say you're developing a real time image processing application. Chances are that you'd be better off with C++ (not saying it's the only option). One thing that I love about C++ is how it integrates easily with native hardware instructions, you can even have pure assembly instructions inside a C++ code block :rolleyes: It's so amazing that it's quite rewarding when you see blinking hardware lights just the way you programmed it to. It's a very satisfying experience. I had the opportunity to interface with hardware through C# and .net, but it is not the same thing and you can only go so far. Of course, using C++ to develop a full blown enterprise application with rich UI can be really, really painful. That's why you should always choose the right tool for the job. And I just love when the right tool for the job is C++ :)
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia
I have never been involved in writing kernel-level software, software for microcontrollers, or game development, so I think I just never got to harness full power of C/C++ in it's natural sphere of application. My only encounter with C++ apart from university was with "full blown enterprise application with rich UI" (although it did use some 3D data visualization), and I guess this took it's part in forming my bias against it :-D
-
I have never been involved in writing kernel-level software, software for microcontrollers, or game development, so I think I just never got to harness full power of C/C++ in it's natural sphere of application. My only encounter with C++ apart from university was with "full blown enterprise application with rich UI" (although it did use some 3D data visualization), and I guess this took it's part in forming my bias against it :-D
MetalNate wrote:
I have never been involved in writing kernel-level software, software for microcontrollers, or game development
It's a shame, but I think you should give it a try, it's a lot of fun. Personally I'd recommend playing with an arduino device just for the fun of it.
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia
-
C++ is just a language lol, that's funny, I though it was THE language. what is .NET written in btw?
-
MetalNate wrote:
Moving from .NET to C++ feels like moving from comfortable city apartment with electric lights, hot water and other conveniences along with modern city infrastructure to stone cave in a middle of wilderness with only wooden stick in hands
I loved your analogy, it cracked me up :laugh: But I think you may be missing one point. You don't need to move away from .net to use C++. It's just another tool to be used for another job. A lot of you want to do can be accomplished by both, but many tasks are better accomplished with one tool rather than the other. For example, you can't go to managed language if you're designing a kernel-mode driver. Or you can use an unmanaged component for your managed framework to perform performance dependent task. Say you're developing a real time image processing application. Chances are that you'd be better off with C++ (not saying it's the only option). One thing that I love about C++ is how it integrates easily with native hardware instructions, you can even have pure assembly instructions inside a C++ code block :rolleyes: It's so amazing that it's quite rewarding when you see blinking hardware lights just the way you programmed it to. It's a very satisfying experience. I had the opportunity to interface with hardware through C# and .net, but it is not the same thing and you can only go so far. Of course, using C++ to develop a full blown enterprise application with rich UI can be really, really painful. That's why you should always choose the right tool for the job. And I just love when the right tool for the job is C++ :)
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia
-
Oh, It's unbelievable that there are responses for my questions! Thanks for the suggestions, really! Actually, I have got the concepts things about C++, like objects, hierarchies things. I guess I am lack of some projects experiences. Even I got the concepts about it, I have no idea how to use them in programming. It might be the more practices make it perfect. I have to spend much time on it and use C++ times and times. Anyway, thanks a lot! Buy the way, I red effective C++ recently. It talks about STL and boost things. I almost program with BOOST and STL library every day. They are important for the C++, aren't they ?
Martin.Cheng wrote:
Actually, I have got the concepts things about C++, like objects, hierarchies things...Even I got the concepts about it, I have no idea how to use them in programming.
Well then you don't actually understand the concepts. As I recall it took me about 2 years to figure out how to apply objects to designs in C++ after I figured out the syntax of classes in C++. Before that I was still doing structured programming rather than object oriented programming even though I was using C++ (and classes.)
-
Oh, It's unbelievable that there are responses for my questions! Thanks for the suggestions, really! Actually, I have got the concepts things about C++, like objects, hierarchies things. I guess I am lack of some projects experiences. Even I got the concepts about it, I have no idea how to use them in programming. It might be the more practices make it perfect. I have to spend much time on it and use C++ times and times. Anyway, thanks a lot! Buy the way, I red effective C++ recently. It talks about STL and boost things. I almost program with BOOST and STL library every day. They are important for the C++, aren't they ?
I have a couple of suggestions based on my experiences. Although you may think you got everything, it's more likely that you don't. Practice says more than theory. I remember myself that one day it hit me: "AHA!!!". It was like that, from one day to the other everything made sense. The problem is that it's very difficult to get to the "AHA!!!" moment, but I do know that the fastest way to get there is by having real world experiences. I don't think you should learn object oriented design through C++ as many of its little nuances can get in the way of learning the real deal which is object oriented design. I'd say to go with C# first if you want to learn OO design. Now, there are a few steps I'd suggest you to take: 1 - Read open source code of well designed OO applications. If you look around it shouldn't be hard to find. 2 - Design a real OO application, with its own domain model layer, with all objects that contain both data and behavior, completely separated from user interface or data access layer. You can get a lot of ideas from open source projects and design pattern books. Try creating an application for someone you know that run a small business, for free, as an experimental project. 3 - Publish the code so people can give you their opinion and point out where you went wrong and where you did right. Here is where the real learning will occur. 4 - Port your application to C++ Just an idea of what I believe is a good way to learn OO C++
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia
-
paul_71 wrote:
you can't just "turn away from .NET to C++".
I disagree. To a significant extent, the world may be divided into projects that choose to live within a humongous infrastructure such as .NET, and projects that stand alone, importing smaller bits of third-party code when they seem relevant. .NET is very much a lifestyle choice. Many C++ projects exist because they have chosen to steer clear. .NET is 10,000 twisty little objects, all alike, and yet all different. Not all parts of .NET are equally well designed, and none of it is brilliant. It's a big infrastructure built by a big team in a big hurry. C++ is around 50 keywords, and a standard library with around 50 template classes. You can get to know all of it. All of C++ compiles to machine code. You can reason about the performance of every bit. The STL is genius, now copied by other popular languages. The people who don't like C++ because it doesn't come with a standard library having 10,000 functions don't get C++ at a fundamental level. C++ is useful because of the extent to which it is stripped down to essentials. You can't write a web browser in 10 lines of C++ code by invoking the WebBrowser object like you can do in .NET. C++ is for the guys who want to implement that WebBrowser object, and who need for it to run at a competitive speed.
actually coding in .NET (or Java or PHP or bash or whatever..) feels a lot like any other of the occasional obligations I have as a C++ programmer to delve into the idiosyncrasies of the diverse 'ecosystem' I work in, which might include a million other 'packages' that exist, like UTF-8, SMB, TCP/IP, RS232, USB, HTML, JavaScript, GWT, SQL, lambda calculus, the visitor pattern or a Logo tortoise. but at the core of this ecosystem is the project itself with resources, objectives and requirements that (for usually good reasons) exclude the use of Java or PHP or bash or (in extreme cases) computer science itself and mandate coding in C or C++. all there is (apart from silicon, wire and electrons) is a compiler. and where did the compiler come from? somebody ported it using C or C++ and a bit of assembler. at the end of the day, I find the real challenge comes when I have to 'turn away from' C++ and use C, or 'turn away from' from boost and use STL, or 'turn away from' templates and use macros or 'turn away from' OpenGL and use DirectX or 'turn away from' BSD and use GPL. turning away from .NET feels like ignoring the existence of a cow in a paddock down the road. it's there. it might provide me with milk or butter one day, but I don't really need it unless I need it. it goes moo.
-
Oh, It's unbelievable that there are responses for my questions! Thanks for the suggestions, really! Actually, I have got the concepts things about C++, like objects, hierarchies things. I guess I am lack of some projects experiences. Even I got the concepts about it, I have no idea how to use them in programming. It might be the more practices make it perfect. I have to spend much time on it and use C++ times and times. Anyway, thanks a lot! Buy the way, I red effective C++ recently. It talks about STL and boost things. I almost program with BOOST and STL library every day. They are important for the C++, aren't they ?
Don't worry. It's really a lot of things you get to hear about and it all must be very confusing. That's why I told you to start with understanding the intentions behind object orientation. The problem with all books, design patterns or libraries is, that they all solve problems you have not encountered yet. You can believe them or not, but simply using them as you are told will not help you understand more. Start writing a small C++ program and try to do it with as little help as possible. Try to rely on what you have learned so far and do things as you think they should be. To be honest, you will probably run into problems every step on the way and your solutions may not be the best. Yet. The good thing is, that each problem will be an opportunity to gain some experience by solving it yourself. At first this may be very frustrating, unless you keep in mind that this is just an excercise. Be proud of every victory, as small as they may be in the beginning, They will lead you to the things you must think about next and after a while books will become helpful again. Once you have understood a problem, you also have a chance to understand a solution.
-
I have been turning away from .Net lately and looking for alternatives. I don't want to have to rewrite everything when a certain company heads into a different direction once more. My answer is C++. I always liked its flexibility to allow you to do very low level programming just as well as very high level programming. And today I stumbled over this video[^], in which Bjarne Stroustrup answers two simple questions. Now I know why I like C++ so much. Thanks, Bjarne.
I like C++ as it let's me do my job without getting in the way, either trying to help me or, heaven forbide, try to protect me.
-
Martin.Cheng wrote:
Actually, I have got the concepts things about C++, like objects, hierarchies things. I guess I am lack of some projects experiences. Even I got the concepts about it, I have no idea how to use them in programming. It might be the more practices make it perfect.
You have sensed the trouble; lack of experience. If you cannot apply concepts like object orientation, you don't really understand them yet. You should therefore stop saying, "I get the concepts." You should ask questions like, "How do I learn to view a project as a collection of objects?" or "How do I decide which operations are closely enough related to put into a single object?" For the first question, I personally very much like the work of Rebecca Wirfs-Brock (search "Wirfs-Brock" on amazon) on class roles and collaborations. I used Designing Object Oriented Software to teach a team of C developers OOP, but I suspect the more recent titles are also good. For the second question, much as been written on the web on "separation of concerns" and "dependency injection". But as a practical matter of learning, you should start writing module tests for each class you write. Nothing slims down your classes like having to test all the interfaces and import all the dependencies into each test case.
Thanks again. It 's quite boring reading book without implement project, isn't ? :sigh: It was supposed to be a tool or a manual when I got some problem. I will follow your suggestion anyway, spending much time to read the book and practicing more~
-
Thanks again. It 's quite boring reading book without implement project, isn't ? :sigh: It was supposed to be a tool or a manual when I got some problem. I will follow your suggestion anyway, spending much time to read the book and practicing more~
Martin.Cheng wrote:
It 's quite boring reading book without implement project
This is always the problem for learning. If you are lucky, some employer will let you learn on their time. Otherwise, there's nothing to do but try to think of some sufficiently interesting thing to code on your own time. Best of luck.
-
Martin.Cheng wrote:
Actually, I have got the concepts things about C++, like objects, hierarchies things...Even I got the concepts about it, I have no idea how to use them in programming.
Well then you don't actually understand the concepts. As I recall it took me about 2 years to figure out how to apply objects to designs in C++ after I figured out the syntax of classes in C++. Before that I was still doing structured programming rather than object oriented programming even though I was using C++ (and classes.)
I had been there months before. I use C++ as C, hah~ It's quite wired. So I have this kinda confusion and post here for suggestions. ;P
-
Oh, It's unbelievable that there are responses for my questions! Thanks for the suggestions, really! Actually, I have got the concepts things about C++, like objects, hierarchies things. I guess I am lack of some projects experiences. Even I got the concepts about it, I have no idea how to use them in programming. It might be the more practices make it perfect. I have to spend much time on it and use C++ times and times. Anyway, thanks a lot! Buy the way, I red effective C++ recently. It talks about STL and boost things. I almost program with BOOST and STL library every day. They are important for the C++, aren't they ?
Boost and STL are great until you try to see what is inside the structures when the program crashes. Some debuggers are intelligent enough to be able to print the contents of collections. In many of them, it is just an undecipherable structure so you have to pick through the STL/Boost bit to see how it was implemented and then work out how to check the values in the debugger. Picking through template libraries can be really painful: why do the writers insist on using one or two letter variables with leading underscores? Were these written by two finger typists?
-
Martin.Cheng wrote:
It 's quite boring reading book without implement project
This is always the problem for learning. If you are lucky, some employer will let you learn on their time. Otherwise, there's nothing to do but try to think of some sufficiently interesting thing to code on your own time. Best of luck.
I am supposed to be the lucky one and the project are not that emergency that I can spend more time on studying. Anyway, nobody want to wast time on the wrong direction, is that right?