Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: Zeb on February 22, 2011
-
I've had my BlitzBASIC topic now for one on C.
What are the differences between C, C#, C++ (and the others) and which is best to learn. I've been given a legal and full copy of VisualStudio 2008 but from my past experience trying to learn C things weren't that easy and certainly didn't seem that welcoming.
I had a bash at learning C++ and no matter how hard I tried I couldn't find many code snippets and when I did none of them would compile and the error messages meant nothing to me.
I think my main problem is going to have to accept that I'm going to have to break away from an IDE environment and maybe use Notepad++ with some non-GUI compiler. On the Amiga DevPac had a very nice IDE, AmigaBASIC had an IDE, HiSoft BASIC had an IDE yet I did manage very well with E which had no IDE and I used CygnusEd.
How are things structured with C on Windows? I mean, the Amiga had all those nice libraries, devices and handlers that could be opened and (ab)used. From what I've seen of DirectX code examples it seems to run very much like a library call system - am I right?
EDIT:
Just been reading other topics from the last page backwards and found codeman's topic which I've been reading and found VERY interesting.
So there's devcpp and the free MS Visual Studio C compiler. Which one to use? I remember I installed the free MS compiler last time and ended up abandoning it because I couldn't find much code that would work and I don't want to go back to the start again.
Just trying to weigh up and decide which road to go down - Blitz or C - and I can't make up my mind.
EDIT 2:
Just been reading some more and it looks like I'm heading more towards C++ than C#. Only thing is, I've read a lot of people saying C# is a clever re-work of Java giving some VERY good and true-sounding evidence to back this up just as I've read a lot of people giving good sounding evidence that C# is nothing to do with Java.
I guess at the end of the day I'm wanting to code apps. I remember I got put off C++ the first time because I couldn't do a simple task like get the list of files on the hard drive and couldn't find any source to do so.
The whole "cout" thing I find very confusing, I'm more used to printf. That cout thing looks messy.
HELP! lol
-
I'd say that you'd best learn C first, then C++, then later give C# a go. Each language was designed to build on what went before. The C language is simple, C++ is more about getting to grips with object oriented programming than learning a new language. I'd imagine that C# is more about learning .NET than anything. Much the same way that learning Win32 was.
-
Depends a bit of what you want to do. Do you want to build minimal 3d intros? Do you want to get down and dirty and try to use the last clock cycle? Do you wants something that just works and works quickly? Do you want to build GUI applications?
Now days I would say go with c# in most cases. The reason is that unlike c/c++ c# just works 99% of the time and everything you need is already there.
My favorite example. A string class. In c# (or rather .net) you have "string" it has just about everything you could ever want. Joins, splits, tokens. In c/c++ you have 100's of different implementations all with their pros and cons. All out there on the web. So you waste a week trying to find one that works for you then comes the next task. Say grab a web page. Boy, thats a few weeks wasted. In c# you create your "WebClient" class and call "DownloadString" and your done.
But as rain_storm points out. This doesn't have as much to do with the language per say. But with the framework classes that exists to help you.
However if you learn c/c++ you will be better for it. The problem is that by the time you should have learned it you have probably gotten bored with another strange pointer or memory issue so you go off and do something else.
-
Thanks for the replies.
I know what you mean with the searching for code bit as I spent ages when I tried learnign C++ last time. I could not for the life of me find a routine anywhere that would get the contents of a specific folder.
I'm not into demo coding (maybe MUCH later down the line) but for now I'm more interested in coding utilities. Not amazingly super wonderful utils but just for the sake of learning it. As I mentioned elsewhere in another post - my [serious] coding days are pretty much over and I'm more wanting to learn C because I never did plus I'm still weighing up whether I want to learn Blitz Basic and be adventurous with maths functions or learn C and go semi serious with the coding.
A lot of basics for C are not new to me. I've been using PHP for quite a few years and I've noticed several similarities. I've also been usign C style formatting strings with assembler on the Amiga when using come library functions so programming is definitely not new to me.
-
when I tried learning C++ last time. I could not for the life of me find a routine anywhere that would get the contents of a specific folder
I think that's because C and C++ the languages do not have libraries for that. The libraries you need are part of Windows - FindFirstFile is the function - and as well as C you need learn how to call win32 API libraries if you want to code on Windows.
Blitz, of course, hides all this from you. They're simple BASIC programming languages and are quite powerful. I use the original blitzbasic all the time on my netbook for prototyping pixel demo fx. B3d and BMax are also good for this and you can go a long way - see for instance Tetra's demos on this site. But these languages are getting a bit long in the tooth these days and not that many people here code in them any more.
C# is great for doing Windows GUI apps and web services. It's quite a bit different from C++ - for a start it has a garbage collection system so you don't need to do all the C++ memory management. I code C# all day, the .net framework library is huge and comprehensive, and I love it. It's no use for coding demos though.
Jim
-
So ... I will maybe repeat things already said around ... sorry for that.
First of all:
If you are doing C / C++ don't use Dev-cpp at all !!! (otherwise I am becoming crazy, and you will find carrot juice on your clothes :carrot: )
Seriously Dev-cpp is outdated, not updated since a long ... and have a spriritual successor which is Code::Blocks. So use Code::Blocks (or Visual Studio of course)
Secondly, you can learn either C or C++ (if you like oriented programming langages). Why, because it supports SDL (Maybe C# too in fact ... not sure). And SDL is running on Amiga (you can code C / C++ on Amiga OS (so maybe you can find back your old memories ;)).
What else ... oh yeah ... if you know a bit Java (and you like it) do C# ... you will like it too. As it has been said ... everything is in the framework and that's really cool (.NET framework). I don't like it too much because I am GNU/Linux user ... but don't mind ;))
C / C++ are always a bit hard to start because of not having a good uniform framework ... and this force us to look in many documentations and so on (which is not really easy when starting). With SDL you can do fancy 2D things (and even have a direct pixel level access (which is slow though :(). Otherwise ... to do listing of files, you have to check in MSDN (official Microsoft documentation) or in manpages for GNU/Linux (which is a pain ... since there is different things for different OS).
Now ... why not talking about something else like python. Python is quick, has lot of things already in ... it's between C / and BASIC (maybe not too much in fact). This is also oriented object ... so why not. After it's like you want of course.
When you have selected your langage (Press Start!) ... ask us nice way to start going on it ... like documentations ... and even ask us for compilation issues. C / C++ are really sucking in their compilation errors ... but it comes with experiences (half of the time I am not reading them and fixing my code)
-
Apparently there is an SDL.Net! http://cs-sdl.sourceforge.net/ (http://cs-sdl.sourceforge.net/) Why you would do this to yourself I don't know :P
Jim
-
Just an update.
I was thinking of learning C++ and I'm now thinking of heading right to C# instead.
Quick question: say I do head to C++ instead of C# and I want to learn how to do something - let's say for the sake of this example I want to get the list of files & folders in a specific folder - how would I look up on how to do this? It must be possible so my guess is it's just a case of tracking down which includes I need and figuring out how to use them but how would I go about this?
-
Depending on the OS (as I said yesterday) (I am supposing you are with Windows ;)) you have to look to MSDN (just type MSDN reading folders on google and it should match).
Google will give you a link with a function name and the documentation on MSDN, in this documentation, you will have all the informations to use it (include / libraries / code sample sometimes).
Often ... it's just by going through google research.
Maybe you should read a tutorial on the langage first just to learn quickly the syntax and the main idea of the langage.
-
LittleWhite, is that just C# or is the MSDN compatible with C++ as well?
-
I did a google search for "msdn directory listing". The C# library came as the first link, the C/C++ win32 one as the second.
Do bear in mind that C# is very different from C++. It has its similarities - mostly syntax - but as a concept it's more like Java than C++.
Jim
-
Quick question: say I do head to C++ instead of C# and I want to learn how to do something - let's say for the sake of this example I want to get the list of files & folders in a specific folder - how would I look up on how to do this? It must be possible so my guess is it's just a case of tracking down which includes I need and figuring out how to use them but how would I go about this?
In visual studio intellisense is really an amazing tool. In 2010 its good enough on its own. In 2008 and below Resharper is a good addition to help improve it.
So the process goes like this.
First you think of where you would put whatever function your looking for yourself. For files I would think Directory, File or Path. So you type it out. "Directory." and intellisense shows a nice list of what you can do on that class. The static functions on it in this case. .Net has quite a few functions like this as static functions.
In your case you would scroll down the list for something that looks plausible. GetFiles is in there. Start typing it and you get a description with all arguments and description for them and your done in this case. You have your list.
string[] files = Directory.GetFile("MyDir");
Of course its not always this simple. Without reshaper you need to have the correct "using" applied at the top of the file (The include your talking about). Then its best to ask google these days. The top link is usally a MSDN link and thats the way to go.
For the record "Directory" is placed in the "System.IO" namespace.
-
Intellisense - I forgot how handy that is!
Jim - it's the Java similarities that's making me not want to do C# as it doesn't feel like C++ and it's the "I'm learning C" thing I like the sound of.
:)
-
C#, java, C and C++ all have a very similar syntax, so writing in one means you will be able to write functions in another.
C# and Java do all the memory management for you. They are nowhere near the metal as they compile to an IL (intermediate language) and run on a VM - the JVM for java and the .NET Framework for C#. These are very fast, but not as good as native code.
C#, unlike C++ doesn't support multiple inheritance or friend classes. It also has a far less complicated templating system. It does, however, have the magic of Reflection which allows you at runtime to inspect all the properties of functions and classes.
C# and Java have massive built-in libraries for doing almost anything. C# can also thunk down into Win32 and COM if you need to.
With C and C++ you have to use the Windows API which is very direct but also very manual.
There are many, many other differences.
I can't tell you which to learn. Learn them all ;-)
Jim
-
As most of the processing resides in the GPU rather than the CPU these days, you can't really assume that C/C++ is faster than Java/C#. The JVM is an insanely great VM with top performance. I wouldn't recommend using Reflection in performance critial applications, but it is great for flexibility.
It's the same kind of people who say that C# is too slow compared to C, that said the same thing about C and ASM. And honestly, how many write ASM these days?
-
C# and Java do all the memory management for you. They are nowhere near the metal as they compile to an IL (intermediate language) and run on a VM - the JVM for java and the .NET Framework for C#. These are very fast, but not as good as native code.
I just wanted to clarify this point, both Java and C# produce native code. They just produce it at runtime rather then compile time. This actually allows them to be faster then C in some benchmarks because they can use runtime information to optimize an application further (which you can't do with a compiler). In practice they are usually a little slower, but not by a huge factor. Java especially is one of the few higher-level languages that gets very close to C++ performance, especially on servers!
For games I'd recommend C#. For apps, if your planning to target Windows only (which personally I would) then I'd also recommend C# with WPF. In all other scenarios I'd recommend Java!
-
Shouldnt you be considering 'D' anyways? Supposedly the next evolution of 'C'. Although, it looks like its to make plug-in coders life easier mainly.
I learned C because I learned coding at home in ASM when a youngster on my speccy. C was for big boys I believed. Later met 'real' programmers and they always said choose the language on what the task is. Obvious in professional environments. At home, I find alot of the languages a pain because of all the overhead, even if you have a fantastic IDE like xCode to hide it all.
But, tbh, for me, u cant beat an emtpy text file that you just bash away into and compile. Thats why I'll always be a C fan. I've learned countless languages/frameworks/libraries over the years. Its good ole 'C' that never seems to want to fade from memory like the others. Plus, you learn system stuff like you did with ASM, that later pays dividends in overall understanding. I know plenty of programmers who have no idea what a tick is or anything outside of a library call. That just wouldnt work for me!
On another note....you want to check out a cool language to code in. Try erLang, I'm just about halfway through the starting tutorials. Love it, but conceptly it sooo different from 'C'. Coming from a kind of Prolog/Lisp/Scheme type background, its not easy for a died on the wool ASM/C coder to make the switch. But, it seems its the coolest way to develop good server back ends, specially for hi performance needs like RTS games.
Learning C should be easy for you if you know some PHP. But the learning resource helps alot. I learned from a book called Using 'C' and some other DevPac stuff. Had a source copy of Steve Bak's Karate Kid too at one point, learned some cool C stuff from that!
My advice, learn C. Then you have a solid foundation for any other C style language later on.
Plus, its good that you have an idea of what to code. I've often found learning a new language boring because the tutorials were so lame. I learned quicker when I wanted to do something specific. Doing your disk utils or whatever gives you a focus and a good feeling when you make it work, as opposed to doing a tutorial.
Cheerz,
Jay
-
And honestly, how many write ASM these days?
As a matter of fact more code is written in assembly then in any HLL, especially in todays disposable microprocessor world. But thats another story for another thread.
I personally never was a fan of .NET, Why would you wish to learn this...
System::AreWeThereYet::NearlyThere::HereItComes::ICanFeelIt::MessageBox("Hello World");
When this is the alternative...
MessageBox(0,"Hello World","Hi",0);
-
You can use all methods without any of that prefixing stuff by putting
using System.AreWeThereYet.NearlyThere.HereItComes.ICanFeelIt;Which isn't much different from having to #include a header. But this 'namespacing' means two or more libraries can define MessageBox without conflicting with one another, and helps the linker determine the library dependencies. If you needed to use both versions in the same cs file then you'd just use as much of the prefixing so as to make them distinct,
ICanFeelIt.MessageBox()
OtherLib.MessageBox()
Jim
-
But, tbh, for me, u cant beat an emtpy text file that you just bash away into and compile. Thats why I'll always be a C fan.
You can do this in any language!
Shouldnt you be considering 'D' anyways? Supposedly the next evolution of 'C'. Although, it looks like its to make plug-in coders life easier mainly.
D is meant to be good, but has some issues with maturity (such as two standard libraries).
Python is something that's been used a lot recently for game development. In practice only a minority of code needs to be highly performant; you don't need to write everything in C or C++. Even then for a dynamic language Python is pretty damn fast, and there is lots of development for making it easy to write C extensions for Python.
There is also Lua. Same reasons as thsoe above only stronger (even faster, used far more in the games industry and is one of the few languages built with easy C integration in mind).
If I had to pick a language to try it'd be OCaml. It aims to be a very practical functional language whilst also aiming to be very fast. Some of the algorithms it uses in the standard library are even faster then those used in the C standard library because it can take advantage of immutability (although in practice it'll probably be slower, but not by much).
On another note....you want to check out a cool language to code in. Try erLang, I'm just about halfway through the starting tutorials. Love it, but conceptly it sooo different from 'C'. Coming from a kind of Prolog/Lisp/Scheme type background, its not easy for a died on the wool ASM/C coder to make the switch. But, it seems its the coolest way to develop good server back ends, specially for hi performance needs like RTS games.
I've also used Erlang; I built my third year project (a highly concurrent game framework) using it. I second that it's a great language to learn, and it's concurrency model is bliss when it works. However debugging is far from simple (especially if you constantly spawn and destroy a high volume of processes which I was). Even reading it's stack traces takes some getting used to.
For concurrency I much prefer Occam-Pi which uses a CSP model. In a sense the difference is that in Erlang you hold onto processes whilst in Occam-Pi you hold onto the channels connecting them. It's a very fiddly language filled with bugs, but once running I'd be far more confident over an Occam-Pi app. Lots of concurrency issues are found at compile time, but it certainly is NOT mature enough for real world use (I only learnt it because it's developed at my ex-uni).
Personally I'd also recommend against C. I don't think it prepares you for other languages because simply doesn't encourage object-oriented programming like with C++, C# and Java (you can write OO code but you need experience to do this well as it's not as pretty). If you really want to pick C then I'd go for C++ instead. You can get further away from the whole malloc/free style of programming whilst being just as fast. You also have much bigger toolbox to take advantage of, such as templates for type parameters.
-
I went along the route, C to C++ and now I am looking at C#. But the one thing I have found is the basic language syntax is similar in all of them, of course C++ adds OOP stuff to C and I am probably still more a C coder than C++ as I still dont use classes enough. With all of them its more about the libs,includes and api access and how they handle it, C/C++ are more direct but also more complex were as from my understanding due to the .net framework C# provides alot more without resorting to loads of other libs etc. making it easier to get stuff going leading to more productivity.
But strange as it may seem I like to code in Blitzmax more than anything else, it offers alot of the OOP features of C languages (can even use C if you want), I can get down an dirty with winapi calls just like in C/C++ or I can stay up high in the pre-coded and simpler to use modules it comes with. Infact using blitzmax types and methods helped me grasp the class concept in C++ better than anything I read for C++ :D
I would say if your up for it learn all of them, but if you want a quick route into coding apps, as that seems to be your current interest then probably go for C# to start with. The visual designer alone will save you hours making the GUI's :)
-
go and download a copy of Code::Blocks IDE. this comes with the MingW32 Compiler included.
then learn C. with C you learn lots of low level stuff
then learn C++, (if you feel you need to),
then you can forget about C# (scripting)...
-
then you can forget about C# (scripting)...
Hehe, I find this funny :) . I think C# is a wonderful language. Sure, it's bigger, slower, not-as-hardcore, etc., but when you actually need to get something done quickly it's a wonderful tool to have. And I certainly wouldn't call it a scripting language, if that's what you're implying :) .
-
I like C# as a work tool too.. Even more than VB, it's much more concise, and as Ferris says, very rapid to develop applications with which means more time to surf the internet.
-
dont get me wrong,
I've nothing against c# as a language, but its not C or C++ and shouldnt be compared as such.
i'm sure its a fine language and yeh as a Rapid dev tool its great
like VB was great, but i feel for serious stuffs you need complete control ( C / C++ & asm).
my nephew plays around with C# & xna but hasnt a clue on how the computer actually draws a pixel onto the screen.
these languages shield you from the down and dirty and ultimately
stunt learning.
sorry, its just my opinion and i totally support others, its a free world
-
No worries, man. And yeah, they DO shield alot of that stuff, because it's often not stuff one wants to be thinking of when implementing large-scale projects or more often, "trash projects" - one-time-use programs made for a specific purpose in a hurry.
Back to the original post, each should be learned, I think. Not only do the concepts exposed in each language make you a better coder, but you learn what you can use in different situations.
And of course, coding in the lower-level environments gives you an opportunity to learn the nitty-gritty stuff, as Dark_Coder mentioned.
-
sorry, its just my opinion and i totally support others, its a free world
-
You kidding man! 400 Pounds is more than what I earn in a month! LOL
-
yeh, the rewards are there if you can do it.
when i first started coding way back on the zx spectrum it was all in basic for the first two years. There was one person who stopped me learning machine code and the hardware in that time (myself).. i look back and think wasted two years hehe :) .
so i say. dont be shy , dive in, use other peoples source code to help you understand.
if you do you wont look back nor would you want to.
there isnt any wrong way to program something, just different ways (wrong is when it just doesnt work)
oh going off on a tangent now, will stop