Thread: C or C++ ?

  1. #16
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by yvan View Post
    how do you measure efficiency ? I'm not talking amount code but speed time those things.
    --linesOfCode = ++abstraction
    too much abstraction not good when you want to learn or when you make something sensitive / dangerous/very important !
    Abstraction always improves things.

    For instance, you have a dynamic array that you add things to and you need to deal with resizing it.

    Non-abstract route: everywhere in the code you need to add something to the array, you write a few lines that checks the current size and expands the array as necessary.

    Abstract route: You write a function called "AddThingToArray" and put the array expanding logic in one location.

    I'd never, ever allow the first option to ship out the door.

    What definition of "abstraction" are you using here?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  2. #17
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Elysia and Laser, you guys make some good points.

    But I still think there is value in using C. And that's because it's a good introduction as to how "computers actually work". One of the first examples in that link Laser posted to is a good example. A string is an array of characters and then the complexity explodes, even when just doing something simple like reading in a name.

    But that's the point! Or at least, it is in my mind. I think it's insane to do anything "real" in C and that's because I've used C long enough to know that trying to be "productive" in C is an arduous and very difficult task.

    I think I had point in there somewhere but to me it's like this, churn butter by hand once and not only will you know how butter is actually made, you will super duper appreciate all butter that you buy in stores from that point on.

    Though I should come in and say this, my university taught Java first then dove into C. I think that's a good order. Java's kind of high-level enough you learn stuff like loops and conditionals and stuff like that but I really enjoyed diving down to the "low level" that is C because it's basically, "Yeah, everything you use is an absolute nightmare underneath." But I was a physics major so I enjoy looking at things in detail.
    Last edited by MutantJohn; 03-10-2016 at 08:23 PM.

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by MutantJohn
    I think I had point in there somewhere but to me it's like this, churn butter by hand once and not only will you know how butter is actually made, you will super duper appreciate all butter that you buy in stores from that point on.

    Though I should come in and say this, my university taught Java first then dove into C. I think that's a good order. Java's kind of high-level enough you learn stuff like loops and conditionals and stuff like that but I really enjoyed diving down to the "low level" that is C because it's basically, "Yeah, everything you use is an absolute nightmare underneath."
    From the article:
    Quote Originally Posted by Bjarne Stroustrup
    At some point, the messier and lower-level features of C++ will have to be examined. One way of teaching/learning about pointers, casting, allocation, etc. is to examine the implementation of the classes used to learn the basics. For example, the implementation of string, vector, and list classes are excellent contexts for discussions of language facilities from the C subset of C++ that are best left out of the first part of a course.
    Using your analogy, an approach that starts with teaching pure beginners programming with standard C as the programming language is like mandating that anyone who wants to spread butter on bread to eat must first churn butter by hand themselves, even if butter can be bought from a store. Stroustrup's suggested approach is to let them eat and enjoy the butter first, learning how best to spread it on bread and how much to use it in baking and cooking, and then later teach them how to churn butter from milk.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed