Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am a 10 years programmer.
My programming language in the beginning was visual foxpro (old version) and now is basic.
They are not object oriented and are procedural language.

I would like to learn a new programming language and after surveying the net of c# and java I finally come up to c#.

I am quite confused (again...please forgive me) between c# and c++.
let me narrow my questions:

a. If I learn c# will I be able at least use c++ later or at least the learning curve is not steep? (As a measurement, if I can write a calculator program in c# will I be able to write it also in c++?)

b. Is c# independent of c++? (Independent by means that I can develop and even (maybe) create compiler or runtime pure of c#?)

c. Can I write c# in notepad and compile it in outside ms environment? (please skip mono for this).

d. Is it possible to write a runtime for c# on any platform (assumed I have good knowledge on the platform) ?

That's all for now. thank you.
Posted
Updated 14-Sep-10 22:44pm
v2
Comments
Per Söderlund 15-Sep-10 4:06am    
You said skip mono, i cannot do that :) because
I think monodevelop offers C# on other platforms.I havent tried it just heard of it.
Dalek Dave 15-Sep-10 4:44am    
Edited for Grammar.
edyzakaria 15-Sep-10 5:31am    
hahaha... i just want to know whether other than mono exist or not. for c# i register mono as my arsenal as VS for windows. :)

I'm no expert, but I'll take a hack at this anyway.

C# is derived from, and simplifies C++. Both are object-oriented, both support most of the same concepts. I've found that C# is much easier to learn - in my case because the syntax makes more sense. C++ depends a great deal on pointers for memory access, while C# hides much of that complexity from the programmer. Pointers can still be used, but it is considered "unsafe" by the compiler and it takes special effort to use them. On the bright side, pointer errors are common and easy to make, and lead to buggy programs and memory leaks. C# helps with this by keeping track of memory allocations and cleaning up after there are no more references to them in the application. Purists will argue that this is a lazy way to program, but for us non-experts, it's a major blessing.

I think that it is easier for a C++ programmer to learn C# than the other way around, but having spent many years trying unsuccessfully to master C++ I am sure that after a few years of using C# I'll find it much easier to learn C++, if I should decide to do so. For the moment, I've found nothing that convinces me that there's any reason ever to learn C++, however. It offers me nothing that I can't do in C#. A more advanced student might have a different opinion on that, but my needs are simple. If you want to translate a C# calculator to C++, you probably will not find that hard to do.

You can certainly write C# programs in Notepad and compile them from a command line using csc.exe, but why would you want to? The Visual C# Express IDE is free, and you don't have to use the Visual elements if you don't want to; the code editor works nicely. Why deprive yourself on the Intellisense system? The vast complexity of the .Net Framework is impossible to memorize, and Intellisense will provide you with helpful hints as you type to aid you in developing programs without constantly having to refer to the Help references or textbooks. The Visual C# package can be a timesaver, even if you prefer to type the code yourself without the "help" of Wizards and canned routines.

As far as I know, C# is a .Net-specific language, and is only supported on the Windows platform, but that may not be true. I haven't looked for any other implementation, and it's possible that someone is working on a port of the language to other platforms. If not, it's probably only a matter of time before someone does so.

Creating a compiler might be chancy using only C#; I don't know. I believe that C# programs are compiled to an intermediate language - MSIL - then further compiled to machine-dependent native code by the JIT compiler at runtime. That may be something you can force offline to produce machine code, but I just don't know the answer to that... sorry!

I do think that you'll have fun learning C#, and it won't be a waste of your time in any way. C# is a strongly typed language that enforces the principles of OOP; that will help you to develop good habits for future use. That can't be a bad thing... Enjoy! :-D
 
Share this answer
 
Comments
edyzakaria 15-Sep-10 3:11am    
Roger.

you are correct for the VS Express IDE and it is absolutely a good one for me. i like it. i just concern about a lockdown situation where i am currently facing. i don't know a lot about things outside windows. if the situation that windows always there for the job then it's ok. but the world is round. it has time when it will be down and time when it will be up. i don't want to be totally blind of outside but i also realize my capacity and time to learn. i just thinking that it might be good to have an alternative if by any means my situation force me to use non windows.

c++ strength and weakness (for me as non expert c++) is in memory management. i got bad mark for that back when i was in college. it is difficult. but it might be difficult because i don't know clearly what it is for. if i know then maybe it will be easy for me. therefore for now i like the c# memory management. but i also don't want to ignore this c++ capability. and there i hope by learning c# it will ease my effort to learn c++ if i need to one day. and as you have said about the writing back the calculator back using c++ is not hard to do then it is good enough for me.

Good encouragement for me Roger. Thanx a lot.
Roger Wright 15-Sep-10 3:24am    
Just a thought for you... When I started programming, I used Assembly language, and got used to using indirect addressing at that level. It's actually quite easy, but it's very easy to make a mistake in calculating address offsets and such, especially if in the course of development you change a variable type and forget to change the addressing. The pointer arithmetic required in C++ is just a high-level implementation of indirect addressing in Assembly. It might be worth your while to do a few projects in Assembly, just for practice. But I still encourage you to focus on C#; not only is it fun, it's useful for almost anything you can do in C++. Don't let the Windows limitation scare you off - the principles you learn will apply to any platform, and Windows isn't going away anytime soon. I predict that, by the time any other platform becomes viable as an effective substitute for Windows, someone will have built a version of C# to run on it. In the meantime, learn it, use it, and enjoy the learning.
edyzakaria 15-Sep-10 4:18am    
Hahahaha... good comment. Thanx Roger.
Dalek Dave 15-Sep-10 4:45am    
That's a well thought out answer.
I would add that C# gives you an understanding of VB too, which has a use as VBA is the basis of Macros for Excel, Word, Acess etc.
edyzakaria 15-Sep-10 12:38pm    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
Very short answer: go with C#.

Short answers:
a. If you learn C# then you didn't get C++ for free.
b. Yes C# is independent of C++.
c. No.
d. Practically, no (porting the whole .NET Framework would be hard).

:)
 
Share this answer
 
v2
Comments
Emilio Garavaglia 15-Sep-10 4:38am    
ahhhh the beauty of 7zip!
Dalek Dave 15-Sep-10 4:46am    
Plus c# is the better supported language because of the .net excercise.
edyzakaria 15-Sep-10 5:28am    
Wah, comprehensive answer.

Thank you.
edyzakaria 15-Sep-10 12:38pm    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
The shortest possible answer: C++ is very different language than C# except for the similar syntax.
 
Share this answer
 
I understand that your priority is to be productive. Then, go with C#. C# is a much cleaner and safer programming language, you get array-index checking, better syntax for generics, etc.

a.) No, you can't write something in C# and then port it to C++. They are simply two different languages. C# looks and feels more like Java than C++.
b.) Yes, C# is independent
c.) no
d.) no

In addition, if you really want to be productive, then learn specific topics in C# and not just the language.
1.) Interoperability with C and C++. Both languages produce either .dll (series of classes or functions without a main entry point) or .exe (.dll with a main entry point). C# can import the dll or exe and call functions. I suggest you learn how to call .dll in the operating system (namely System32, System, etc.). These give you access to all hardware attached to the system and all available services
2.) ADO.Net and database communications. You should learn how to query databases (MSSQL, MYSQL, ORACLE). Get a feel for System.Data (DataTable, DataRow, DataColumn, etc.)
3.) ASP.Net and how to create websites and webservices. Learn how to communicate with facebook, twitter, amazon, etc.
4.) Custom Control Creation. Basically, how to create custom controls out of existing controls. This could be a better datagridview, a better button or I don't know, I group of controls that do something specific *(e.g. login panel)
5.) C# Component Vendors. There are companies that sell ready-made controls such as Dev Express. Their products have trial versions. They are extensions of C# and they make C# look a lot better
6.) VISUAL STUDIO 2005 or higher. This should be at the start. It's almost inconceivable to do C# without Visual Studio. Get used to the project panels (dockable on the left), the palette and the properties window. Simply get used to all the buttons in there as well as the working area. Also know about the refactor tools: Safely rename, extract method, encapsulate fields, etc. They should save you a lot of time in the future.

On the final note, don't be afraid to use the GUI components in C#. Unlike in Java Netbeans where the generated code is mostly uneditable and inefficient, C# generated code are editable two ways (design or source). and the delegate model would make event wiring extremely efficient.

If your goal was to make your learning time productive, I hope this post is helpful. If you like it, please accept it as an answer.
 
Share this answer
 
Comments
edyzakaria 17-Sep-10 13:08pm    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
edyzakaria 17-Sep-10 13:12pm    
yep i like it. detail enough for productivity.
yes you are correct, i don't have time to learn a lot (multiple) language here. i need to learn the good one so at least it equipped me for productivity.

thank you.
In complement to Roger, let me add some more information.

C++ is an evolution of C towards OOP and Generic programming (this second was added later with the income of templates, and was mainly "discovered by using templates", so the language syntax is a little bit fuzzy) actually introducing some "functional programming" techniques (via "lambda").

It retains the C "original sin" that consider the memory as a resource that must be managed by the programmer. In C this is a requirement (since it is a "high level assembler") But C++ -to retain this- introduces OOP without making a clear distinction between objects and values (you can instantiate a class either on heap and refer to it with a pointer, as well as on the stack or as an embedded member) and hence having to distinguish in syntax between address and reference. With the problem that is no always so clear who has to destroy something, and how can every other be informed of such an event. And that's what makes C++ "difficult".

On the other side, Java removed a number of C++ features (the ones that seemed to its designers "dangerous") and introduced a garbage collected memory model, and the idea that every object is on a managed heap.
This simplify a lot the OOP programming, but eliminates some useful thing certain abstract operation are comfortable with (like operator overloading, default parameter,...).
Java is not properly a "compiled language" mainly because a machine hardware processor don't have a "garbage collected heap". It requires a "virtual machine" dealing at least with the memory handling stuff.
Java designer -by the way- specify the interface between such such a machine and the language so that the language can be compiled in a way that no knowledge is required about the hardware instruction set, thus making Java programming suitable for every Java machine implementation for whatever platform.

Microsoft, to react to expansion of Java, introduced the .Net initiative, that -essentially- made available a "garbage collected heap and a virtual machine speaking MSIL - MS Intermediate Language", that -unlike the JVM- is much more similar in is "instruction set" to the underlying x86 processors. (an MSIL assembly program is compiled just before it is executed into processor instruction and then executed: this makes programs slower in start but faster in execution)
Since C++ (the most used language for COM object development, whose are mostly based many MS component interfaces) cannot interact with such an environment (there is no "relocable pointer" - also known as "handle" - and "tracked reference" for that) an new language (C#) was developed.
Like Java, it introduces a clear distinction between values (that must be on stack or somehow embedded in objects) and objects (that are always on heap) thus making the responsibility of the garbage collector clear, and the need of distinct pointer and reference syntax useless,thus eliminating the most of C++ fuzziness.
Unlike Java, C# retains C++ features like operator overloading, letting "type abstraction" still possible, and low level access still possible with unsafe operation that can still be explicitly required where needed.

Similarly, C++ had also been extended by Microsoft into C++/CLI by adding a number of keywords to let C++ able also to interact with "managed" environment.
As far today (2010) things seems to me, such "extension" are not widely accepted from both the C++ community (Who does more "system programming stuffs" don't like "managed environment") and the .Net community (that prefer the more simple C#, for managed stuffs).

To enforce the use of .Net, Miscorsoft came with a framework that today has a huge class library, making relatively simple every sort of "Programming" either about GUI, Networking, Web, Multimedia etc.
C++ cannot access such libraries and must therefore use natively compiled (or compilable) libraries.
Conversely, C++ compiler are available for virtually whatever processor, while MSIL JIT compiler for processor other than x86 are a rarity. (but x86 means both Windows and Linux, that is 98% of the end-user and data-center OSs of today: mono is -in its essence- the Linux implementation of an MSIL compiler).

Now to come to your questions:

a) Depends: C# is a simplified C++: going to C++ from C# means learn how to manage yourself memory and manage yourself addressing and pointers.
But the most of the GUI programming does not depend on the language but on the library used to manage the graphic interaction.
If your "calculator program" spits results on the "standard output" after taking inputs from the "standard input" ... C++ and C#are different only in what I just told.
If it has a graphic user interface, in C# you will probably use WinForm or WPF (.Net libraries), in C++ you will probably fall-through to the native Win32 C API or to some C++ wrapper like MFC or like WxWidget, Qt etc.
Completely different experiences.

b)yes: they are two well defined languages, each with its own specification. One is not a preprocessor for the other. If I well understood the question.

c)yes, by invoking csc from the command line. But it still requires a .Net framework equipped machine to run (Just like a Win32 Application requires a Win32 "equipped machine" to run: you cannot run a Windows exe on linux, after all!)

d)Ideally yes, until a .Net equivalent MSIL machine exist for that platform. Apart from "mono", I'm not aware of any other implementation on.

In substance, if you want to be a windows developer (including Windows mobile) C# is probably more productive. If you want to be cross platform, Java for OOP and C++ for "native" are more widely available, but less "feature reach".

If you're not interested in immediate feature, but are foreseeing a long term language, give also a look to D (here[^].
It is still immature in terms of frameworks and tools, but as a language it eliminates all the C++ fuzziness taking many C++, C# and Java paradigms (including both RAII and garbage collected OOP) good functional and meta-programming (D templates are far better then C++ ones) and compiles in native machine code. (and can be integrated in MS Visual Studio via visual D[^]
It is gaining popularity in game programming, since it easily interface native C libraries, but is still in its "nerd stage" for certain aspects.
 
Share this answer
 
v2
Comments
edyzakaria 15-Sep-10 4:53am    
Emilio,

Wow, what a history. Thanks a lot !!
Thank you also for the answer.

Btw, i take a loot at your introduced D language. Quite interesting. I bookmarked the page. The sample of syntax quite similar with c#. Indeed, it is still immature. But i will try to look at it periodically for any improvement.

Thank you.
AspDotNetDev 16-Sep-10 17:31pm    
I think you meant "csc" not "css". Oh, and awesome answer to "a". I wrote an almost identical answer before I even read yours :-)
Emilio Garavaglia 17-Sep-10 2:23am    
OOPS: you're right. I fix it!
Roger Wright 17-Sep-10 2:41am    
Excellent elaboration, Emilio - Thanks! I completely forgot that, using C++, you're stuck with ATL, MFC, and native Windows libraries. The .Net Framework adds a huge base of functionality that the programmer doesn't have to write from scratch. That, in fact, is my only difficulty in using C#; learning the language is a snap, but learning the Framework is a lifetime project. Thanks for the perspective...
I came from a C++ back ground and picking up C# from it is honestly quite trivial. There are some things that take getting use to and as you oberve them you often are a better programmer than that which took the straight C# route, as they do not see the bennefit of using certain features and pick one of the other ways to skin a cat. Hard to give a concrete example here.

But more importantly we have found that those that learn C# first have huge difficulties in picking up C++. They tend to create numerous bugs or simply can not comprehend how to get a simple data structure working (memory mapping and such).

With that said, my recomendation is learn C++ first. You need not learn in completely in depth but get the basics and some of the intermediate concepts down. After that learn C# continue to study it until you consider your self an expert.

In the end you will be able to support legacy software, native code required apps, and any new concepts.
 
Share this answer
 
v3
Comments
edyzakaria 17-Sep-10 0:33am    
Ah, true in experience. I learned C++ when i was in college and get a grade C at the Advance C++ Programming (C = C hahaha...). i stuck at "malloc" :p.
it is a good idea to re-learn again c++. time is my constraint. but what you said is also correct. i also will try to see some basic again at c++, but when i hit malloc again, maybe i will run away. hahahaha....

salute to c++ skilled people :)
edyzakaria 17-Sep-10 2:33am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
1) C++ is as similar to Java as C++ is similar to C#. Similar syntax in many cases, but different behavior and significantly different syntax when you really get into things. The frameworks are what is really different (though, technically, you can use the .Net Framework with C++). If you wrote a C# calculator using C#, you'd probably be making use of Windows Forms or WPF and the .Net Framework. In C++, you would likely use lower level libraries, so it would be a very different (and more difficult) experience.

2) C# is neither a subset nor a superset of C++. C++ will not compile in a C# compiler and C# will not compile in a C++ compiler.

3) Yes, there is a command-line compiler (csc.exe). You pass the path to the file to compile, along with build parameters.

4) Yes, you would have to implement the CLI on the platform of your choice. The CLI is an open specification (meaning, you buy the documents that describe it). It would take a lot of work.
 
Share this answer
 
v2
Comments
edyzakaria 17-Sep-10 2:34am    
i like the number 4 answer.
thank you.
edyzakaria 17-Sep-10 2:34am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
Emilio Garavaglia 17-Sep-10 2:39am    
though, technically, you can use the .Net Framework with C++

Nope: C++ doesn't have tracking pointer and tracking reference, hence cannot natively access managed memory. That's why C++/CLI was invented.
But C++/CLI is standardized by ECMA, and C++ by ISO. None of the two recognize the other's standard.
AspDotNetDev 17-Sep-10 2:51am    
Managed C++ is what I meant by C++. It is essentially an extension to C++, with keywords like gcnew. Essentially, though, it is still C++. Saying it is not C++ is like saying JavaScript in IE is not JavaScript because it is not the JavaScript that is in Firefox. It has proprietary extensions, sure, but it still has a base of the same language.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900