Rationale for C first: please critique

This is a discussion on Rationale for C first: please critique within the C Programming forums, part of the General Programming Boards category; Virgin post: greetings! Like many, I've taken it upon myself to learn programming. I learned Fortran 77 and Basic on ...

  1. #1
    Registered User LowWaterMark's Avatar
    Join Date
    Aug 2008
    Posts
    12

    Rationale for C first: please critique

    Virgin post: greetings! Like many, I've taken it upon myself to learn programming. I learned Fortran 77 and Basic on a TRS 80 back when Jefferson and Adams were ratifying the Declaration of Independence.

    Now it's a new day and I've chosen to learn C despite my true desire to become fluent in C++. My rationale is that I want to learn a lower level language first so as to better understand things from the machine's perspective. My compound question is this: does that make sense and does it outweigh the risk of picking up bad programming habits, e.g. not learning the proper use of object-oriented programming right from the start?

    I began pondering my wisdom after reading "Does managed code make people stupid" over on the Community Board.
    Last edited by LowWaterMark; 08-10-2008 at 03:25 AM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,259
    If you intend to learn C++, then learn C++. There is no need to learn C beforehand. Similarly, if you intend to learn C, there is no need to learn C++ beforehand. There a possible exception if you need to write C++ libraries code interfaces to lower level code (eg device drivers, wrapping C libraries, etc), in which case you need to know both .... see next para.

    If you anticipate a need to know both languages (eg a job that involves maintaining old C and C++ code) then you will need to know the differences between them, and techniques in both languages. In this case, the choice of what to learn first depends on your learning style. If you have a theoretical or conceptual learning style (ie you prefer to learn concepts and techniques before putting into practice), you will be better off learning C++ first (and you will groan when it comes to learning C, as it will seem so dirty and low-down). If you have a hands learning style (ie you prefer to learn by doing things hands-on as a means of learning ideas) then you will be better off learning C first (and you will groan when you move to C++, as you will keep being tempted to do things hands-on, and using C++ well means sitting back and doing things conceptually first). Either way, if you need to learn both languages and understand where the differences between them are (often essential when maintaining code) the hardest thing will be the transition between them.

    Practical gotchas result from the fact that a lot of older C compilers (as per 1989 standard) are actually C++ compilers, meaning that the C you learn often includes some elements of C++. The (deliberate) backward compatibility of C++ to C also encourages a lot of people to write C code that uses a few C++ features and insist they are doing C++ (they are, but it's not a good way to use C++). A lot of basic guides for both languages also blur the distinctions between the two languages: precisely because the authors don't fully understand the differences either.
    Last edited by grumpy; 08-10-2008 at 04:17 AM.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Diffucult question. I started learning C a president or two after Jefferson/Adams, before C++ compilers were generally available, never mind common-place. I started working for a company that uses almost only C++ in their production code about a year ago.

    Understanding C is (as I mentioned in another post recently) part of C++ - although you can get away with not knowing ALL the common stuff in C when using C++, sooner or later you will probably find code that uses the fundamentals shared between C and C++.

    Learning object oriented programming is a different matter than learning C++, if that makes sense. Yes, C++ is a language that supports object oriented programming, but there's absolutely no guarantee just because it uses C++ syntax that a program written in C++ will be properly object oriented. And I wouldn't say that I'm particularly up to speed with object oriented design even after a year of working mostly in C++.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    The thing with C++ is that it's still a low level language in the roots. Most higher level elements are just written C++ code in a lower level.
    So if you learn C++, you will STILL learn all the low level stuff and how things work, so you're not better of learning C first.
    I echo what others say. Stick to the language YOU want to learn most, because otherwise you're going to pick up bad habits or just groan on the annoying bits of pieces in the language you don't like, instead of hurraing it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    I have to agree with the others on this one - learn the language you want to use. Usually I would recommend learning C as it is very useful for branching out into other programming languages, but if the goal is to code in C++, then learning C first can involve more work as you must become aware of the differences in the languages as well. A good example of this is the malloc() function in C to dynamically allocate memory. Malloc() returns a void pointer and in C it is perfectly valid to assign that pointer to any other type of pointer, however C++ is strongly typed and does not allow this operation without a cast being made, which is a bad idea. If you want to code in C++, you would use the keyword new to allocate memory instead. Since C++ is almost a superset of C, it often allows more than one way to accomplish tasks, but one way is usually better than the other - in this example the C++ way is better due to a feature called exception handling which can be used easily with the new keyword.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  6. #6
    Registered User LowWaterMark's Avatar
    Join Date
    Aug 2008
    Posts
    12
    People, thank you for your time and seemingly clear consensus. Bummer as I'm closing in on the final chapter of "Absolute Beginner's Guide to C" by Greg Perry. Oh well, it's not like I've been writing programs in C for NASA for the past twelve years.

    There is no question that I learn best within a conceptual framework as grumpy was discussing. If I have a grasp of the theoretical foundation of whatever, the details tend to come easily. Concepts, theory, imagery, allegory and metaphor are for me the raw materials of getting a handle on something new. Looks like I'm off to the sticky on C++ Book Recommendations to find my formulary for learning C++.

  7. #7
    Registered User LowWaterMark's Avatar
    Join Date
    Aug 2008
    Posts
    12
    BTW, I'm trying to dovetail the recommendations from ACCU Book Reviews C++ with those from the C++ Book Recommendations sticky here on this board. Sound reasonable? That is, are ACCU reviews considered credible by this community?

    ********2hrs later*********

    Well that didn't work, especially after factoring the variables conceptual, philosophical, theoretical or whatever. I added 5-star recommendations on C++ Programming from Amazon and came up with the big null-set. So please don't flame me or hit me because I have to ask: has anyone read a really great text on introductory C++ programming that approaches its task from a highly theoretical perspective?

    I know I'm pretty much in the wrong forum. I'm just an all-around bad person. Think of it as a metaphor for my being lost in general. Have mercy.
    Last edited by LowWaterMark; 08-10-2008 at 11:21 AM. Reason: time lapse

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List question from a newb(Need code Critique)
    By Gatt9 in forum C++ Programming
    Replies: 2
    Last Post: 01-08-2006, 02:11 AM
  2. Critique my StringTokenizer please...
    By maxhavoc in forum C++ Programming
    Replies: 10
    Last Post: 11-24-2004, 08:08 PM
  3. Critique my program
    By Jason Spaceman in forum C Programming
    Replies: 6
    Last Post: 10-26-2004, 05:38 PM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM
  5. critique me please
    By ober in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 10-02-2002, 01:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21