Thread: What can I do in c++, that I can't do in c?

  1. #76
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287
    I'm studying pure theory at the moment. I'm currently covering the subjects of trees, and at the moment binary trees. As is, you can look at a computer architecture as being structured like a brain, which is referred to the Von - Neumann architecture, named after one of its creators. I have no plans to be a programmer at the moment, but I still want to study computer programming. I'm not going to study a specific language at the moment, which means I won't be doing very much coding, but I think that I'll get the most value from studying pure theory.

  2. #77
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Hmm..

    Question: What can you do in C++ that you can't do in C?

    Answer 1: Get 30 pages of gibberish template-related compiler errors. Yeah, for 1 line of code! Multiply this 30 by the number of lines of code that depend on the 1 line that's in error, and you end up with a big old mess.
    Answer 2: Get a way to do the same thing in 14 different ways that all do the same thing, but in 14^2 different ways. LOL. Look at "simple" parameter passing: pass by value, pass by pointer, by reference, by pointer to reference, reference to pointer, and now with C++11, some weird double reference thing associated with move semantics I guess.. in the end, none of this complexity needs to bubble up to the programmer. It's a thing called accidental complexity.

    Seriously, though...


    Quote Originally Posted by Terrance View Post
    I'm studying pure theory at the moment. I'm currently covering the subjects of trees, and at the moment binary trees. As is, you can look at a computer architecture as being structured like a brain, which is referred to the Von - Neumann architecture, named after one of its creators. I have no plans to be a programmer at the moment, but I still want to study computer programming. I'm not going to study a specific language at the moment, which means I won't be doing very much coding, but I think that I'll get the most value from studying pure theory.
    Modern computer architecture is indeed modeled after the Von Neumann architecture. However, more generally, they are a hardware implementation of what's called a Turing machine. In essence, Turing discovered his machine could compute the result of all "computable" problems. An alternative line of theory is the lambda calculus, which was found to be equivalent to Turing's model of computation, but free of side-effects. Certainly this is an interesting (if abstract) study, but IMO is not a topic generally for discussion on this forum, which is more in line with practical programming. Which brings me to my point. Studying the background of theoretical computation is interesting, but IMO will do little do increase your practical programming skills. You need to decide which is of more value to you: talking theory with mathematicians, or with real-world programmers?

    Also, to answer the question posed in your topic question: C and C++, and all other so-called Turing complete languages, are equivalent in the sense that they can compute answers to all "computable" problems. However, beware the Turing tarpit.
    Last edited by MacNilly; 12-02-2016 at 03:40 AM.

  3. #78
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    With regards to accidental complexity, I think rvalue references and move semantics are definitely a good example of that.
    Code:
    auto fn(vector<int>&& vec)
    {
      // vec still needs to be moved!
      // it's an lvalue of an rvalue reference
      // std::move is the static_cast required to give you the rvalue you so desire, or so I understand
    }
    
    template <typename T>
    auto fn2(T&& t)
    {
      // now t is a universal reference and instead needs be 
      // std::forward'ed to be used properly. 
      // this actually triggers reference collapsing
    }

  4. #79
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by MacNilly View Post
    Hmm..

    Question: What can you do in C++ that you can't do in C?

    Answer 1: Get 30 pages of gibberish template-related compiler errors. Yeah, for 1 line of code! Multiply this 30 by the number of lines of code that depend on the 1 line that's in error, and you end up with a big old mess.
    Answer 2: Get a way to do the same thing in 14 different ways that all do the same thing, but in 14^2 different ways. LOL. Look at "simple" parameter passing: pass by value, pass by pointer, by reference, by pointer to reference, reference to pointer, and now with C++11, some weird double reference thing associated with move semantics I guess.. in the end, none of this complexity needs to bubble up to the programmer. It's a thing called accidental complexity.
    It's fairly obvious that you don't like C++. Do you use it regularly? Based on your own posts, I get the impression that you really don't know C++ very well. Are you somehow forced to endure its idiosyncrasies and complexities, by some third party, such as an employer? If not, then just use something else. Something that makes more sense to you. You're not likely to get a lot of respect from users on the C++ forum, if your interactions here are to constantly malign C++, without offering any real advice or assistance. Many of us who use it extensively enjoy it, and appreciate its incredible flexibility, which, unfortunately, often comes at the expense of complexity. Yes, there are things about it that we don't like, and things we'd like to see changed, but there is a process for that, and it's called the ISO Standards Committee. The members are not gods. They do speak to mere mortals like us, and most of them are happy to answer questions and explain their rationale for doing things a certain way. In fact, they heard the pleas for better error messages, when using templated code, and have responded with language in the newer revisions of the standard, that is designed to improve the usefulness of diagnostic messages, and it has improved the state of affairs. It is an ongoing process. Change doesn't happen overnight, or all at once. All of the recently added features of C++ are beneficial in some way, and many of them can be adopted immediately, to effect instant improvement in your code. Move semantics have the potential to drastically improve performance. In cases where there are multiple ways to do the same thing, often, it's because different ways work better in different situations.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #80
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287
    Modern computer architecture is indeed modeled after the Von Neumann architecture. However, more generally, they are a hardware implementation of what's called a Turing machine. In essence, Turing discovered his machine could compute the result of all "computable" problems. An alternative line of theory is the lambda calculus, which was found to be equivalent to Turing's model of computation, but free of side-effects. Certainly this is an interesting (if abstract) study, but IMO is not a topic generally for discussion on this forum, which is more in line with practical programming. Which brings me to my point. Studying the background of theoretical computation is interesting, but IMO will do little do increase your practical programming skills. You need to decide which is of more value to you: talking theory with mathematicians, or with real-world programmers?

    Also, to answer the question posed in your topic question: C and C++, and all other so-called Turing complete languages, are equivalent in the sense that they can compute answers to all "computable" problems. However, beware the Turing tarpit.
    Yes, I find I get more value of studying the theory of computer programming rather than gaining practical programming experience. I have around 1000 hours of programming experience, though I've never been a professional programmer, unless you count some professional sql experience as being professional programming.

    The way I see it is, if I was a professional programmer, I would be writing/debugging, and applying general software engineering methods for approximately 2000 hours per year. So if as a professional programmer, I would be applying software engineering methods for 2000 hours per year, would it be worth my time to write code as a non-professional programmer, or should I instead study the theory, to enhance my ability to think about programming. From my knowledge, it is better for me to be studying theory, and understanding the underlying concepts of computer programming, rather than writing code.

    After studying The Art of Computer Programming for 50 hours or so, I've learned many things I never would have by writing code or studying Deitel and Deitel - like programming books. TAOCP is purely theoretical, and goes into the scientific methods of understanding computer programming. The book has taught me, so far, that computer programming is rooted in mathematics and science, and that the purpose of computer programming is to write instructions to a computer so it can process complex sets of algorithms and and perform calculations on information at a much faster rate than a person could, with nearly flawless execution, assuming the instructional code you write to a computer is correct. I wouldn't learn these concepts merely by writing code, so TAOCP is of much more value to me than studying software engineering concepts.
    Last edited by Terrance; 12-03-2016 at 11:12 AM.

  6. #81
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    You get the best value by working at problems, splitting them into successively smaller problems until they virtually solve themselves. Pick a language or two to get properly intimate with. You won't learn computer programming by studying theory. You are neglecting your practical development imho. The only way to learn computer programming is to actually write programs, make mistakes, and fix them. There is only so far basic theory can take you.

  7. #82
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    The way I see it is, if I was a professional programmer, I would be writing/debugging, and applying general software engineering methods for approximately 2000 hours per year.
    You are, to a degree. Unfortunately, I think the human aspect is more pervasive than anything else. Differing programming styles and philosophies can become problematic. It's an industry where people are "smart" so egos collide a lot of the time.

  8. #83
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287
    Quote Originally Posted by Hobbit View Post
    You get the best value by working at problems, splitting them into successively smaller problems until they virtually solve themselves. Pick a language or two to get properly intimate with. You won't learn computer programming by studying theory. You are neglecting your practical development imho. The only way to learn computer programming is to actually write programs, make mistakes, and fix them. There is only so far basic theory can take you.
    But when you learn the theory, it allows you to understand and think through all of the problems correctly. It is kind of a reward vs value trade off. If you study the theory, then your value increases, but your ability to produce doesn't. By simply writing code, there will always be better programmers than me, but by studying the theory, I gain an advantage over others.

  9. #84
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    I strongly disagree. Others will learn the theory as they go and be able to put that theory into practical applications in industry whereas you won't be able to. Sure you'll know the theory but you won't have enough practical experience with computer programming languages to put it into effect. I can tell you over a thirty year career I've never had to reach for Knuth even though I do own TAOCP.

    Why not combine both theory and practice. Write an emulator for the hypothetical MIX computer that Knuth uses to illustrate algorithms.

    There is no substitute for practice. Read all the books in the library on programming and you'll still be a worse programmer than someone who has coded, failed and fixed his code over the same time period.

  10. #85
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    True, I'd recommend picking a project and sticking with it. That'll teach you what you need to know as you need to know it which is probably one of the most valuable industry skills you can have.

  11. #86
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287
    Quote Originally Posted by Hobbit View Post
    I strongly disagree. Others will learn the theory as they go and be able to put that theory into practical applications in industry whereas you won't be able to. Sure you'll know the theory but you won't have enough practical experience with computer programming languages to put it into effect. I can tell you over a thirty year career I've never had to reach for Knuth even though I do own TAOCP.

    Why not combine both theory and practice. Write an emulator for the hypothetical MIX computer that Knuth uses to illustrate algorithms.

    There is no substitute for practice. Read all the books in the library on programming and you'll still be a worse programmer than someone who has coded, failed and fixed his code over the same time period.
    I don't think that is true. After all, I did study computer science and computer information systems in college, and took most of the courses required for a computer science degree, although neither of my degrees are in computer science. On top of my studying computer science, I have an additional 1000 hours of pure coding experience, which is a lot considering I've never been a professional programmer. But studying the theory is best for me, and i still find it to have the most value, as programming itself is merely a skill, and something developed over time. But studying theory expands your ability to apply your skills properly.

  12. #87
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by Terrance View Post
    Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
    This is pointless. Go read your books. Come back and post some code.

  13. #88
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287
    Quote Originally Posted by algorism View Post
    This is pointless. Go read your books. Come back and post some code.
    Part of the point of studying pure theory, is that it becomes anti-coding. In other words, why code for 500 hours, when you can spend 500 hours studying theory? Most would prefer to code, and coding has more short term benefits. But studying the most difficult theory is what will really increase your value as a programmer over the long term.

    Of course, this is my input from a purely economics perspective.
    Last edited by Terrance; 12-04-2016 at 06:55 PM.

  14. #89
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    You're a madman, Terrance!

  15. #90
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    What algorism said

    Let's see something you wrote at the end of your 1000 hours.

    They say to get to the 'I wrote the book' level in just C++ takes 7-10 years of practical experience.

Popular pages Recent additions subscribe to a feed

Tags for this Thread