I am a beginner programmer in C++, and I still learning the bases, but I have a simple question about The Standard library and STL in C++, I think this is not from The Core of the language, I mean this library just make programming and portability easier, and that mean if I learned and mastered C++ rules, I can build my own, I mean in general this call experience by practicing.
Example: cout is the standard output function, but if I want to program a GUI software for Windows for example, I will never just look at it!!
My Question:Is that True?and if not, Why?
You can't really be said to be a C++ programmer without a good knowledge of the standard library. And writing your own is a very bad idea. I strongly recommend you get a copy of Nicolai Josuttis's book and embrace the power it will give you. You will learn, for example, that streams are not only good for performing I/O in console applications.
And maybe you should also take a look at Good Idea / Bad Idea Should I Reimplement Most Of C++?, which discusses the pros & cons of writing your own standard library.
You are correct that the C++ standard library are not part of the "core language" and that most of what the standard library offers you can be achieved independently using only the features core language.
However, it is much to your advantage to learn the standard library. Why waste time rewriting functions that are already there for you? If you chose to rewrite them anyway, your versions will likely be buggy. That's just one of the truths of software development, no matter how good you are, but more so if you're a beginner to the language. In contrast, the implementations out there are tried and tested in the field.
Looking for Your sample that std::cout is not useful withing GUI programming is not entirely true. Even if You will not use cout it is worth to know std::basic_ostream for simple string formatting abilities.
You won't use everything from the STL, but MAN are those string and container classes, and sometimes the algorithms, useful!
Related
I feel like writing a (rich) text editor mainly to be used for note-taking, in either C or C++, using most probably GTK or Qt for the UI.
The problem is that I can't really decide what to use. I know both C and C++, C a little better. I've never used Qt but I'm completely fine with learning, and I have some experience with GTK.
Is there any particular combination you would give preference to and why? In particular, do you think there is any advantage to using C++, or will C do just fine?
I'm writing an editor myself, and I too have choose C++ and Qt.
The reasons for this:
C++ is CPU- and memory-efficient. I hate slow text editors with a passion.
Supporting libraries are almost always written in C or C++, so I can interface nicely with them (and extend them if needed).
Qt is a great, well supported, cross-platform/-system GUI library, and it contains a lot of generally useful base classes/algorithms. It makes C++ actually fun to use.
Personally, I would go for C++/Qt.
The reason for my bias is that unlike GTK, Qt is not only a UI toolkit, but provides a lot of other features like networking, database access, xml parsing... which could benefit you a lot. And all that with a consistent API.
The main fault of Qt is that it is a replacement for standard C++ library in a sense that it has its own list, string, map, hash... classes. Those have much nicer API than STL and are (IMO) much more pleasant to work with, but if you learn C++ this way, it will be much more difficult to return to standard C++ if you ever need to.
If you want a gentle introduction to OOP with C++ and Qt, see this book (free to download):
http://cartan.cas.suffolk.edu/oopdocbook/
C++ is probably, better suited for RAD (Rapid Application Development) than C. This is because of its additional features such as classes and objects. C I think would just handicap you because, you do not have some stuff like classes and objects.
Usually, OO languages are suited for GUIs and what not whereas, languages like C are for low-level driver stuff where efficiency is of great importance (even though its a little debatable).
C++ is a better C. C++ can do whatever C can do and in addition supports object-oriented and generic-programming design paradigms. 'SUPPORT' here means the language itself and the facilities around it provide ease, pleasure and productivity for the programmer to achieve these design goals. Go for C++ and you won't regret.
If you choose Qt, you must also choose C++ because Qt is a C++ library. If you are programming a rich text editor, I don't know how much it's left for you to do on top of Qt's text editor which well supports rich text. You probably only need to concentrate on adding domain-specific features of your interest.
I about to take some courses in Pattern Recognition.
As i have no prior knowledge in either C or C++, my professors told me to learn a bit of one of them before the course, and learn more when doing the course.
Which one should i pick?
The prior knowledge in programming i have is limited to mostly C# but some PHP, SQL and Prolog as well.
The choice of a low-level language like C or C++ probably means you are into performance at the cost of the development time.
If this is your first low-level language, then learn C. It is simple, robust and proven language, and it allows to write the fast code. It has a decades long record of portability. It is much easier to integrate C code with code written in other languages. With C++ it is too easy to make things wrong. C++ requires much greater degree of language mastery and much more programmer's attention to make things right. While it is possible to write fast code in C++, it's more of an art than doing the same thing in C.
If you have only a few months to learn, then at the end you'll be able to write an OK C code, but this time is simply not enough to get enough experience with C++, hence your C++ code written in the first year or two will be awful.
See, for example, severe criticism of C++ from Linus Torvalds: C++ is a horrible language and C++ productivity. Basically, it boils down to C++ being too complicated even for professional programmers, and C++ code being ambiguous with context-dependent behaviour (this may be considered a higher-level language feature, but it makes more difficult to reason about the performance).
One of the major open source libraries for computer vision, OpenCV, is available both for C and C++, but it is also available for Python, which is a much easier language to get the things done quickly (and also to learn as a first language). BTW, I assume if you manage to offload most of the work to the library, which itself is written in C/C++, the performance cost of Python won't be huge (but generally Python is 10x slower than C).
Stroustrup (inventor of C++) argues that C++ is easier to learn than C:
There will be less type errors to catch manually […] fewer tricks to learn […], and better libraries available.
With that in mind, go for C++.
C and C++ are fundamentally different in the way they approach programming. If you have experience with C#, C++ would be a choice since it is object oriented as well. Also, even though they are different, knowing C++ will let you read (and mostly understand) C code as well. Also, check out this question for some information on the differences between these languages.
I would recommend learning C++ as this probably be easiest if you know about classes etc from C#. Also you can write free functions in C++ but is harder to write classes in C.
A standard library you will likely use is opencv.
C# will set you in good stead to master C/C++. You will probably be able to see through the opencv code examples and understand them.
You can likely get by with enough C you pick up from working through the examples and becoming familiar with them. The focus of the course will be on the algorithms and not how fancy your code is.
Sounds like a fun course! Good luck.
This may seem a trivial question, but it's one that's bothered me a lot lately. Why do some programmers refer to "C++/STL" like it's a different language? The STL is part of the C++ standard library -- and therefore is part of the language, "C++". It's not a separate component, and it does not live alone in the scope of things C++. Yet some continually act like it's a different language altogether. Why?
It's possible to be a competent and experienced C++ programmer and never use the STL. You may be using Boost or ACE, or been an MFC windows programmer for 10 years.
If you want someone experienced in using the STL, asking for someone who knows C++ is no guarantee that you'll get one.
Also for my mind, writing code that's heavily dependent on the STL feels very different to writing, say, MFC code. They might as well be different languages. They certainly won't look particularly similar.
An understanding of the STL isn't necessary to understand C++. It's useful to have when you need ADTs, but you can go (could have gone?) through your whole C++ career without needing it.
The above answers are really good; I'm only going to add to their content in a broader context.
Developers might refer to language/api|library e.g. C/Win32, Java/Struts, Java/Spring, C#/.net MVC because there are in essence two knowledge bases - knowledge of the language in question and knowledge of how to use that specific library, API or framework. Something like Win32 is pretty huge, as is say Django, which I'm currently learning. Django itself works in a very specific way and knowing that is what I'm learning, not Python.
The same is true of C++/MFC or C++/Boost or C++/STL. The language is C++ - the API/library you're using is MFC, Boost or STL.
Probably because STL came a little late to the C++ game, and many people have written code that does not use any STL. For example, think early win32 programming with MFC.
Guess:
When C++ was first released, the STL did not exist. It came into existence later as an optional addition and then was incorporated into the standard.
When writing a resume, people would often list C/C++ as a language, which, in many cases means they don't know either.
Sometime resumes would list "Visual C++" as a language, trying to indicate they don't know what a language is.
This, together with "great knowledge of C++ and PHP" statements, go strait into recycle bin at my firm. Not because they are necessarily bad programmers - but because the interview time waste is not worth it.
My question is: Is learning C++ without learning C enough to program any kind of computer programs and get the computer to it`s maximum level (Full Control except the tasks that need Assembly language)?
Thank you
Yes, there is no point in learning C first if you want to learn C++. They are two different languages and learning C first is not a requirement.
Everything you can do in C you can do in C++ (probably in a safer way too)
I think the important question to ask is 'What do you want to do?'
There are many tasks and situations where neither C or C++ are exactly appropriate. They also present quite a steep learning curve and do not lend themselves to fast results.
If you are starting out I would recommend a simpler language such as Python (or even PHP for web stuff) but don't take my word for it and ask about - form your own opinion.
Knowing C is useful as it lets you know in greater depth what the computer is actually doing, but for the sake of productivity (and your sanity) it's probably best going with something a bit more high-level to start with.
This reminds me of the question "Should I learn driving with manual transmission (stick shift) to drive a truck or automatic transmission to drive a car". Different skill sets and usage really. With C you "think" procedurally. With C++ you "think" of Objects. Your entire program is structures differently. True, the "syntax" of C++ is a super-set of C but these are really two different languages. Because most C++ compilers also compile C code, there is a common misunderstanding that C++ is just an extension of C. This is only true about the syntax not the concept. For example, you use the same alphabet to write in English and French but the languages are very different.
I hope this helps.
C++ is a great place to start and yes, you can do everything with it. There's no advantage to learning C unless you are planning on working on platforms where it is particularly well suited, such as embedded electronics.
If you master C++ as a language and the OO concepts behind it you will have no difficulty picking up any other programming language. What's more you'll have a much better appreciation for memory management than you would get if you started with a slightly higher level language such as Java.
Good luck.
I think it all depends on the platform you wish to develop for.
If you want to develop applications on the Mac or iPhone you need to use the Cocoa and Cocoa Touch frameworks which are (mostly) written in Objective-C.
If you want to develop games for most consoles you need to use the native frameworks which are almost all written in C++.
I'm not sure what the Windows frameworks use, but I'd guess at C++.
The language you use is secondary to the frameworks you'll need to use for the platform you're developing for.
Yes, C++ is (pretty much) a superset of C
C++ is include all of C features and more other features like the support of OOP, so the answer is Yes you can.
it's different languages..
chose depending that you want to do...
Yes, you can start learning C++. Start with non-OOP part of C++, which is similar to C. Then you can move to the OOP part. Most of the books teaching C++ from ground up follow this approach.
me just learn c++ but
no problem in understanding c
c++ is much more supportive and safe than c.
although it is a puls puls version...
C++ is all that C is, and then more, so using C++ will not prevent you from doing anything with the computer that you can do in C (although it will in some cases prevent you from writing what in C would normally be an error in any case because C++ compilers use stronger type checking).
Now with respect to "Full Control"; there are some tasks that are the responsibility of the OS, and modern OS's will prevent you from having full control at user level (because processes have to play nicely together). Of course if you are coding for an embedded target, or writing a bootloader or OS, or a kernel mode driver, then you do have full control; and that is why C and C++ are used predominantly for such tasks because they are intrinsically systems-level languages.
I think any language is just medium of expressing one's logic, the main thing is your logic which needs to be perfect. First of all you must understand what are the features that could be explored in C++ that are not available in C.
C is known for its simplicity. If you start learning C, you will very well understand that how crisp and clear this language is. However, it is not a compulsion that you should learn C first and then C++; Its just a recommendation.
Learning C first is like playing level 1 of a game, where C++ is level 2 :-)
Having said that you can always play level 2 directly and can equally succeed in that, but with a little difficulty. :-)
I started by learning C++ and it was fine.
However it wouldn't hurt to have a browse through C before diving into C++. Loosely speaking C is a subset and you will learn the fundamentals there. C++ tends to have some tricky topics to grasp so you'll be safer by having strong foundations.
If you are starting programming, I would say start with C. It will give many basics and will let you think in a more low-level way than starting C++. You do not need to be the boss in C, just get the basics that will help in the future.
There is a nice article written by Joel Spolsky (joelonsoftware.com) that talks about how to start.
Since I have been mostly using script languages in the past time but now want to go to the "high-performance" level I decided to learn C++ some time ago.
I looked at some "beginner" tutorials and bought an O'reilly C++ pocket reference book (it's really helpful). My problem is that I now know all the basics but I'm not good enought to program a more complicated game, for example, yet.
Do I have to get one of those thick C++ books for further learning?
I'm going to use C++ on Windows mainly. What APIs beside Win32 are important for me?
My goal would be to write a small interpreter for a programming language I've though of - I managed that in several scripting languages already, what API/Library knowledge do I need in C++ to write one?
You don't need a thick book - you need a good one. Get Accelerated C++, written by Koenig & Moo, two of the original C++ development team.
Depends what you want to do.
You don't need anything - you can write a perfectly good interpreter or compiler using just the C++ Standard library. See this SO question for lots of info in this area.
Learn with books. C++ is a complex language. My suggestion is to first go with a rather quick introduction and general overview of the major programming paradigms that C++ supports: OOP and generic programming: Accelerated C++.
When you finish this book, you can go with the two volumes of Bruce Eckel's Thinking in C++ which are very detailed.
For UI programming, the best C++ toolkit is Qt, and it is multiplaform-ready. You can read "C++ GUI Programming With Qt4" (the first edition is free to download, just google it). If you want to stick with C++/Windows API, learn the Windows Template Library, altough it may be a bit hard due to lack of official documentation (altough there are good tutorials on the net). WTL is the way to go to create very small, lightweight applications (Qt DLLs on the other side, need a few MBs each).
I have always found that learning a language from a book is pretty difficult and that after you know the basics you should begin to program. So instead of picking up a thick manual I would check out something like http://www.cprogramming.com/tutorial.html#advanced or just google for c++ tutorial and something that you would like to try to make.
A good (and) thin book to get started in C++ is Accelerated C++ by Koenig and Moo.
I mainly do programming under Linux, but I hear a lot of bad things about MFC, so I'd try to find a different GUI library.
Once you get up to speed with some of the more complicated parts of C++ syntax, have a look at the Boost.Spirit libraries for parser generation. The various Boost libraries provide some very useful extensions to the Standard Library.
Honestly, In learning C++ i never picked up a book (no flaming please). The best advice i can give is to go to this page and go through the tutorial. It covers the majority of the C++ language (read: most commonly used features) and keeps it as simple as possible. As far as APIs that are important... well that is a matter of preference. No one toolkit/api has really "won", but Qt, GTK-- (gtkmm), and wxWidgets are all big players. And besides GUIs, you'll probably want to learn either the raw winsock2 and threading APIs OR the boost library's threading and network interfaces. I do agree that MFC is dying, and for windows-only development C# is taking an increasingly large role (even on linux/mono C# is starting to catch on... slowly).
Also, the best way to learn a language is to code. So don't just read a whole ton- without practical experience you're never going to learn the language. Ask questions, answer those you can, and write tutorials- for yourself if nobody else. Writing down what you've learned is a great reference, and the process of straightening everything out in your head to write it down in a fashion that another person can understand it alone is a great way to reinforce concepts. In a strange, but seemingly backwards, way I found the best way I learn programming is by helping other people with their questions.
#Neil- i disagree that online tutorials are "flat out wrong". If anything, the style they teach you might be geared towards readability rather than optimization- which in-my-not-so-humble-opinion is an advantage. In my limited experience I've found cplusplus.com a go-to reference for pretty much everything.
Specifically, to answer your questions:
1. No thick book needed. I've heard that the thinner ones can be useful as a quick reference, though.
It's completely subjective and depends on your goal. Boost's network and multithreading libraries are probably a good start.
between std::string, std::stringstream, and getline(std::istream&, std::string&) you should be pretty good. C++ comes with a whole ton of built-in functionality yet isn't too bloated/huge/impossible to learn. Take advantage of it. All of the parsing is built in already.
Please, for Pete's sake, don't use directly use the Win32 API. You'll be painting yourself in the Microsoft corner. There are plenty of cross-platform libraries out there you can use instead:
Standard C++ library: strings, file i/o, containers, algorithms
Boost for the everyday stuff they left out of the standard library: parsing, networking, threading, smart pointers, memory pools, date/time, matrices, etc... Boost libraries are peer-reviewed before being accepted and are high-quality. Boost is the breeding ground for libraries that eventually become part of the next C++ standard.
GUI Toolkits: Qt and wxWidgets are very mature and widely used. There are many more.
For C++ on windows, definitely learn Microsoft Foundation Classes (MFC). Without MFC, you have to implmenet all of the windows API stuff yourself, which is more C than C++ and can be quite a pain.
You also may want to get, learn, and use the boost C++ libraries. They aren't windows specific, but they are a great resource for anyone.
I highly recommend Stroustrup's Intro C++ book. It covers C++ and STL in a very approachable way.
After that you might consider looking into books on Qt, a multi-platform GUI toolkit, or WTL or MFC for Windows. You could do .NET + C++, but that would be a lot to learn. In my experience with Qt and MFC, books have not helped much. Tampering with sample apps, building small apps just to test out one kind of feature, and poking around the docs was the only way I could get my head around either library. The books I had tended to simply gloss over too much--they were not worth the money.