HorizonForumsone horizon
Log inSign up

[ms] · Est. May 2002

Music madethis place,we just kept itgoing...

One durable person. One social graph. Many communities—and every way people speak, share, listen, write, gather and remember.

Forums / General Yakkity Yak

C++ and C# programmers

30 durable postsStarted 2004-06-30Latest 2004-07-16
#1683Post 1 of 30

I'm a C++ programmer with many years experience behind me, and I've dabbled a little in C#. Thing is I'm going for a job where they want to see some C# knowledge, although they're not too bothered about commercial experience.

Has anyone got any good bullet points to answer the question "What are the main differences between C++ and C#?". I know a few (of course), but I want to impress the panel.

Cheers

#215727Post 2 of 30

I work with c# now and have had c++ in the past. Main thing is that C# is better for building GUI's and other graphical tools....if youve ever done any visual basic, its some what like that. What it has over Visual Basic is that its object oriented and multi-threaded (u can run two processes at the same time). You dont have to worry about memory allocation, which has always been a pain in the a$$ with C++. you dont have to worry about pointers. Strings and text manipulation is alot easier with C# because you have better string manipulation components built in. If youve ever had java experience which I personally dont, but everyone tells me that C# is microsoft version of java and that they parallel heavily. Syntax is pretty much identical between the two... if you are competent with C++, you will have no problem picking up C# especially if youve ever done any VB programming. Thats what pops to my mind immediately when i think of the question.....theres tons more tho.

#215774Post 3 of 30

why don't you have to worry about pointers? what do you mean by that?

#215975Post 4 of 30

[quote=groffhibbitz]why don't you have to worry about pointers? what do you mean by that?[/quote]

When you pass arrays into functions in C++. you have to declare a pointer to that array...ie

float * examplepointer; examplepointer = &array[0]; x = functionCall(examplearray);

in C# you just pass the array name directly into funciton call...

float array[N]; x = functionCall(array);

this thread definitely belongs on a different forum

#215987Post 5 of 30

I have my 25m swimming certificate.

#216016Post 6 of 30

[quote=ichrang][quote=groffhibbitz]why don't you have to worry about pointers? what do you mean by that?[/quote]

When you pass arrays into functions in C++. you have to declare a pointer to that array...ie

float * examplepointer; examplepointer = &array[0]; x = functionCall(examplearray);

in C# you just pass the array name directly into funciton call...

float array[N]; x = functionCall(array);

this thread definitely belongs on a different forum[/quote]

that is easier! I like it.

Have you ever used python? You don't have to worry about anything there. You don't even have to declare types!

python:

array[n] x = functionCall(array)

#216041Post 7 of 30

[quote=Musical Journey]I have my 25m swimming certificate.[/quote]

So, what does that mean? You can swim as far as 25m ? :mrgreen:

#216053Post 8 of 30

[quote=brakada][quote=Musical Journey]I have my 25m swimming certificate.[/quote]

So, what does that mean? You can swim as far as 25m ? :mrgreen:[/quote]

Yeh, 25 miles is some distance i think you`ll agree. :RockOn:

#216101Post 9 of 30

[quote=ichrang]I work with c# now and have had c++ in the past. Main thing is that C# is better for building GUI's and other graphical tools....if youve ever done any visual basic, its some what like that. What it has over Visual Basic is that its object oriented and multi-threaded (u can run two processes at the same time). You dont have to worry about memory allocation, which has always been a pain in the a$$ with C++. you dont have to worry about pointers. Strings and text manipulation is alot easier with C# because you have better string manipulation components built in. If youve ever had java experience which I personally dont, but everyone tells me that C# is microsoft version of java and that they parallel heavily. Syntax is pretty much identical between the two... if you are competent with C++, you will have no problem picking up C# especially if youve ever done any VB programming. Thats what pops to my mind immediately when i think of the question.....theres tons more tho.[/quote]

Ok that's is mostly a bunch of crap. C# and the new VB.NET are similar, but so is managed C++ if you look at it that way. They all use the same CLR but are not syntactically the same.

The main differences between C# and C++ is [list] Garabge collection, no explicate call to delete objects C# is a true object oriented language (like java) not some dress up make beleive object orientation built over C C# is strongly typed. C# isn't compiled to machine code, it's compiled to IL (Intermediate Language)

[/list]

for a more in depth review of the two there are a ton of websites with C# tips for C++ programmers

for instance: [url]http://www.andymcm.com/csharpfaq.htm[/url]

#216248Post 10 of 30

[quote=ichrang] When you pass arrays into functions in C++. you have to declare a pointer to that array...ie

float * examplepointer; examplepointer = &array[0]; x = functionCall(examplearray); [/quote]

thats not really true.

you can declare a function to accept an array as an argument.

void bob(int[] fucko, int n) { //whatever }

void main() { int blah[20];

bob(blah, 20);

}

now, the dynamics in how the compiler handles that situation are different... but it can be done :)

#216347Post 11 of 30

watches l33tn3ss of thread go right over his head :Whoaa:

#216362Post 12 of 30

Re:: C++ and C# programmers

[quote]The main differences between C# and C++ is Garabge collection, no explicate call to delete objects C# is a true object oriented language (like java) not some dress up make beleive object orientation built over C C# is strongly typed. C# isn't compiled to machine code, it's compiled to IL (Intermediate Language) [/quote]

I case you don't know why these help:

[b]Garabge collection, no explicate call to delete objects [/b] Stops memory leaks and dangling pointers (big issues in C++), basically when all references to an object are removed (ie they all become null) then the object is fair game for the garbage collector. The garbage collector will occasionly step through the heap looking for objects without references and will free them automatically. Because of this you can't guarantee that an object will destruct when all references to it become null, so your finalizers need to be able to handle loss of refering objects or objects it refers to. The GC is a whole topic in its own right, so its worth looking into this before any serious C# coding (they will almost certainly ask about it in any interview).

[b]C# is a true object oriented language (like java) not some dress up make beleive object orientation built over C C# is strongly typed. [/b] No globals. Default access to most things are private. Its impossible to cast to void and treat the object as untyped. Everything derives from the base object class, including fundamental value types like ints, floats etc.

[b]C# isn't compiled to machine code, it's compiled to IL (Intermediate Language)[/b] IL is a byte coded language, basically C# is compiled down to simple instructions that the CLR (Common Language Runtime) can parse quickly and simply. This probably won't concern you for most jobs.

One more thing, the .NET Framework API mainly throws execptions to flag errors rather than returning error codes. So you tend to have to wrap a lot of functionality with try-catch-finally blocks.

Paul

#216386Post 13 of 30

Re:: C++ and C# programmers

[quote]C# is a true object oriented language (like java) not some dress up make beleive object orientation built over C [/quote]

C++ is perfectly well object-orientated if you use it as such, it's just that nearly all "C++" programmers use it like "C with classes". This isn't necessarily a bad thing IMO, having to go completely OO can be very restrictive and feel somewhat pointless. I hate Java for it's excessive "objectness", I just get pissed off writing stupid code that could be done in a much cleaner way.

And managed C++ = :Wasted:

#216524Post 14 of 30

Re:: C++ and C# programmers

[quote]This isn't necessarily a bad thing IMO, having to go completely OO can be very restrictive and feel somewhat pointless. [/quote] Only if you do it wrong ;)

#216572Post 15 of 30

Thepariah: nicely put

These are language differences.. there are also some fundamental differences of the C# development and runtime environment.  C# is one of languages in the Microsoft .NET platform which includes, among other things, a CLR, or common language runtime.  As was stated above, C# is compiled into bytecode (IL) which is interpreted at runtime by a virtual machine.  This is very similar to java, and Microsoft's .NET runtime is about a 21M redistributable.  When you build C# apps, they are supposedly portable because they run as bytecode in this VM, although Microsoft has only made this CLR for Win32 (there is a project called [url=http://www.mono-project.com/about/index.html]MONO[/url] which is trying to fix this.  In practice you will find that C# has a lot more in common with Java than C++.

There are also a bunch of other language differences, as C# has things like deletgates (sort of like function pointers for events), class properties (member variables with get/set functions,) new class features (interfaces, sealed classes, etc,) and more.

You can check out [url=http://msdn.microsoft.com/vcsharp/team/language/default.aspx]C# Language Homepage[/url] [url=http://download.microsoft.com/download/5/e/5/5e58be0a-b02b-41ac-a4a3-7a22286214ff/CSharp%20Language%20Specification%20v1.2.doc]C# 1.2 Language Specification[/url]

#216577Post 16 of 30

Re:: C++ and C# programmers

There's shit loads of resource on the net, and as Chris pointed out the MSDN is very useful. One of the best resources actually comes installed with Visual Studio.NET

Check ...\Microsoft Visual Studio .NET 2003\Vc7\1033\C# Language Specification.doc

It coveres everything, has useful examples and gives comparisons with C++.

Paul

#216586Post 17 of 30

Re:: C++ and C# programmers

[quote=Paul Louth][quote]This isn't necessarily a bad thing IMO, having to go completely OO can be very restrictive and feel somewhat pointless. [/quote] Only if you do it wrong ;)[/quote] I agree with you Paul. That is a bunch of bunk that Java makes it more restrictive because of it's "objectiveness". If you break your program down into the objects you are supposed to have. You'll find your program much easier to maintain. I think you need to learn object oriented techniques unrelated to any programming language. This will allow you to focus on the concepts and not the syntax and how these are implemented based on a particular language. Read up on subclassing, inheritence, interfaces, etc and get a strong understanding of these before saying that Java is restrictive. I'm fairly new to Java but one thing I do know is this puppy is definately not restrictive. I think it's that you are just most comfortable with C++. If anything Java will make you a better programmer. :wink:

Chris & Paul. Do you guys also do programming for a living?

#216595Post 18 of 30

[quote]Chris & Paul. Do you guys also do programming for a living?[/quote] Only for 10 years or so ;)

#216642Post 19 of 30

[quote=Paul Louth][quote]Chris & Paul. Do you guys also do programming for a living?[/quote] Only for 10 years or so ;)[/quote]

so .. paul .. not only are you a working dj (a job i want) but you are also a software engineer (a job i want).

screw the economy and screw you :Down: ;)

#216809Post 20 of 30

Thanks for the tips and links guys :Bingo:

#216843Post 21 of 30

Re:: C++ and C# programmers

major geekness

#216965Post 22 of 30

Re:: C++ and C# programmers

[quote=Paul Louth][quote]This isn't necessarily a bad thing IMO, having to go completely OO can be very restrictive and feel somewhat pointless. [/quote] Only if you do it wrong ;)[/quote]

Maybe. I think perhaps a case of different viewpoints though..

Either way, I'm happy using C++ the way I do at the moment, even if it's frowned upon by some :)

#216985Post 23 of 30

Re:: C++ and C# programmers

[quote=Neo] Chris & Paul. Do you guys also do programming for a living?[/quote]

For a living and for fun, although its been a year or two since i've done any personal development. I'm actually on a C# project right now.

#216988Post 24 of 30

Oh finally I found it again, this article is really, really good

[url]http://www.itgatewaysolutions.com/articles/CPlusAndCSharp.htm[/url]

I think that's about as complete as it gets

#217034Post 25 of 30

Re:: C++ and C# programmers

[quote=Chris Micali][quote=Neo] Chris & Paul. Do you guys also do programming for a living?[/quote]

For a living and for fun, although its been a year or two since i've done any personal development. I'm actually on a C# project right now.[/quote]Awesome. That's how your productions are so good. Technically minded.

I want to pick up C# after I get a Java cert. There's so much you can do with Java. I'm on a J2EE project right now. My first taste of Java and I'm doing servlets & jsp's.

#217134Post 26 of 30

Re:: C++ and C# programmers

[quote=Neo][quote=Chris Micali][quote=Neo] Chris & Paul. Do you guys also do programming for a living?[/quote]

For a living and for fun, although its been a year or two since i've done any personal development. I'm actually on a C# project right now.[/quote]Awesome. That's how your productions are so good. Technically minded.

I want to pick up C# after I get a Java cert. There's so much you can do with Java. I'm on a J2EE project right now. My first taste of Java and I'm doing servlets & jsp's.[/quote]

:lol:

Sorry, I gotta laugh. Java is mostly theory, man. Even after 10 years, it is still mostly theory. I have yet to see the fully OO and fully functional Java-based OS they raved about 10 years ago as its truest potential. Most J2EE projects started in 98-2001 ended unsuccessfully (somewhere about 80%) according to stats gathered in 2003-early 2004.

As you will soon discover, [b].NET[/b] is truly pushing the envelope of both GUI-based and data-driven applications in every tier (w/o having to learn different toolkits for each core functionality). With [b].NET 2.0[/b] around the bend, it is truly amazing.

I have been programming for 9 years, and have got my hands on all the shit MS put out this week (the Express line of tools, as well as VS.NET 2005 Beta 1). IN due time, I'm gonna migrate from pre-.NET to .NET 2.0. This whole .NET 1.0/1.1 is really a joke. It's nothing but an intro, not the good stuff.

If I'm wrong, at least I'll die rich :)

#217650Post 27 of 30

[quote=superEGO72][quote=Paul Louth][quote]Chris & Paul. Do you guys also do programming for a living?[/quote] Only for 10 years or so ;)[/quote]

so .. paul .. not only are you a working dj (a job i want) but you are also a software engineer (a job i want).

screw the economy and screw you :Down: ;)[/quote]

So you'll probably hate it even more when I tell you the software-development I do is writing games for PS2/XBox/Gamecube ;)

#217661Post 28 of 30

Re:: C++ and C# programmers

c# dont allow multiple Inheritance :cry:

#217669Post 29 of 30

Re:: C++ and C# programmers

You don't need multiple inheritance. Flattening out hierarchies is a good thing, and allows you to move modules around later without huge dependencies. Loosely coupling classes using interfaces and messaging is better than using multiple inheritance imo.

Paul

#217806Post 30 of 30

Re:: C++ and C# programmers

[quote=nasserd]Sorry, I gotta laugh. Java is mostly theory, man. Even after 10 years, it is still mostly theory. I have yet to see the fully OO and fully functional Java-based OS they raved about 10 years ago as its truest potential. Most J2EE projects started in 98-2001 ended unsuccessfully (somewhere about 80%) according to stats gathered in 2003-early 2004.

As you will soon discover, [b].NET[/b] is truly pushing the envelope of both GUI-based and data-driven applications in every tier (w/o having to learn different toolkits for each core functionality). With [b].NET 2.0[/b] around the bend, it is truly amazing.[/quote]

You sound like Microsoft's little marketing boy. You're definately a pro-Microsoft programmer which I was as well until I started learning about Java so I won't argue with you but Java does have it's place. As far as projects being unsuccessful, that's probably true with [b]ALL[/b] software projects. Many are over budget, take too much time and get canceled. It's the nature of the business it has nothing to due with the technology really. The thing about microsoft is all there products are so integrated so RAD is possible. People are more impressed with getting something completed in the shortest time. As the open-source movement grows I see Java and/or C# becoming even more popular. Why else do you think Microsoft made C#?

Log in to reply