Learning c++ via vb.net and object-oriented programming

In most cases, the idea of programming is all the same. What makes it difficult is learning a particular language with all its different syntax, commands, etc. Like real-world cultures, people speak different languages, but everyone needs to eat and poop, except the words for those might differ from culture to culture. Even if there were no language differences, I’m sure one could still gesture, if considered obscene but still get the point across. If you could pick up those cues, then you’ll see that most cultures are the same. So let’s take a look at similarities between c++ and vb.net…

I’m studying Nokia’s QT framework (pronounced “cute”), which is based on c++, and it’s overwhelming because I’m self-taught in vb.net. What attracted me to QT was that is was cross-compatible with many operating systems: Windows, Mac, Linux, etc. If you seriously want people to use your software, you need to make is as accessible as possible. In my case, I have to learn c++. Granted Microsoft’s .Net Framework is incredibly easy to use, I just won’t be able to distribute my vb.net apps to non-Windows users. Plus, I don’t think it’s convenient to have users download the 300+ Megabyte framework, plus the compiled app itself, if they don’t already have it. With QT, you distribute only what your app references, therefore making your distribution truly standalone.

The first thing I notice about c++ implementation is that is doesn’t automatically hook up event handlers like vb.net. In c++, you have to create a reference to the function first, then make a call to it in the “main” function. If the main function made a call to a non-existent function before it, there would be a compiling error. In this sense, c++ is truly object-oriented. Everything is meticulously step-by-step. No wonder, there’s a quote floating out there amongst c/c++ programmers, something like, “If you mess up in c#, you shot yourself in the foot. If you mess up in c++, you lose your leg.” Yowzers.

So, let’s look at some equivalency between vb.net and c++.

Boldfaced words are reserved words
Italicized words are what you may assign

To declare a variable

in vb.net:
Dim identifier As type

In c++:
type identifier;

Notice that in c++, you must end each line with a semicolon (;). The compiler will not stop executing a line of commands until it finds a semicolon. In vb.net, it automatically executes a line of code before a line break unless you use a continuation indicator underscore (_). Ultimately, when vb.net code is compiled to machine code, I’m sure the implementations will look incredibly similar. However, I still think vb.net is the more user-friendly language to code in.

To create a void function/sub method – a function that doesn’t return a value

in vb.net:
Sub functionName()
do something
End Sub

in c++:
void functionName(){
//do something
}

To create a function – a function that returns a value

in vb.net:
Function functionName() As type
do something
return something
End Function

in c++:
type functionName(){
//do something
return something;
}

int Main vs. Sub Main

In c++, the “main” function is required, as it is the entry point to the application. In vb.net, you are only required to create a Sub Main method if you create a module as the startup object for your project/solution.

Tags: , , , , , , , ,

Comments are closed.