Serving the Quantitative Finance Community

 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

C++ or VBA?

June 7th, 2004, 5:15 pm

Could anyone explain to me the relative merits of C++ and VBA ?Thanks.
 
User avatar
daveangel
Posts: 5
Joined: October 20th, 2003, 4:05 pm

C++ or VBA?

June 7th, 2004, 8:33 pm

C++ is a strongly typed object oriented language. C++ supports object oriented features like inheritance (single and multiple), operator overloading. You can also use C++ as a better C if u wished. C++ is fairly unforgiving and must be programmed with care (for example memory allocation and deletion). VB is a flexible tool for building applications and RAD. It is not a strict object oriented language. However, it allows you to build components quickly.
knowledge comes, wisdom lingers
 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

C++ or VBA?

June 8th, 2004, 12:17 pm

Thanks. Could you give some practical examples of things I wouldn't be able to do in VBA.....(not quite sure what inheritance means).
 
User avatar
player
Posts: 0
Joined: August 5th, 2002, 10:00 am

C++ or VBA?

June 8th, 2004, 12:55 pm

inheritanceThink of it like animalsA dog is a mammalAn alsation is a dog.Each one inherits features from the one before.
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

C++ or VBA?

June 8th, 2004, 1:12 pm

Inheritance means taking on the attrbutes of a basic class, and changing them.This may add or remove functionality.I might create a base class Price. This consists of a real number and a currency.This may be used by generic routines that don't care much about what they are dealing with, like a Price display on screen.From it I might derive a BondPrice class, extended to have Yield as a memberIt may contain a constraint that the value may not be negative. Some prices are negative so this is the right level to put this business rule.From this I might derive a IndexLinked class, which has the kind of inflation measure used....and so on.You can of course create a grossly inflated class that contains the 1,000 different fields that a generic bond class may contain.Except it won't.You'll forget one, or the market will evolve some new feature, so you have to constantly fiddle with it. Every time you do so, everyone who uses your code gets screwed. You will have to master the entire bond market, whereas if you let people inherit from a decent base class people who know about each instrument can do what they're best at, without screwing everyone else.For instance I had a rule that prices of bonds weren't negative, but yields may be. You may want to create a class where that can't happen either. Yield is often calculated from price, but you may work in a market where yields are quoted, and people work out the price from that.In VB, you can't do inheritance properly. This makes it harder to build big VB programs and harder for several people to work on the same project at the same time.
 
User avatar
daveangel
Posts: 5
Joined: October 20th, 2003, 4:05 pm

C++ or VBA?

June 8th, 2004, 2:27 pm

You could have a base class called an Instrument say which supports methods like pv(). Then you can inherit from that another instrument say called MoneyMarketDepo which then impleemnts the pv() method for a depo, and you could have a class called FixedLegSwap which inherits from Instrument and implements a pv() method. So if you have a bunch of pointers to Instruments, you can do something like inst->pv() and the appropriate pv() method will be called.to do something similar in VB would require a large Select statment and each time you add a new isntrument u need to make sure that the select statement is chnaged !!
knowledge comes, wisdom lingers
 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

C++ or VBA?

June 8th, 2004, 4:12 pm

So would you say that VBA have any advantages at all?
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

C++ or VBA?

June 8th, 2004, 4:45 pm

VBA as a language ain't that great.However, it is well integrated with Excel, and if you just quickly need to knock something up, there are few better systems than VB.I suppose the analogy is between walking and driving a car. VB is like walking, practically everyone can do it, starting is quick, but over long distances it sucks.A C++ car is faster, but you have to walk to where it's parked, drive it then park it again.There isn't anywhere that you can't go by foot, or by car, but there are some places that are a lot easier if you choose the right one.
 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

C++ or VBA?

June 8th, 2004, 5:23 pm

right - thanks for your responses.
 
User avatar
sound
Posts: 0
Joined: October 10th, 2002, 4:14 am

C++ or VBA?

June 11th, 2004, 4:54 am

VB is like walking, practically everyone can do it, starting is quick, but over long distances it sucks.A C++ car is faster, but you have to walk to where it's parked, drive it then park it again.Plus you got to know or learn to drive well Or with a large project have several good drivers. C++ has a far steeper learning curve.
 
User avatar
Charlie
Posts: 0
Joined: February 7th, 2002, 8:51 am

C++ or VBA?

June 11th, 2004, 5:57 am

Or C#. Not as fast as C++, but so, so easy to develop solutions in, manipulate data into and out of Excel, etc. This is my first anniversary of conversion - (that's my 1 week anniversary!). And I've already coded up far more than i could have done in C++ in such a short time.Charlie
 
User avatar
SPAAGG
Posts: 3
Joined: March 21st, 2003, 1:31 pm

C++ or VBA?

June 11th, 2004, 6:15 am

nice analogy Dominic !
 
User avatar
Jim
Posts: 1
Joined: February 1st, 2002, 5:20 pm

C++ or VBA?

June 11th, 2004, 1:23 pm

VBA is like a plastic picnic knife; C++ is like a surgeon's scalpel. C++ takes longer to learn how to use properly, but very powerful in the hands of a skilled practioner. Its easier to get started in VBA, but as an app gets bigger and bigger VBA just doesn't cut it. On the other hand, if you're not careful with C++, it can leave you permanently disfigured. Moral: Don't do brain surgery with VBA; Don't use C++ to spread the peanut butter.
 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

C++ or VBA?

June 11th, 2004, 2:18 pm

Isn't it amazing how poetic mathematicians can be!
 
User avatar
mckenzieg1
Posts: 0
Joined: June 3rd, 2002, 6:35 pm

C++ or VBA?

June 18th, 2004, 8:20 pm

Most of the above discussion is correct and informative, but it looks like some of the respondents are glossing over the difference between VBA and plain VB.VBA == 'Visual Basic for Applications' is Microsoft's version of Visual Basic that is 'hosted' inside a bunch of Microsoft applications (primarily Office, but also Visual Studio and a few others). If you want to write code that is tightly integrated with one of the Office apps, then VBA is usually the way to go - the VBA development environment is included with the app, the application's macro recorder produces VBA code, and accessing all the features of the app is usually quick and easy. VBA isn't a full-fledged object-oriented programming language by any means, but it does have a decent set of 'object style' features, and it is possible to write a good-sized VBA 'application' that is well-structured and quite maintainable.As others have already explained, C++ is a full-fledged, general purpose object oriented programming language. C++ is extremely flexible, is available on many different platforms and OSes, and is particularly good for low-level, high efficiency work. The main practical problems with C++ are: - C++ is TOO flexible. There tend to be multiple ways to do things, many of which are confusing and bug-prone. (There are two classic books by Scott Meyers, "Effective C++" and "More Effective C++", which are substantially devoted to explanations of how seemingly benign bits of code will break your program in strange and horrible ways.) C++ is not very good at protecting you from your mistakes, and we all make mistakes. - conventional C++ style tends to be dense and obscure. It is possible to write beautifully clear and readable C++ code, but most programmers don't seem to do so. This means that if you are going to work with other people's C++ code, you are should probably expect a very steep learning curve and a lot of tough sledding.If you want a general-purpose modern OO language that is more forgiving than C++, look at Java.If you are coding on Windows (which is the only place you can use VBA anyway, outside of the Macintosh version of Office), then look at C#.NET or VB.NET, which are more or less identical as far as functionality goes, and which have an excellent development (Visual Studio), a rich standard library (not quite as zippy as the C++ STL in terms of algorithms and data structures, but a lot broader and more useful for general purpose application development, since it includes GUI, database, XML, etc.) VB.NET and VBA have similar 'look and feel' as far as basic syntax goes, but VB.NET is a 'real' full-blown OO language, with proper inheritance.The importance of 'raw speed' of programming languages tends to be vastly over-emphasized, IMHO. For most practical purposes, a good development environment and libraries, solid program design and intelligent choice of algorithms are all much more important for producing high-quality, maintainable applications on time and on budget.