Thread: C or C++ ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by yvan
    you need recursion for example to solve some problems algorithmically
    Just because an algorithm is implemented with recursion does not mean your language of choice needs to support recursion. You can use an explicit stack to simulate the effects of recursion. Additionally, in algorithms that use "tail recursion" (calling the recursive procedure at the end of the procedure code itself) it could/should be rewritten as a loop, because nothing can happen until you reach the base case, and the stack of function calls unwinds. The only reason you see tail recursion is because it is simple to write.
    Last edited by whiteflags; 03-10-2016 at 01:43 PM.

  2. #2
    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. #3
    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