Author Topic: Which version of C?  (Read 18336 times)

0 Members and 5 Guests are viewing this topic.

Offline Zeb

  • C= 64
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
    • Amiga Software Downloads
Which version of C?
« 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
« Last Edit: February 22, 2011 by Zeb »
if (empty($coffee)) {new $coffee();} else {drinkCoffee('fast');}

Amiga coder (assembler, E), PC coder (learning C)

PC SPECS:
W7 x64 Ultimate, AMD Athlon X2 Dual Core 5200 @ 2.6GHz, 4GB DDR2 PC6400 (800) RAM, JeanTech Storm 700W PSU, ATI Radeon X1650 Pro 256MB PCI-Ex16, SoundBlaster Audigy Platinum 2 eX, 3TB hard drive storage, Dual 22"WS TFT, Epson R300 printer, Epson V100 Perfection scanner, DL-DVD-+RAM/ROM/RW, DL-DVD-+RW, X7 laser gaming mouse and more...

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Which version of C?
« Reply #1 on: February 22, 2011 »
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.

Challenge Trophies Won:

Offline Xetick

  • Atari ST
  • ***
  • Posts: 132
  • Karma: 80
    • View Profile
    • Plane9
Re: Which version of C?
« Reply #2 on: February 22, 2011 »
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.

Plane9 - Home of the Plane9 3d screensaver/music visualizer
Challenge Trophies Won:

Offline Zeb

  • C= 64
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
    • Amiga Software Downloads
Re: Which version of C?
« Reply #3 on: February 22, 2011 »
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.
if (empty($coffee)) {new $coffee();} else {drinkCoffee('fast');}

Amiga coder (assembler, E), PC coder (learning C)

PC SPECS:
W7 x64 Ultimate, AMD Athlon X2 Dual Core 5200 @ 2.6GHz, 4GB DDR2 PC6400 (800) RAM, JeanTech Storm 700W PSU, ATI Radeon X1650 Pro 256MB PCI-Ex16, SoundBlaster Audigy Platinum 2 eX, 3TB hard drive storage, Dual 22"WS TFT, Epson R300 printer, Epson V100 Perfection scanner, DL-DVD-+RAM/ROM/RW, DL-DVD-+RW, X7 laser gaming mouse and more...

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Which version of C?
« Reply #4 on: February 22, 2011 »
Quote
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
Challenge Trophies Won:

Offline LittleWhite

  • Senior Member
  • Amiga 1200
  • ********
  • Posts: 418
  • Karma: 31
  • It's me!
    • View Profile
Re: Which version of C?
« Reply #5 on: February 22, 2011 »
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)
The demoscene will never die, never!

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Which version of C?
« Reply #6 on: February 23, 2011 »
Apparently there is an SDL.Net! http://cs-sdl.sourceforge.net/  Why you would do this to yourself I don't know :P

Jim
Challenge Trophies Won:

Offline Zeb

  • C= 64
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
    • Amiga Software Downloads
Re: Which version of C?
« Reply #7 on: February 23, 2011 »
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?
if (empty($coffee)) {new $coffee();} else {drinkCoffee('fast');}

Amiga coder (assembler, E), PC coder (learning C)

PC SPECS:
W7 x64 Ultimate, AMD Athlon X2 Dual Core 5200 @ 2.6GHz, 4GB DDR2 PC6400 (800) RAM, JeanTech Storm 700W PSU, ATI Radeon X1650 Pro 256MB PCI-Ex16, SoundBlaster Audigy Platinum 2 eX, 3TB hard drive storage, Dual 22"WS TFT, Epson R300 printer, Epson V100 Perfection scanner, DL-DVD-+RAM/ROM/RW, DL-DVD-+RW, X7 laser gaming mouse and more...

Offline LittleWhite

  • Senior Member
  • Amiga 1200
  • ********
  • Posts: 418
  • Karma: 31
  • It's me!
    • View Profile
Re: Which version of C?
« Reply #8 on: February 23, 2011 »
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.
The demoscene will never die, never!

Offline Zeb

  • C= 64
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
    • Amiga Software Downloads
Re: Which version of C?
« Reply #9 on: February 23, 2011 »
LittleWhite, is that just C# or is the MSDN compatible with C++ as well?
if (empty($coffee)) {new $coffee();} else {drinkCoffee('fast');}

Amiga coder (assembler, E), PC coder (learning C)

PC SPECS:
W7 x64 Ultimate, AMD Athlon X2 Dual Core 5200 @ 2.6GHz, 4GB DDR2 PC6400 (800) RAM, JeanTech Storm 700W PSU, ATI Radeon X1650 Pro 256MB PCI-Ex16, SoundBlaster Audigy Platinum 2 eX, 3TB hard drive storage, Dual 22"WS TFT, Epson R300 printer, Epson V100 Perfection scanner, DL-DVD-+RAM/ROM/RW, DL-DVD-+RW, X7 laser gaming mouse and more...

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Which version of C?
« Reply #10 on: February 23, 2011 »
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
Challenge Trophies Won:

Offline Xetick

  • Atari ST
  • ***
  • Posts: 132
  • Karma: 80
    • View Profile
    • Plane9
Re: Which version of C?
« Reply #11 on: February 23, 2011 »
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.
Code: [Select]
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.
Plane9 - Home of the Plane9 3d screensaver/music visualizer
Challenge Trophies Won:

Offline Zeb

  • C= 64
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
    • Amiga Software Downloads
Re: Which version of C?
« Reply #12 on: February 23, 2011 »
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.

:)
if (empty($coffee)) {new $coffee();} else {drinkCoffee('fast');}

Amiga coder (assembler, E), PC coder (learning C)

PC SPECS:
W7 x64 Ultimate, AMD Athlon X2 Dual Core 5200 @ 2.6GHz, 4GB DDR2 PC6400 (800) RAM, JeanTech Storm 700W PSU, ATI Radeon X1650 Pro 256MB PCI-Ex16, SoundBlaster Audigy Platinum 2 eX, 3TB hard drive storage, Dual 22"WS TFT, Epson R300 printer, Epson V100 Perfection scanner, DL-DVD-+RAM/ROM/RW, DL-DVD-+RW, X7 laser gaming mouse and more...

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Which version of C?
« Reply #13 on: February 24, 2011 »
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
Challenge Trophies Won:

Offline pikzel

  • ZX 81
  • *
  • Posts: 2
  • Karma: 2
    • View Profile
Re: Which version of C?
« Reply #14 on: March 08, 2011 »
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?

Offline JL235

  • C= 64
  • **
  • Posts: 71
  • Karma: 9
    • View Profile
    • Play My Code
Re: Which version of C?
« Reply #15 on: March 20, 2011 »
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!
Play My Code - build games in your browser!

Offline Zeon

  • ZX 81
  • *
  • Posts: 3
  • Karma: 2
    • View Profile
Re: Which version of C?
« Reply #16 on: March 28, 2011 »
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

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Which version of C?
« Reply #17 on: March 28, 2011 »
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);


Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Which version of C?
« Reply #18 on: March 28, 2011 »
You can use all methods without any of that prefixing stuff by putting
Code: [Select]
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,
Code: [Select]
ICanFeelIt.MessageBox()
OtherLib.MessageBox()

Jim
Challenge Trophies Won:

Offline JL235

  • C= 64
  • **
  • Posts: 71
  • Karma: 9
    • View Profile
    • Play My Code
Re: Which version of C?
« Reply #19 on: March 30, 2011 »
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.
Play My Code - build games in your browser!