Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why learn C++

Status
Not open for further replies.

MattSTech

Programmer
Apr 10, 2003
333
US
I have done several searches on the subject and can't find a convincing answer. Please point me to some threads if you find any applicable.

I use VB6 as a hobby. Don't shoot me yet! I understand the concept of programming. I have picked up fragments of other languages here and there. I purchased Visual Studio 6.0 Pro a while back and it comes with a lot of goodies including C++. I use VB6 because it doesn't take 1000 lines of code to make a simple application.

I understand that resource issues have a lot to do with using C++ instead of VB6, but in the days of 4GHz processors and a few GB of RAM what is a few megs here and there? <Perhaps an example where having a 50kb exe will function better than a 2mb exe>

From what I gather C++ can work with parts of windows that VB6 can't touch. What parts? <1 or 2 examples would be sufficient>

Why not C? Isn't C the origin of the universe? Was Windows written in C? Can "I" write a good OS in C? <"I" meaning someone with knowledge vastly exceeding my own>

I don't want to get into a discussion about .NET, I am still about 10 years from upgrading to that. But I would like to know what magical things I could do in C++.

Thank you so much for assistance.

Matt


 
Actually Assembly is the "origin of the universe". :)
Every other compiler was written in some language which was written in Assembly. But since Assembly is ugly and hard to use, C is the next best thing. C isn't object oriented though, so C++ was invented...

I believe VB can use any Windows API function it wants, albeit in a very convoluted way.

I believe most of Windows is written in C, with a bit of Assembly here and a bit of C++ there...

One of the magical things you can do with C++ is create class or function templates. These are classes that hold a specific type of data, but that type is determined by you. For example, C++ has a STL (Standard Template Library) and one of those templates is called a 'vector'. It's basically an array, but much smarter. Declaring vectors of type int and double is as easy as this:
Code:
vector<int>    vInts;
vector<double> vDoubles;
You can look at the list of member functions for vector and other STL classes on the MSDN website, then you'll see all the wonderful things in those templates.
Of course those are templates that someone already wrote. You can write your own templates to make you life much easier too. If you have a bunch of classes or functions that do almost the exact same thing, but just use different data types, that's when templates are a real time saver.
 
Thank you for the very well explained response.

From the little reading I have done about STL containers on the MSDN site it seems I have misjudged the scope of C++.
Example:
I want to search through a database containing roughly a Terabyte of data for the entry "fish sticks". When finished searching I would like to store the results in an array/vector? <I will figure that one out with a little more reading>

Could I use C++ and do this seamlessly and in record time?
I can do this in VB but perhaps not in record time.

I have been told that most C++ programmers rarely create GUI's and all of their work hides in these magical classes (dll's I assume?)

Could I create a little DLL in C++ and call these magical functions from Visual Basic? <I suppose if it were a COM DLL, yes? Does this limit the functionality?>

Perhaps my questions seem off base. I just want to understand the world I am about to jump into. It took me 6 years to get into subclassing and hooking in VB (which I would consider fairly advanced) and I want more functionality even though I do not know for what yet. Thanks again for the response. And taking time out of your day to fill me in.

Matt

 
MattSTech said:
Could I use C++ and do this seamlessly and in record time?
I haven't done any database programming yet, but I'd have to say that almost anything you write in C++ will run significantly faster than it would in VB.
VB is great for writing GUI's, but if you're doing something that is very time intensive, C++ is a better choice.

MattSTech said:
I have been told that most C++ programmers rarely create GUI's and all of their work hides in these magical classes (dll's I assume?)
I've only written a handful of Windows GUI's in C++. Most of the time I write the code that gets called by the GUI, in .exe, .lib or .dll's. A lot of times I write console applications that use a text GUI since it's a lot easier and faster to write.

MattSTech said:
Could I create a little DLL in C++ and call these magical functions from Visual Basic? <I suppose if it were a COM DLL, yes? Does this limit the functionality?>
Yes, you can create a DLL that exports some of your C++ functions, then call those functions in VB. You would use COM or COMish code. The biggest obstical is probably the different data types. VB has a Variant data type that C++ doesn't, so you can't use Variant. C++ has unsigned integer types that VB doesn't have, so 4,294,967,296 might look like -1 in VB.
 
C/C++ is a much stricter language, and works at a lower level than VB Its about as close to machine code as you can get without assembly.

You can pick apart bytes and bits if you need to talk to a parallel port or a network socket. You can write GUIs with MFC without too much trouble.

You can export functions from a dll and call them from VB either as COM/ActiveX things or as 'C' style exports. (No variable argument lists, no 'this' pointer)

In C operators don't change their meaning as much as VB. & is always "bitwise and", and && is always "logical and". (Except when & is used to take the address of something, sorry)

C/C++ has better formatting functions for strings, handles random access file i/o better ( I think )

I don't know if you can do multithreading easily in VB.

VB makes me crazy with their Dim syntax, their On Error Goto..., On Error Resume next, MsgBox sub vs MsgBox() function, etc...... The ONLY thing I like is I can say 10 + " Years Old" and get "10 Years Old" (Or do I have to say 10 & " Years Old")

If you learn 'C' learning javascript is a piece of cake, If you learn C/C++, learning java isn't too bad, but you'll learn more about object orient programmming than you ever did with C++

don't get me started.....!

 
NullTerminator said:
The ONLY thing I like is I can say 10 + " Years Old" and get "10 Years Old"
Well you could overload the operator+() to allow you to do that if you really wanted to... ;-)
 
The C and C++ are tool-making languages: for example, VB (and most of others languages compilers/interpreters) is implemented in C or C++. Now most of operational systems, DBMS etc are implemented in C/C++ too.

Well, if you want a car, buy it and enjoy. But if you want to build a car from the scratch, you need proper tools (and knowledges;).

Yet another example (from the real world;): a simple (but non-trivial;) C++ code packed in DLL attached to VB application may check (and prompt) user form input on the fly because of it's a 1000 (one thousand) times faster than VB code (I have used special data structures and algorithms).

Apropos, C++ COM libraries perfectly well work with famous VB variant data, and languages where 10 + " Years Old" is equal to "10 Years Old" w/o error (at least warning) message are very dangerous tools.

Let's compare army ration and banquet, but it's impossible to maintain an army (of user needs) by luxurious restaurants.
 
Thank you for the responses.

I am trying to force myself to look into the bigger picture here. I bought a book about 4 years ago on Java that got me looking into objects. (I think the book was even called "Java Objects")<Had a smiling woman on the cover>. This seemed very intriguing.

I stopped at roughly page 250 because I didn't know where I was going with it (and I still don't know why she was smiling). I didn't want to learn Java at the time, just objects, and what they were. I am a manufacturing engineer and most of my projects have been simple utilities to make my job easier. Granted, there were several projects that extended into several pages of code. However, most utilized the same concept of going to a DB and grabbing a couple values.

I am making the time investment in C\C++ because I want something more. It seems this is where I should start, so here I go...

Thank you for your time and influence.

Matt
 
Hy

The technical differences between them are known,
or you can easly find them, and other people gave
you informations of this kind. I want evidentiate you
philosophical and applicative differences.

In my work-life I have had to know many languages, timely speaking from Assembly,Fortran,Pascal,Cobol,PL1,Basic,C,C++
MS Visual C++ (a lot of time of difference to learn MFC and Framework) Visual Basic (in itself and as Macro Language of various Applications).
(I never used Java).

Sure the MS Visual C++ has been the more difficult to learn
also if when I have approached it I was more expert than 15 years before.
On the other hand, it is the most powerfull, becouse it includes all the capabilities of the others.

Which to use between VB and C++ ?

I think that there is the same difference between an handicraft and an manufacturer work: an craftsman employs 10 hours to do a job, and when he repeats it, he employs at least 9 hours.

To do the same work in a factory, more than one person are involved to design it (the design is fundamentals building Class) and a lot of money are spent to build prototype and 1st released object.
After this, the 2nd copy of the object has a very little cost, and the time to produce it is pratically zero.

If you have to "sell" your sotfware, maintain it (next releases), be ready to upgrade it at changes of OS, build it in more than one person (of different skill and ability), you must use MFC Classes, build your own classes and give them to your collegue to build tenth of similar forms in a large project.

If you build sw for yourself, using VB, in one day you can produce what you need: using MFC, you can employ 1 week. But if your works has no 1 but 10 forms, similar, that use and reuse routines and similar classes (derived one from the others) you employ only 10 days:
the first 3 to design applications and classes, the second 3 to build them, and the remaining to deploy all. If you build 10 forms doing copy and paste, in one day you may finish, but if you have in future (3 days later!) to review them, to make corrections, you have a lot of
work to do, with high probability to make mistakes or forgetfulnesses in form 7 or 8. If them derive all from 1, just in one place you have to make common changes, as in a factory machine: done one time, next will be the same.

When I worked in BASIC, a program to draw a circle in the video was 1 row long.
If you write it using MFC, you have to write tens of lines and if you explode the code automatically generated, they are hundreds.
The difference is that the old program occupied all video; now you can use other tens of windows on video,
minimize,resize,maximize the win, without write one more line of code.
If you want print it, you have to define just a class more, and you can print it on all types of printers that you can install on your computer (or on the computer of your customer, that you never will see).

Bye



 
Thank you Victor,

I have a quick question of your post.

When using Visual Basic in a large project:
It is possible to store routines and functions that can be used in any forms in a VB created class (ActiveX DLL). I do this quite often to reduce duplicating code.

What benefit does an C++ MFC created class/ library offer over a VB created class besides execution speed?
Perhaps that it is calling/ instantiating an object vs a chunk of sequential code??

Thanks,

Matt
 
I'm glad this question came up. It's about time.

In the old days it was blooming obvious why you used C (or later C++) rather than the Basics that are the ancestors of VB. They weren't in the same league.

Now in .NET, a lot of the heavy work is going to take place in the .NET runtime library, which is exactly the same whether the application is VB or C++. Meanwhile a VB application is efficient and fast, beyond anything dreamt of in an old 64K interpreted GWbasic thing. But an average C++ application is much less pedal-to-the-metal speed-optimised than an old C-applicaton, because most people feel that development time and maintenance are more important than a few seconds processor time (which in any case will be irrelevant next week when processor speeds have doubled again).

If you look at C++, it has some truly horrible syntax, clearly designed for two-finger typists rather than readability. Its error messages are disgracefully unhelpful. It suffers from creeping featurism, with bolt-on unnecessary alternatives for coding the same thing. But millions of programers are experts in using it; perhaps that's why it's the language of choice for serious work? A language is more than just a syntax definition and a choice of compilers; it's a skill-set of experienced users. If you want to be taken seriously by them, you need to learn their tools.

(And incidentally, while I'm on a C++ .NET moan, why does the local help in Visual Studio on Console::Read say you should avoid using it, and substitute Console::ReadLine, while Console::ReadLine says that to make your programing robust you should avoid it and use Console::Read? Any language whose primary helpfile tells you (cyclically!) NOT to use a feature should be wondering whether the feature is correctly implemented)

 
... and to be fair to Visual Studio, there are probably plenty of worse examples out there in other compilers. And the Express version is, after all, free...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top