C# vs C++
Author |
Message |
rahzab
|
Posted: Wed Sep 23, 2009 8:41 am Post subject: C# vs C++ |
|
|
I read the whole 7 page article on the best programming languages. I don't understand a lot of the advantages and disadvantages of the languages (I'm still a newbe programmer). However, I would like to start game programming (do it as a hobby). This year in computer science class we are learning java. Last year, I learned VB 6, and the year before, turing. So in terms of programming concepts, I can do the basics and programming isnt all new to me.
Where the article on best programming language comes in, is that, I really hate Java. I just hate it maybe because I'm so used to the VB 6 style of programming. The basic input in Java is confusing (my programming teacher didnt really explain that well). However, I have some understanding of what's going on.
So, I decided to continue the course, to refresh all the concepts, and get used to an object orientated language (I don't even know what that means). However, I wanted to learn a new language, one that is really flexible (from making games (3-d, 2-d) to small applications (like a bot for a mmo)) . I decided to choose between C# and C++. C# because it's new, and in other forums people claim that in the future C# will be the "big language". C++ because it has huge support and because it's used more. So, can someone here explain to me the specific disadvantages and advantages between these two languages. I think I'll choose the one that has more advantages. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
jbking
|
Posted: Wed Sep 23, 2009 9:46 am Post subject: Re: C# vs C++ |
|
|
C# vs C++: A Checklist From a Programmer's Point of View while dated does give some examples of the differences. There is also something to be said for which dialect of the language you take, e.g. are you taking C# 1.0, 2.0, 3.5 or 4.0 while for C++ there is Microsoft's Visual C++, GNU's C++ and other compilers that one could use.
GameDev.net's forums also have a discussion on this.
There are a few principles behind OO like abstraction, inheritance and polymorphism. S.O.L.I.D. are also some ideas on how to use OO compared to say Procedural programming. |
|
|
|
|
 |
DemonWasp
|
Posted: Wed Sep 23, 2009 11:04 am Post subject: RE:C# vs C++ |
|
|
You will find that C# code is fairly similar to Java code. It may be worth trying to learn the "basic input" that your teacher couldn't explain well enough, because it's probably well-designed and just poorly-explained ... and it's probably done similarly in C# and even C++. Look at the Scanner class, part of the Java API.
The short version is that C# / Java will be easier to write code in. C++ requires a LOT more thought go into each and every line of code you write. Easier development means faster development, which means it's easier to write a lot. For 3D development, I can't speak on C#, but Java definitely has both OpenGL interfaces and Free 3D Engines that perform quite well.
Before you dive into any of these languages, you should learn what Object Oriented Programming (OOP) is, because all three of those languages are Object-Oriented. |
|
|
|
|
 |
rahzab
|
Posted: Wed Sep 23, 2009 1:57 pm Post subject: Re: C# vs C++ |
|
|
I'm beginning to grasp the idea of OOT, as everything in java is done in classes. (I was exaggerating in my other post, more like I'm new to it)
As for the "basic input" I was referring to the teacher said "It's not important right now...", however I'll paste the syntax I don't understand.
try
{
System.out.println("Enter a value for x");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
x = Double.parseDouble(input);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (NumberFormatException e)
{
System.out.println("Input by user was not a number.");
e.printStackTrace();
(I couldn't find the syntax option and put it into java)
The bolded part is what he never explained. I think my frustration with java is that it takes so much longer to do simple things whereas in VB 6 and turing it was much easier. I understand in an object orientated language emphasis is put on how we deal with data over the logic in outputting the data.
btw, thanks for the input and I will check out the link (I'm posting this from school) |
|
|
|
|
 |
andrew.
|
Posted: Wed Sep 23, 2009 3:53 pm Post subject: RE:C# vs C++ |
|
|
Java: |
// This is a try-catch block. It is used for handling errors
try
{
System.out.println("Enter a value for x");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); // This creates a new "reader" object. It is a BufferedReader and it's getting input from system.in
String input = reader.readLine(); // You create a new String and then make the readLine method in the BufferedReader class return the result for you to store
x = Double.parseDouble(input); // You are converting from String to double (real number). It's the same as strreal in Turing.
}
catch (IOException e) // This is the second part of the try-catch block. It "catches" any kind of error and you can tell the computer what to do with it instead of just having the program crash.
{
e.printStackTrace(); // This will print the error
}
catch (NumberFormatException e) // This one is to check whether there was an error with the input.
{
System.out.println("Input by user was not a number.");
e.printStackTrace(); |
Hope that helped. |
|
|
|
|
 |
DemonWasp
|
Posted: Wed Sep 23, 2009 4:09 pm Post subject: RE:C# vs C++ |
|
|
The first line is getting a BufferedReader that itself reads from an InputStreamReader, which reads from the InputStream System.in (this would be stdin in C, or cin in C++).
The second line reads the first whole line of input as a String.
The third line tries to convert whatever it got in to a double, using the parseDouble function (which is, logically enough, a member of the Double class).
If everything goes according to plan, x now has a valid double value as read from the input. However, if something didn't go right, an exception could be generated. Exceptions occur when something you weren't really expecting happens.
In this case, if the user entered something other than a double as the first line, there's a problem: the number isn't formatted correctly. Double.parseDouble() wisely throws a NumberFormatException that contains the details of the error. Two lines later, that exception is caught by the catch block for NumberFormatExceptions, which outputs the fairly obvious error message "Input by user was not a number.", shows the stack trace (listing of which methods you were in and where within them) and exits.
The following is a simpler (untested) version of the same thing:
Java: |
System.out.println ( "Enter a value for x: " );
Scanner in = new Scanner ( System.in ); // Scanners can read doubles, ints, Strings...whatever!
if ( in.hasNextDouble() ) {
x = in.nextDouble();
} else {
System.out.println ( "Input by user was not a number!" );
}
|
Note: the above code will only work if your JVM is at least version 1.5 (sometimes called 5 because SUN isn't good at version numbers). Run java -version at a command-line to find out more information on which version you currently have (though if you're running in Ready to Program, you'll only have 1.4.2, and I would recommend you switch environments quickly.
The reason that things are often easier in VB / Turing is because they doesn't give you as much power, nor are they as demanding that you specify exactly what you want to do. What if you want to get the token (delimited by spaces) out of a String? Well, in Turing you'd write something yourself; in VB there may be a way but I don't know it offhand. In Java you would write Scanner in = new Scanner ( myString );
There's also a lot of really cool stuff that can be done in Java that can't be done in Turing or VB6 (mostly because Turing has a really-broken OO model and VB6 doesn't even have one), but I'm out of time to post for now.
I should also mention that I'm not necessarily trying to discourage you from trying C++ or C# (though I generally caution newer programmers to stay away from C++ until they've done work in C). Just pointing out that it's probably not Java's fault you don't like it...there are plenty of legitimate reasons to hate on Java, but that's not one of them. |
|
|
|
|
 |
rahzab
|
Posted: Wed Sep 23, 2009 4:52 pm Post subject: Re: C# vs C++ |
|
|
wow, you guys rock. See I think the problem is our teacher kind of expects us to know what's going on, I asked a lot of people in my class and they do not know what's going on. I think our teacher should spend some more time on explaining or at least elaborating on some of those lines. I think I will read a Java tutorial. Maybe it has a lot more explanation but thanks a lot. |
|
|
|
|
 |
DemonWasp
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
wtd
|
Posted: Sat Sep 26, 2009 11:11 pm Post subject: RE:C# vs C++ |
|
|
My Java tutorial is pretty fast-paced, but doesn't wimp out when it comes to OO concepts. |
|
|
|
|
 |
wtd
|
Posted: Sun Sep 27, 2009 1:30 am Post subject: RE:C# vs C++ |
|
|
The choice of C++ or C# depends almost entirely on what specific tools you plan to use. If you plan to use tools which dictate C++, then you're going to use C++ and C# probably isn't even an option.
On the other hand, there may be cases where C# is the obvious choice. If you plan to stick pretty soely with Microsoft tools, for instance, you'd be a fool to learn C++ in-depth over C# at this stage in the game. |
|
|
|
|
 |
jbking
|
Posted: Sun Sep 27, 2009 4:39 pm Post subject: Re: RE:C# vs C++ |
|
|
wtd @ Sat Sep 26, 2009 11:30 pm wrote: On the other hand, there may be cases where C# is the obvious choice. If you plan to stick pretty soely with Microsoft tools, for instance, you'd be a fool to learn C++ in-depth over C# at this stage in the game.
Doesn't Microsoft have a Visual C++ that's part of Visual Studio? Or is that intended mostly for legacy applications? I'm just wondering though I do a lot of work in C# using Microsoft tools. |
|
|
|
|
 |
saltpro15

|
Posted: Sun Sep 27, 2009 6:20 pm Post subject: RE:C# vs C++ |
|
|
I've heard rumours of some magical Visual C# IDE that automatically debugs google style (aka "Did you mean _______ ? ) |
|
|
|
|
 |
jbking
|
Posted: Sun Sep 27, 2009 7:16 pm Post subject: Re: RE:C# vs C++ |
|
|
saltpro15 @ Sun Sep 27, 2009 4:20 pm wrote: I've heard rumours of some magical Visual C# IDE that automatically debugs google style (aka "Did you mean _______ ? )
Resharper can do something like that in terms of finding or suggesting classes, methods or other references to something. |
|
|
|
|
 |
rdrake

|
Posted: Sun Sep 27, 2009 11:49 pm Post subject: Re: C# vs C++ |
|
|
jbking @ Sun Sep 27, 2009 4:39 pm wrote: Doesn't Microsoft have a Visual C++ that's part of Visual Studio? Or is that intended mostly for legacy applications? I'm just wondering though I do a lot of work in C# using Microsoft tools. It's part of VS, yes.
saltpro15 @ Sun Sep 27, 2009 6:20 pm wrote: I've heard rumours of some magical Visual C# IDE that automatically debugs google style (aka "Did you mean _______ ? ) Noooope. The IDE doesn't do that at least. It does, however, have IntelliSense which watches what you're typing and tries to figure out what you want. If you make a typo then it doesn't find what you really meant. |
|
|
|
|
 |
Vermette

|
Posted: Mon Sep 28, 2009 10:49 am Post subject: Re: RE:C# vs C++ |
|
|
jbking @ September 27th 2009, 19:16 wrote: saltpro15 @ Sun Sep 27, 2009 4:20 pm wrote: I've heard rumours of some magical Visual C# IDE that automatically debugs google style (aka "Did you mean _______ ? )
Resharper can do something like that in terms of finding or suggesting classes, methods or other references to something.
We use Resharper in conjunction with StyleCop in my lab, and I gotta say it's pretty nice. We even have it set up so violating coding standards will still build, but will generate warnings and blocks code check-in until they're resolved. Arguments over brace style and naming conventions are answered by digital fiat  |
|
|
|
|
 |
|
|