Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
Dirge
Gerbil Jedi
Topic Author
Posts: 1620
Joined: Thu Feb 19, 2004 3:08 am

I have a question about C and C++

Sat Apr 02, 2005 7:42 pm

I am keen to learn a programing language and develop for the free software community. According to the GNU coding standards it is recommended developers use C rather than comparable alternatives.

I wonder if C is still a useful language or only good for maintaining legacy code? Is it necessary to learn C before C++ or should I just learn the newer C++.
FDISK /MBR
 
daveagn
Gerbil XP
Posts: 468
Joined: Wed Jun 02, 2004 5:44 pm

Sat Apr 02, 2005 7:47 pm

By the looks of this graph http://www.cs.berkeley.edu/~flab/languages.html either is a good choice.
 
UberGerbil
Grand Admiral Gerbil
Posts: 10368
Joined: Thu Jun 19, 2003 3:11 pm

Sat Apr 02, 2005 8:04 pm

It's not really an either/or choice. C++ started life as an object-oriented extension to C (it was originally implemented as a set of preprocessor directives that converted C++ into regular C source). A lot of what you learn in C carries over to C++. It's a bit like learning Latin before Italian, or algebra before calculus. Know the former can lead you astray from time to time when learning the latter, but by and large it gives you an advantage. Once you get past the basic syntax, the biggest hurdle for most people learning C is understanding pointers. For C++ it is understanding objects (and everything that goes with them -- inheiritance, polymorphism, etc). They're both conceptual hurdles of the same order.
 
Sparrow
Gerbil Elite
Posts: 669
Joined: Sun Mar 06, 2005 3:11 pm

Re: I have a question about C and C++

Sat Apr 02, 2005 8:12 pm

Dirge wrote:
I wonder if C is still a useful language or only good for maintaining legacy code? Is it necessary to learn C before C++ or should I just learn the newer C++.


C and C++ share a great deal. C++ is just C with objects, meaning most anything you write in C is valid C++ code. Once you learn C++ , you know C. It's good to know the difference though, because for a lot of things, you will only need C. But there are certain occasions where C++ comes in handy. Object-oriented programming is a pretty big topic though, so I won't try to get into all that right here.

But anyhow, C is a good foundation. Both languages do have some quirks that you have to watch out for, though (like pointers, as UberGerbil mentioned). Take it slow.

Good luck, and have fun!
 
sativa
Grand Gerbil Poohbah
Posts: 3044
Joined: Sun Apr 14, 2002 7:22 pm
Location: lafayette, la

Sat Apr 02, 2005 8:20 pm

Since C++ encompases C (and adds some).. learn C++.

Everything is moving towards object orientation so ... might as well. Once you learn C++, learning Java is a breeze.
Science is forbidden. Laboratories manufacture danger!
 
Yahoolian
Grand Gerbil Poohbah
Posts: 3577
Joined: Sun Feb 16, 2003 3:43 pm
Location: MD
Contact:

Sat Apr 02, 2005 8:23 pm

I'd say learn Ruby, it looks like a much better language for beginners than C/C++.

For instance, hello world in Ruby is simply

puts 'Hello World'


If you want to get into C/C++ you can always do that later. But those languages are more suited for experienced programmers, IMO.
Last edited by Yahoolian on Sat Apr 02, 2005 8:26 pm, edited 1 time in total.
 
daveagn
Gerbil XP
Posts: 468
Joined: Wed Jun 02, 2004 5:44 pm

Sat Apr 02, 2005 8:24 pm

Yeah, but not nearly as much stuff is coded in Ruby.
 
Yahoolian
Grand Gerbil Poohbah
Posts: 3577
Joined: Sun Feb 16, 2003 3:43 pm
Location: MD
Contact:

Sat Apr 02, 2005 8:27 pm

Yeah, but you can always learn C/C++ later....
 
Fearless
Gerbil First Class
Posts: 153
Joined: Tue Jan 01, 2002 7:00 pm
Location: Colorado Springs, CO

Sat Apr 02, 2005 8:33 pm

Just repeating what most have said. C++ grew from C. It is possible to write a pure C program and compile it with a C++ compiler. The only difference in the object code will be an artifact of C++ called name mangling (which enables overloading functions with the same name and different arguments).

In fact it *is* possible to write an object oriented program with straight C using function pointers (a construct/concept that allows you to keep something akin to a phone number of the function). Just a pain is all.

The *big* differences in coding right now are not the language but the approach. Object oriented vice functional decomposition. Functional is easier to grasp for most people. First you do a then you do b, etc. Object oriented is more trying to describe things in the world -- what is everything you can do with a car?.... Apply brakes, Apply gas, turn wheel, etc. Finding the right breakdown to you problem with objects starts boardering on art and will come with practice. Using the above example... abstract the car into a vehicle so that you can have different behavior for a truck appling the breaks (ie uses a different formula). So at a more generic driver level, the same call to the generic vehicle object has different derived behavior for a car than for a truck based on which was instantiated.

Having never done much coding before I would start you with functional. As I said easier to understand and for small things easier to write.

If you don't have a compiler yet I would get the C++ Gnu one (open source). As I said -- will work with either style.

Hope I didn't muddy things too much. :wink:
Image
 
Dirge
Gerbil Jedi
Topic Author
Posts: 1620
Joined: Thu Feb 19, 2004 3:08 am

Sat Apr 02, 2005 8:35 pm

Thanks daveagn for your link, I found it very interesting. It looks like C is still a very popular language.

I guess I am swayed by the GNU coding standards into considering C first. But it is good to hear C/C++ are so similar.

My next problem is choosing a good introductory text. Thanks to Craig P. from another thread in this forum I have a link to a good list of book reviews.

If anyone could recommend good online tutorials it would be a help :)
FDISK /MBR
 
Dirge
Gerbil Jedi
Topic Author
Posts: 1620
Joined: Thu Feb 19, 2004 3:08 am

Sat Apr 02, 2005 8:41 pm

Yahoolian wrote:
I'd say learn Ruby, it looks like a much better language for beginners than C/C++.

For instance, hello world in Ruby is simply

puts 'Hello World'


Ruby looks pretty damn cool, certainly some thing I will look at in the future.
FDISK /MBR
 
Yahoolian
Grand Gerbil Poohbah
Posts: 3577
Joined: Sun Feb 16, 2003 3:43 pm
Location: MD
Contact:

Sat Apr 02, 2005 8:48 pm

Really, I recommend learning Ruby first. There are plenty of open source Ruby projects, for instance one that interests me is Instiki.

Also if you should consider Perl if you are thinking about the code base. Just take a look at CPAN.

But this whole notion of learning a language because of it's popularity seems like a bad idea to me. Pick a language based on how easy it is to learn, and if you want to learn the harder languages save that for later. Heck TI BASIC was my first language...

Anyways, you can take a look at Programming Ruby by The Pragmatic Programmers to learn it online.

What kind of stuff are you interested in? If you want to do low-level, close to the hardware type stuff then you should learn C/C++. Otherwise I recommend against it, there are many better languages out there.
 
Forge
Lord High Gerbil
Posts: 8253
Joined: Wed Dec 26, 2001 7:00 pm
Location: Gone

Sat Apr 02, 2005 9:16 pm

I chose to start with C because my Gentoo install gives me a valid C/C++ toolchain and I have *lots* of source code to consult/poke at. As soon as I have a pretty good grasp of C, though, I'm going to toss the second half of the C++ books I have in, as I see them as two flavors of one language, and intend to learn them as such.

Just my approach, though.
 
Grumpy_Eel
Gerbil Elite
Posts: 772
Joined: Fri Oct 18, 2002 4:16 pm

Sat Apr 02, 2005 10:09 pm

Ive taken java, visual basic, and am currently in ap computer science (which is just advanced java) I wish they offered C++, i know they used to, but stopped for some reason. But w/e its not like i actually want to be a programmer, just need some class to surf the internet in. :D
Your body slaughters millions of bacteria every second... you genocidal maniac.
 
Buub
Maximum Gerbil
Posts: 4969
Joined: Sat Nov 09, 2002 11:59 pm
Location: Seattle, WA
Contact:

Sat Apr 02, 2005 11:37 pm

I will have to take an opposing view to many who have posted here. C++ may symantcally have developed as "C with objects", but logically, how they are used in the real world today, they couldn't be much further apart.

I personally feel that learning C first will put you at a disadvantage when learing C++. You will approach C++ from a C-with-extras approach, and that's not at all how C++ should be used.

You would be far better served to learn C++ after having learned Java. I think it's very important to solidfy the object-oriented concepts. Then, when you get to C++, because it is much lower-level, you need to move to the next step which is extending that object knowledge to smart containers, smart-pointers, etc. It's possible to write a very functional, powerful C++ program where you never see or touch a raw pointer. Without approaching the problem from the new-world C++ paradigm, that might not even occur to you; you might just use a pointer because that's how you've always done it, and because it's most familiar.

Yes, to answer the original question, C is most useful for maintaining legacy code. There are some very small-scale embedded applications where it's used just because they need the smallest memory footprint possible. Other than that, there is very little reason to use C.

My recommendation is to learn Java, C++, then C. C should be a cinch once you know C++, because in this case you'll be approaching it from the C++-without-stuff mindset.
 
Taddeusz
Minister of Gerbil Affairs
Posts: 2618
Joined: Wed Jun 04, 2003 6:16 pm
Location: Oklahoma City
Contact:

Sun Apr 03, 2005 12:05 am

I would learn C first. In most school curricula C is a prereq for C++. Learning C first gives you a good foundation for knowing the general syntax of the language. You really can't learn C++ without learning C first because as everyone has said, it's basically an extention for C.
 
Sparrow
Gerbil Elite
Posts: 669
Joined: Sun Mar 06, 2005 3:11 pm

Sun Apr 03, 2005 12:32 am

Buub wrote:
My recommendation is to learn Java, C++, then C.


I guess that makes sense from a certain perspective.

But it's hard for me to imagine what it would have been like to learn Java first, before learning C. Perhaps that's because I learned on my own, not in school. I was more interested in writing my own little programs than in abstract concepts or the "big picture." Maybe that was short-sighted, I dunno, but I did learn those abstract concepts eventually, and I don't think learning C first hurt me any.

In any case, we don't use either C or C++ at work. We use Visual Basic (don't laugh) but I certainly wouldn't recommend that to someone who was new to programming, it's likely to give you a whole slew of bad habits.

(And I never was a big fan of Java anyway. Always seemed clunky and goofy to me. Trying to write a simple client/server app proved to be quite frustrating. So I wrote it in C, and haven't really used Java since. But perhaps I was too hasty.)
 
Flying Fox
Gerbil God
Posts: 25690
Joined: Mon May 24, 2004 2:19 am
Contact:

Sun Apr 03, 2005 1:30 am

My next problem is choosing a good introductory text.

I recommend C++ Primer. Stroustrup's own book didn't really do it for me, and a couple of my friends shared my views as well.

As for the order for C#/Java, C++ and C, it really does depend on what project you are doing first. Doing a real project is what really motivates to learn the language. And going one way or the other will have their pros and cons. As others have said, if you go from C -> C++ -> C#/Java then you may think in "lower level" terms after you have moved on. I have seen ugly heavily function/procedural influenced code written in the guise of OO. For the other direction, I have seen those "high level" programmers come back to do "low level" programming and make a mess of things (omg where is your delete? what? you mean you didn't put one in!? :o)

You just have to get into the correct mindset when you are in the languages.
 
Illissius
Graphmaster Gerbil
Posts: 1116
Joined: Thu Oct 23, 2003 5:25 am
Location: Hungary
Contact:

Sun Apr 03, 2005 4:03 am

Flying Fox wrote:
My next problem is choosing a good introductory text.

I recommend C++ Primer. Stroustrup's own book didn't really do it for me, and a couple of my friends shared my views as well.

Heh. I managed to get about halfway through it before giving up. ;)

As for the order for C#/Java, C++ and C, it really does depend on what project you are doing first. Doing a real project is what really motivates to learn the language.

Concur. Decide what you want to work on first, and more often than not your project of choice will already have a 'preferred' language, making the choice easy. If you want to do GUI stuff I'd recommend looking into Qt/KDE which has a very nice API. Even has Ruby bindings (which I'm wanting to learn, looks pretty awesome), only problem is all the API docs are for C++ which can be a bit disconcerting (especially if you try to learn it before C++, which I tried to do at first)...
Work is punishment for failing to procrastinate effectively.
last.fm profile
 
Ma10n3!
Graphmaster Gerbil
Posts: 1233
Joined: Mon Feb 07, 2005 6:07 am
Location: US Territory

C/C++: Best performing cross-platform capable language.

Sun Apr 03, 2005 4:57 am

If you are doing something that will actually do some number-crunching, or you're a staunch supporter of performance, no matter the task (or difficulty), use C or C++. Only assembly for the given CPU is faster.

BTW, anyone here used C/C++ for CGI scripting/programming? I've got a few ideas, but I'm a n00b at this stuff myself.
Napoleon Bonaparte: 1812--Height of power; Adolf Hitler: 1912--Beginning; Black Horseman: 2012--?; Yellow/Gray?
 
Yahoolian
Grand Gerbil Poohbah
Posts: 3577
Joined: Sun Feb 16, 2003 3:43 pm
Location: MD
Contact:

Sun Apr 03, 2005 9:29 am

Ma10n3! - Premature optimization is counter productive.

It would be a big pain to use C/C++ for CGI scripting/programming. Use PHP, Ruby, Perl, Python, or some other language more suited for it. Probably PHP would be the best for you, because it's fairly close to C++.
 
Flying Fox
Gerbil God
Posts: 25690
Joined: Mon May 24, 2004 2:19 am
Contact:

Sun Apr 03, 2005 9:51 am

Illissius wrote:
Flying Fox wrote:
I recommend C++ Primer. Stroustrup's own book didn't really do it for me, and a couple of my friends shared my views as well.

Heh. I managed to get about halfway through it before giving up. ;)
Did you mean C++ Primer or The C++ Programming Language? :roll:

If you want to do GUI stuff I'd recommend looking into Qt/KDE which has a very nice API. Even has Ruby bindings (which I'm wanting to learn, looks pretty awesome), only problem is all the API docs are for C++ which can be a bit disconcerting (especially if you try to learn it before C++, which I tried to do at first)...
wxWindows is purportedly to be another popular framework, cross-platform too.

It would be a big pain to use C/C++ for CGI scripting/programming. Use PHP, Ruby, Perl, Python, or some other language more suited for it. Probably PHP would be the best for you, because it's fairly close to C++.
There is actually people still using C/C++ for CGI scripting/programming? ouch... :o

If you look around even the highly trafficked sites like Amazon or eBay are not using CGIs anymore. In a modern day architecture you will probably use PHP/Perl/Python/JSP/ASP/ASP.NET for your web frontend, and if you do need some performance heavy stuff you move that code to your 2nd tier instead of the presentation (browser) layer. And for that you can use whatever you want, even ASM. :)
 
Illissius
Graphmaster Gerbil
Posts: 1116
Joined: Thu Oct 23, 2003 5:25 am
Location: Hungary
Contact:

Sun Apr 03, 2005 2:46 pm

Flying Fox wrote:
Illissius wrote:
Flying Fox wrote:
I recommend C++ Primer. Stroustrup's own book didn't really do it for me, and a couple of my friends shared my views as well.

Heh. I managed to get about halfway through it before giving up. ;)
Did you mean C++ Primer or The C++ Programming Language? :roll:

The latter.
Work is punishment for failing to procrastinate effectively.

last.fm profile
 
just brew it!
Administrator
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Sun Apr 03, 2005 8:32 pm

Another recommendation for Lippman's C++ book. Although Stroustrup invented the language, he isn't very good at explaining it IMO.

My recommendation would be to learn some scripting languages (Perl, Python, PHP) for doing stuff where a scripting language is appropriate; and learn C++ for those cases where you need "heavy lifting" (e.g. situations where you need more performance than you can get from a scripted language). C++/Java and the various scripting languages really are complementary.

I'll be the first to admit that I sometimes use C++ in situations where a scripting language would be more appropriate, simply because I'm most comfortable/fluent with C++. For many tasks, it is quicker for me to just bang it out in C++, rather than do the legwork to figure out how to do it in a script language like Perl... even though the script-based program would be shorter. I really need to get off my butt and learn Perl/Python/etc... I'm sure that once I'm reasonably fluent in them, I'll use them a lot more.
Nostalgia isn't what it used to be.
 
Flying Fox
Gerbil God
Posts: 25690
Joined: Mon May 24, 2004 2:19 am
Contact:

Mon Apr 04, 2005 12:45 am

just brew it! wrote:
Another recommendation for Lippman's C++ book. Although Stroustrup invented the language, he isn't very good at explaining it IMO.
Interesting, somehow fanboyism comes to play and most comments I heard from my circles wanted to put Stroustrup's book on top, but the ones that actually read the book confirmed my views. :roll:

just brew it! wrote:
I'll be the first to admit that I sometimes use C++ in situations where a scripting language would be more appropriate, simply because I'm most comfortable/fluent with C++. For many tasks, it is quicker for me to just bang it out in C++, rather than do the legwork to figure out how to do it in a script language like Perl... even though the script-based program would be shorter. I really need to get off my butt and learn Perl/Python/etc... I'm sure that once I'm reasonably fluent in them, I'll use them a lot more.
Tell me about it, LAMP has been my self-study goal for at least a year and a half. OTOH, I have been doing quite a bit VBScript (god forbids! :o) over the last little while too. Just calling the FileSystemObject stuff beats C++ file management any day, in terms of ease of use and lines of code needed.
 
just brew it!
Administrator
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Mon Apr 04, 2005 1:20 am

Flying Fox wrote:
Interesting, somehow fanboyism comes to play and most comments I heard from my circles wanted to put Stroustrup's book on top, but the ones that actually read the book confirmed my views. :roll:

I think there are a couple of issues at work here.

First, a general observation. For technical subjects, I think it is often better to not learn the topic from the original inventor. They've lived and breathed the subject matter for years, and are prone to making unwarranted implicit assumptions about what you already know, since it's all second nature to them. Furthermore, being a technical genius doesn't necessarily mean you're good at communicating your ideas. Someone who has had to go through the process of learning the subject matter from scratch themselves -- and with good communication skills -- makes a better teacher, since they've had to struggle up the same learning curve you're trying to climb.

Secondly, Stroustrup strikes me as a bit of an academic. He's an "old school" Bell Labs guy, from their heyday as a research institution. As a result, I think he suffers somewhat from "ivory tower syndrome".

Stroustrup's books are great if your goal is to write your own C++ compiler. But if you just want to use the language to get some real work done, there are better ways to learn it. :wink:

Tell me about it, LAMP has been my self-study goal for at least a year and a half. OTOH, I have been doing quite a bit VBScript (god forbids! :o) over the last little while too. Just calling the FileSystemObject stuff beats C++ file management any day, in terms of ease of use and lines of code needed.

There are so many things I want to learn. In addition to the various scripting languages, I'd like to pick up some Gnome/KDE GUI development skills, improve my understanding of HTML and CSS, learn MySQL (and possibly Postgress as well), and maybe even dabble with setting up a wiki site (the software used to run wikipedia.org is freely available). And if the job lead I'm currently working on pans out, I will also need to get up to speed on OpenGL in a real hurry... which will push all of that other stuff back.

You gotta keep up. Current (and broad) skills are the only real job security these days. A broad skillset means you can always find something else to do if the industry you're working in implodes, or your job gets outsourced to India...
Nostalgia isn't what it used to be.
 
Craig P.
Gerbil Team Leader
Posts: 285
Joined: Tue Dec 31, 2002 3:12 am
Location: South Bend, IN

Re: C/C++: Best performing cross-platform capable language.

Mon Apr 04, 2005 2:58 am

Ma10n3! wrote:
If you are doing something that will actually do some number-crunching, or you're a staunch supporter of performance, no matter the task (or difficulty), use C or C++. Only assembly for the given CPU is faster.


Um, I would say that if it's raw performance, you should prefer raw assembly, Fortran, then C or C++, in that order. (And I'm not sure which of C or C++ is better -- I recall reading about some template magic being used to great effect in speeding up C++ for numerics, but I also recall that C may have picked up a no-aliasing directive that would help too.)
 
Craig P.
Gerbil Team Leader
Posts: 285
Joined: Tue Dec 31, 2002 3:12 am
Location: South Bend, IN

Mon Apr 04, 2005 3:05 am

As far as C vs. C++ -- despite its heritage as a child of C, I think modern C++ has moved well beyond it; someone who knew just C would probably be lost reading any of the more interesting stuff I wrote. Now some of that is objects, but most of that is templates. Along those lines, while I'm not sure C++ is a good introductory language, I'm also not sure it's a good idea to start with another one if that's where you're ultimately going; approaching C++ from a Java background will mean you bring in baggage, same as if you approach from a C background, it's just different baggage.

Personally, I use classes and objects, sometimes more than others depending on whether I'm doing something that's strongly procedural or not, but I find templates to be a far more interesting feature than object orientation.
 
Ma10n3!
Graphmaster Gerbil
Posts: 1233
Joined: Mon Feb 07, 2005 6:07 am
Location: US Territory

Mon Apr 04, 2005 6:14 am

Flying Fox wrote:
In a modern day architecture you will probably use PHP/Perl/Python/JSP/ASP/ASP.NET for your web frontend, and if you do need some performance heavy stuff you move that code to your 2nd tier instead of the presentation (browser) layer. And for that you can use whatever you want, even ASM. :)


That's actually what I meant; use C/C++ for the data manipulation, but use something else for the front-end. There's an article about this, along with using MySQL, in this month's Linux Journal.
Napoleon Bonaparte: 1812--Height of power; Adolf Hitler: 1912--Beginning; Black Horseman: 2012--?; Yellow/Gray?
 
Veritas
Gerbil First Class
Posts: 113
Joined: Wed Dec 26, 2001 7:00 pm
Location: Houston, TX
Contact:

Mon Apr 04, 2005 8:42 am

I wonder if C is still a useful language or only good for maintaining legacy code? Is it necessary to learn C before C++ or should I just learn the newer C++.


To answer your questions directly rather than hashing out arguments about whether you should one or the other here are my comments.

C is still a useful language. I personally have not used it in a while. I know it is still expected to be known at universities like Princeton (where one of the creators of C <a href="http://www.cs.princeton.edu/courses/archive/spr05/cos333/">teaches</a>). It is still a great language for embedded software (i.e. microcontrollers, et al.)

C is not necessary to learn C++. I personally think it is quicker to write large programs using C++ (over C) because of things like the Standard Template Library. There is a good, free version of STL at <a href="http://www.boost.org">Boost.org</a>.

If I am looking to do something really quick, I just use <a href="http://www.python.org">Python</a>.

I have heard lots of good things about Ruby but I have not personally used it so I can't say much about it. Well, other than it seems smart people like Ruby which is always a good indication it is a good language.

<a href="http://www.paulgraham.com/pypar.html">This</a> is a small, but good essay on learning programming languages.

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On