|
On April 24 2012 05:40 blade55555 wrote:Show nested quote +On April 24 2012 03:25 GogoKodo wrote:On April 24 2012 02:48 fire_brand wrote: Don't start with C. It'll teach you the wrong stuff. You're better off learning something else that's actually useful. C actually will hinder your learning later on. Learning C will not teach you the "wrong stuff", whatever that is, and C is definitely useful. From what I read when I was teaching myself programming most people agreed that learning C first would give you bad habbits that will cause many problems in c+ and what not.
I'm a senior CS undergraduate student and I honestly wish that my University picked C or C++ as its main language instead of java. While java might be an easy language to pick up, I feel extremely gimped in regards to understanding dynamic memory management and trash collection. I am pretty fluent and Java and learning C++/C right now so I can actually get a job because there seems to be little demand for Java programmers in all the jobs that I have applied for so far. If anything learning Java first over C has taught me more bad habits than I think learning C would have. A good book to start with is http://www.amazon.com/Programming-Modern-Approach-2nd-Edition/dp/0393979504?tag=tealiq-20 This is the one I am using to guide my own studies.
As for differences, I think the most defining ones are C++ is basically C with object orientation and a ton more tools to make your life easier Java and C# are really similar in that they run with virtual machines and they are super high level languages that have a lot of automation and built in safety.
edit: spelling
|
I think the most common starting language is either C++ or Java. I think C++ is better to start with. The basic syntax is far easier to understand. Take a C++ hello world:
#include <iostream> using namespace std; int main() { cout << "Hello, World!"; return 0; }
compared to a Java Hello, World:
public class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World!"); } }
In C++, you don't have to think about what public, static, void, or class mean. The other major part about C++ is pointers. Everyone should play with pointers and understand how they work. In Java, every object works essentially as a pointer. Java is an easier language to program in once you are familiar with programming, but C++ is easier to start and better for learning.
|
No idea how old you are, but I guarantee if you go get some advanced certificates in Java programming you're going to get hired very fast in America. There's so many java programming jobs right now. I understand it decently but I just don't like programming enough to do it day-in and day-out. If you can stand it you could be making 80$/hour....
|
I learned C as my first programming language and I can recommend to anyone to do it as well. It will give a solid foundation for learning other languages and well as forcing you to learn some computer concepts along the way. There are plenty of applications of C, like Linux programming, embedded devices, etc. It will also be straightforward to learn C++ from there.
If you get a chance get K&R book either as your main book or as a companion to whatever book you are reading. It's a classic.
|
Sorry for the double post. I blame TL iPhone app/
|
|
On April 26 2012 06:11 adwodon wrote:Show nested quote +On April 24 2012 06:11 olabaz wrote:So I also recently decided to learn C and have been learning for a couple of days now. The book recommended by MIT as well as a bunch of other legitimate sources seems to be C Programming Language. I looked into this book and did not really like that they didn't give the main function a return value. I then found out about another book that is widely accepted called C Programming: A Modern Approach and I really like the way it is written and laid out so far, and it is what I'll be using. A larger list of books can be found here. I was told by a lot of people not to learn C but I feel like it'll be a fun exciting language that will help me in the my future studies of physics. Haters gonna hate! I was one of the better programmers when I did my MSc in particle physics, not that I could have a valid opinion... C will not help you in physics, it will probably just hinder you, but you've obviously been told this and think you know better. Most physicists stuck with FORTRAN for the most part, they're switching over to C++ with a lot of the larger collaborations (event generators etc) because OO is too useful. If you're serious about physics over programming you'll not need to go in depth with anything, just learn Java then C++ and some scripting languages, as well as how to use Unix and you'll be fine, you'll learn what you need when you need. As people have said, C is for low level things, learning it will serve no purpose in the physics world and you'll simply have to erase bad habits when you learn a more appropriate language. C is not useless for physics...
|
On May 05 2012 06:40 olabaz wrote:Show nested quote +On April 26 2012 06:11 adwodon wrote:On April 24 2012 06:11 olabaz wrote:So I also recently decided to learn C and have been learning for a couple of days now. The book recommended by MIT as well as a bunch of other legitimate sources seems to be C Programming Language. I looked into this book and did not really like that they didn't give the main function a return value. I then found out about another book that is widely accepted called C Programming: A Modern Approach and I really like the way it is written and laid out so far, and it is what I'll be using. A larger list of books can be found here. I was told by a lot of people not to learn C but I feel like it'll be a fun exciting language that will help me in the my future studies of physics. Haters gonna hate! I was one of the better programmers when I did my MSc in particle physics, not that I could have a valid opinion... C will not help you in physics, it will probably just hinder you, but you've obviously been told this and think you know better. Most physicists stuck with FORTRAN for the most part, they're switching over to C++ with a lot of the larger collaborations (event generators etc) because OO is too useful. If you're serious about physics over programming you'll not need to go in depth with anything, just learn Java then C++ and some scripting languages, as well as how to use Unix and you'll be fine, you'll learn what you need when you need. As people have said, C is for low level things, learning it will serve no purpose in the physics world and you'll simply have to erase bad habits when you learn a more appropriate language. C is not useless for physics...
C is the backbone language for SO many other languages and is still used for MANY applications and systems.
|
On April 26 2012 07:06 darthcaesar wrote: I think the most common starting language is either C++ or Java. I think C++ is better to start with. The basic syntax is far easier to understand. Take a C++ hello world:
#include <iostream> using namespace std; int main() { cout << "Hello, World!"; return 0; }
compared to a Java Hello, World:
public class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World!"); } }
In C++, you don't have to think about what public, static, void, or class mean. The other major part about C++ is pointers. Everyone should play with pointers and understand how they work. In Java, every object works essentially as a pointer. Java is an easier language to program in once you are familiar with programming, but C++ is easier to start and better for learning. This is complete and utter bullshit. C++ is far more complicated, feature rich and requires annoying memory and pointer management. It does not force you to use a certain style (object oriented, like java) and is generally probably the most beginner unfriendly language you could find (of the major ones, stuff like lisp and caml not included). Pointers are a bad argument, modern languages stray away from them, because they are a major source of errors.
No, I'm not bashing on C++ as a language in general, I just think that it's not suited for beginners. When you start out, you want to write programs that work, not fight with compilers, linkers, memory leaks, buffer overflows, header files etc. I would recommend java, although not because of the language itself, but because the library and the IDE eclipse, which are very easy to use and learn with - plus there is a lot of material and the language is used widely. You can do pretty much everything in Java with the standard library.
I understand that you want to learn C, but I would really not recommend it. It does teach you a lot about hardware, memory management etc., but it does not teach you how to be a good programmer. To put it into an RTS anology:
Java is SC2 C++ would probably be Brood War C is Dune2
which one would you want to learn RTS with?
|
Dunno why there's so little support for python or ruby. In terms of just learning to think the right way, those are probably the best bet. Very little getting between you and making stuff happen. Plus, interactive interpreter is great for experimenting and discovering new ideas. I personally don't really like ruby, but expect it's just because I'm not cool enough to "get" it. Several programmers I respect technically really like it.
I'd be interested to hear more about C/C++ teaching bad habits. I write C daily, and have worked with java, C++, perl (gak), and python codebases professionally. My first language happens to have been C++. I've found that most if not all "bad habits" arise from ignorance and poor instruction, and aren't really the sort of thing that a language forces on you.
If you're just learning to program, and particularly if you want to learn C, I highly recommend finding someone(s) that's willing to look over your code. Some things don't really communicate well in books and benefit greatly from having experience looking over your shoulder.
|
I really hate that Ruby forces no types. I find the lack of type fixing very useful at times, but at others it's extremely detrimental. My game is coming along quite nicely, and it is purely done in Ruby. (lol Ruby game)
|
It's really quite incredible how the OP clearly isn't showing an interest in any other languages and yet you guys keep rambling on about this language is better than that - blah blah blah.
Arnstein, C is a wonderful language. It is mainly used for systems programming, so it is a very low level language. Fortunately, it's a no-bullshit language, meaning code is usually very direct and easy to follow. C is not an object-oriented language, so you will not run into things like "classes" or "inheritence", which can sometimes lead to some very ugly and confusing code.
I will explain the difference between some higher level languages and C, and you could use that to decide where you would like to start, if your heart is not already set on C. This should give you a good perspective on what you will be embarking on. Most really high level languages have these:
- Object-Orientedness - Garbage Collection/ Automated Memory Management - Lack of pointers - Security
Object-Orientedness + Show Spoiler + Objects and object-oriented programming languages were something designed to make human design of programs simpler. The entire idea behind an Object is that you group similar properties and functions of a "real-life" object into one cute name.
Here's an example to give you a better idea. Suppose you were designing a video game and inside that video game there are tanks. We can even take the Seige Tank is starcraft as a concrete example. If were to think about the important PROPERTIES of a tank we could make a short list, something like this:
- Armor - Damage - Health - Speed
And if we were to think of some important functions or actions of a tank we could come up with something like this:
- Attack - Seige Mode - Stop - Move
Now I can create an "object" that groups all these properties together to make it easy for myself. I could say:
myTank.Armor = 3; <- This would change the armor value of the tank to 3 myTank.Damage = 10000; <- Holy crap that's STRONG!!!
C lacks the ability to create objects directly. However, in can still be done pretty similarly to most high-level langauages through the use of structures. You will learn about those eventually.
Garbage Collection/ Automated Memory Management + Show Spoiler + As you may imagine, inside your program you will be creating a bunch of variables, objects, strings, and all sorts of stuff. Well, who is keeping track of all that stuff? When should stuff be destroyed and when should it be kept?
The answer to this question depends on what language you are programming in. Most really high level languages like java, C# and many others have what is called Garbage Collection and Automated Memory Management.
Garbage Collection and automated memory management is exactly what it sounds like. Your program will cycle through all the stuff you've made and delete things that it thinks you will no longer ever use. Most of the time this works pretty well, meaning you can program-and-go and not have to think about problems with memory space running out or using something you shouldn't be using.
C does not gave garbage collection. You will be doing everything manually, so you must keep track of all variables, pointers, and memory that you use. This may sound daunting, and sometimes it can be, but unless you're solo making software to manage an entire airplane that spans over a million lines of code it probably would not bother you too much.
Lack of pointers + Show Spoiler +Pointers? What the hell is a pointer, anyway? A pointer is exactly what it sounds like. It's a VARIABLE that points to something. More technically, pointers point to addresses of memory inside a computer. Snooze. Sounds simple, right? Apparently it's not. Pointers can be too compliated for some programmers, which is why languages like java and C# have allegidly gotten rid of them. I say allegidly because pointers are such a fundamental part of modern day computers that there really is so escpating them. Really high level languages like java HIDE all the pointer operations going on the background to make programming more trivial. C does not. You will be dealing with pointers DIRECTLY, and often times even things you think are simple library functions will use pointers. To give a crude example, say you wanted to copy a string. Well. cplusplus.com has a great resource that lays out the common C libraries very nicely for you. You will be using these libraries very often, so keep this link handy! Link is: http://www.cplusplus.com/reference/clibrary/Let's take a look at strcpy() (Short for String Copy) Link is: http://www.cplusplus.com/reference/clibrary/cstring/strcpy/" char * strcpy ( char * destination, const char * source ) " This part is the meat of the function. Almost every time you see an ASTERISK (*) in a program in C, it's a pointer. So this function takes in two pointers and even returns a pointer! Just to copy a string!! The truth about the matter is that pointers require getting used to, but living without them is impossible. They are wonderful and really amazing tools in a programming language.
Security + Show Spoiler + I realize this probably doesn't matter for you, but higher level languages are generally more secure. That's because majority of low level control is hidden from you. You must realize that your program will be grossly insecure in C. So if you plan on writing an FTP server where people will be submitting personal information, I'd look into learning about how to program securely.
A quick word about C++. The thing that makes C++ interesting is that it's not really a very low level language nor is it a very high level language. C++ is object oriented, however, it doesn't not have memory management and still has pointers. It's really an "in-the-middle" programming language.
C is a great choice for a first programming language, especially if you're a computer scientist. Seems like your degree will be quite technical, so you might be dealing with low level issues and programming a lot. Might as well learn C. And the beautiful thing about C is that it transitions into other languages perfectly. I wrote a post in the "Big Programming Thread" elaborating on this that got updated to the OP. Feel free to check it out. http://www.teamliquid.net/forum/viewmessage.php?topic_id=134491
Let's get started on C! I won't be teaching you the "technical" part of programming because there are a million tutorials out there. I will be teaching you the most important part yet least covered and most confusing part. Setting up your compiler and compiling your first program. I'm going to teach you how to do it on WINDOWS, because most people will be using windows and I want this post to be general. Also, because codeblocks is abysmal trash. Same idea on any OS, really. So we have two things we want do.
Installing, compling, and understanding GCC, which is part of the GNU compiler collection, is our main goal here. Here are the steps:
- Get GCC/GNU via an IDE. - Add the /bin directory to your PATH enviornment variable, allowing you access to a command line compiler as well as other programs.
In case you were wondering, the GNU compiler collection is a set compilers for multiple programming languages. GCC, which is probably the most famous C compiler, is part of the GNU compiler collection.
Part 1: Get GCC/GNU via an IDE
The IDE I'm going to be using here is called dev c++. In truth, this is not a very good IDE but it's great because it's simple to install and use. It's small, supports both C and C++, and contains a /bin folder with the entire GNU compiler collection, which we will use in part 2. So let's head over to dev c++'s site and download and install it. Link: http://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++ 4.9.9.2/devcpp-4.9.9.2_setup.exe/download
Installing this is just like installing any program. If you can't figure this part out, you probably shouldn't be trying to program anyway. Once it's install, run it and you will see this.
+ Show Spoiler +
Go to File > New > Project... This will open a new tab. Make sure you have Console Application Selection, and make sure C Project is selected at the bottom. You can choose to make it the default language as well. Give the project a name and hit OK. Copy and paste this into the big white portion where all the code is.
+ Show Spoiler + #include <stdio.h>
int main(int argc, char *argv[]) { printf("Hello World!! \n"); system("PAUSE"); return 0; }
The four buttons I have boxed in red are really your favorite buttons. Compile, run, Compile and run, and rebuild. Hit the compile and run button, and your program should be up and running! Congradulations, you've compiled and ran your first program!
You can use dev to start programming and expiermenting with stuff. Have fun with it!
Part 2: Add the /bin directory to your PATH enviornment variable Hit the windows key + r. This will open up run. Type in "cmd" and press enter. Welcome to command prompt! Now, if you've ever done something like type "ping google.com", then I'm sure you've wondered what the hell is going on. This is command prompt running the PING program, which happens to be a command line program. GCC is a command line compiler. Dev C++ makes it all dolled up and cute for you, but really it's just running the GCC command line compiler for you with your source code.
What we need to do is add "gcc" and all the accompanying programs to your windows PATH variable so you can call it for any directory. This will let you use the command line compiler to compile anywhere with any options you like, as well use the accompanying programs. This will come in handy because a lot of tutorials use the command line compiler and I don't want you to feel left out.
Check out the "C:\Dev-Cpp\bin" directory. Notice the gcc.exe and all the other wonderful programs? For those of you NOT using dev, head over to google and use it to download the GNU compiler collection. Install and navigate to the /bin folder. Make sure it has gcc and ld inside that directory. Copy the path, as you will be adding it to your PATH variable to call it from anywhere.
To add that entire directory to your PATH environment variable, go to system properties ( shortcut: windows key + pause|break ) Click "Advanced System Settings" and click the "Enviornment Variables" button.
Warning: Do not randomly change stuff in here. You WILL break your computer. Under "system variables" scroll down until you find PATH. Edit it, and at the end append ";C:\Dev-Cpp\bin" The semicolon seperates paths. Mine, overall, looks like this:
+ Show Spoiler + C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Dev-Cpp\bin
WARNING: DO NOT COPY MINE. JUST AN EXAMPLE.
Click okay, save, blah blah blah, and reopen command prompt and type "gcc -v". Some of you might need to restart your computer. You should see a bunch of info if it worked.
Now create a file on your desktop and call it main.c. Copy the code from above. Change the command prompt directory to your desktop, and type "gcc -o myfile.exe main.c". Congrats! You've succesfully compiled using the command line compiler. For those of you need help with the command prompt commands: + Show Spoiler + "cd" changes your directory. Example 1: cd C:\Windows Example 2: cd Desktop
"dir" lists all files in the directory. Example: dir
Use these to navigate to your desktop.
For those of you wondering why this might be useful, it's because you can now use GCC's full potential without IDE restriction. What do i mean? Well... in the same above scenerio, type "gcc -S main.c" and find a file called main.s on your desktop. Gasp! Voodoo magic, what kinda of code is THAT? Blasphemy, says I!
Enjoy. Hope this helps some of you. Feel free to IM/PM me if you ever need any help.
|
On May 05 2012 06:40 olabaz wrote:Show nested quote +On April 26 2012 06:11 adwodon wrote:On April 24 2012 06:11 olabaz wrote:So I also recently decided to learn C and have been learning for a couple of days now. The book recommended by MIT as well as a bunch of other legitimate sources seems to be C Programming Language. I looked into this book and did not really like that they didn't give the main function a return value. I then found out about another book that is widely accepted called C Programming: A Modern Approach and I really like the way it is written and laid out so far, and it is what I'll be using. A larger list of books can be found here. I was told by a lot of people not to learn C but I feel like it'll be a fun exciting language that will help me in the my future studies of physics. Haters gonna hate! I was one of the better programmers when I did my MSc in particle physics, not that I could have a valid opinion... C will not help you in physics, it will probably just hinder you, but you've obviously been told this and think you know better. Most physicists stuck with FORTRAN for the most part, they're switching over to C++ with a lot of the larger collaborations (event generators etc) because OO is too useful. If you're serious about physics over programming you'll not need to go in depth with anything, just learn Java then C++ and some scripting languages, as well as how to use Unix and you'll be fine, you'll learn what you need when you need. As people have said, C is for low level things, learning it will serve no purpose in the physics world and you'll simply have to erase bad habits when you learn a more appropriate language. C is not useless for physics...
Care to elaborate?
If you want to learn physics, learn physics, don't add complex programming languages on top of that. You'll have a much easier time, and find it easier to apply something like Java to a physics undergrad course.
I'm sure you can find some use for C, but I've never come across a physicist in academia that uses C, it's not the ideal language and most physicists want to do physics, not programme, but if you think you can somehow squeeze 8 extra hours out of each day to double up your discipline then go ahead.
Why not just do a Computer Science degree?
Don't say I didn't warn you.
|
On May 05 2012 18:35 Abductedonut wrote: It's really quite incredible how the OP clearly isn't showing an interest in any other languages and yet you guys keep rambling on about this language is better than that - blah blah blah.
Maybe thats because the OP asked about learning to code in C then went on to ask what the difference between C++ and C# is.
Sorry, but if you don't know that yet you probably shouldn't be diving right into C, its like saying hey the kid wants to learn to ski down black diamond routes, I see no reason why not, it's what he asked for! It's far easier, especially when learning under your own steam to learn more about the different types of languages and start with something easier, which is what people are recommending which also has fun applications.
Especially since a lot of us probably remember wanting to learn a language, in most cases probably C / C++ and not knowing the differences just blindly went into it only to find out it was completely the wrong language to learn at the time.
The only circumstance I would think learning C first would be appropriate would be if you were on a CS course, learning all the other things about computer systems and being taught in a formal manner, otherwise you're just going to make mistakes.
|
Thanks for so many replies people! You are all good sources of information, and very helpful!
For those wondering why I absolutely wants to learn C: Next year I'm hopefully starting to study technical cybernetics, and the first language I will learn there is C. I want to start now so the first semester won't be THAT tough(even though people say it's the most intense and theoretically hard study after nanotechnology).
|
You really should go for C++ and not C, C is really outdated! ^_^
/Just my opinion!
|
On May 14 2012 06:15 og8456 wrote: You really should go for C++ and not C, C is really outdated! ^_^
/Just my opinion!
This could not be farther from the truth.
|
I wonder if anyone actually reads OP's posts here? More than once he clearly said he is going to work with cybernetics so it's obvious he is going to need some low-level grip, C is probably the best language one could ask for that.
|
On May 14 2012 06:17 Anacletus wrote:Show nested quote +On May 14 2012 06:15 og8456 wrote: You really should go for C++ and not C, C is really outdated! ^_^
/Just my opinion! This could not be farther from the truth. It's from 1970. That alone should probably tell you that it's outdated
Is it still widely used and has its own niches where it is best? Absolutely! Does that make it a good modern programming language? Nope!
|
While it's definately true that C has many areas of application its also true that as a beginner, you'll be spending way too much time worrying about various C quirks rather than PROGRAMMING. Language is but a tool and ultimately it won't matter what you started out with but by choosing beginner friendly language you'll assimilate core programming ideas much faster. If you go with C you'll have to learn about pointers and other shit and generally waste your time. Go learn C when you have some development experience under your belt and you'll save yourself a lot of time.
|
|
|
|