Thread: Why is C++ used more for software development that C?

  1. #16
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Mario F. View Post
    No hate. Instead, dislike of their language design. Much as I dislike macros (although here it's more to do with developers).
    Have you ever looked at a generics tree that tries to be something more than the most basic of structures? Those things are nearly indecipherable. It's syntactic gibberish with real meaning that will take an axe through your skull to finally understand.
    Would you mind posting some examples of templated code of such complexity?

    Edit: So, I've finally figured out how to write generic containers that support the STL's iterator interface. I'm totally kind of grooving on templates because this is the first time I've ever really been successful with them. Now that I've got a decent grip of templates and a better feel for thinking like a compiler, I feel unstoppable!

    There's no longer any code that I cannot eventually understand now! I can std::distance all the things!
    Last edited by MutantJohn; 05-25-2016 at 08:44 PM.

  2. #17
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Angola
    Posts
    8,445
    Quote Originally Posted by MutantJohn View Post
    Would you mind posting some examples of templated code of such complexity?
    Yes. I would mind. I have none with me and I don't want to go search for them. Neither I am willing to play catch with you.
    But you have a great source for that. Just read a book that teaches all about them. You can start with the classic Vandevoord & Josutis' C++ Templates.

    Quote Originally Posted by MutantJohn View Post
    There's no longer any code that I cannot eventually understand now! I can std::distance all the things!
    Give it three months without doing any template coding. Maybe 6 months since you are a young fella. Just do it. It's a good experiment.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #18
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Don't write any generic C++ for 6 months? That sounds kind of hard now that I'm all jazzed up but I suppose it might work. I'm almost done with my little toy containers and then I'll start back at a more domain-specific problem (that does not really require generics).
    Neither I am willing to play catch with you.
    I understand.

  4. #19
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by MutantJohn View Post
    Don't write any generic C++ for 6 months? That sounds kind of hard now that I'm all jazzed up but I suppose it might work. I'm almost done with my little toy containers and then I'll start back at a more domain-specific problem (that does not really require generics).
    Next time you think you should make a generic type, post details about it here. Someone will likely be able to show you why you don't need it to be generic.

  5. #20
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,656
    Quote Originally Posted by MutantJohn View Post
    There's no longer any code that I cannot eventually understand now!
    You will eventually understand this
    But I am hoping to waste a lot of your time.

    What is happening here is easy to see, but the way it is achieved is ridiculously complicated!
    If you have an explanation immediately, kudos wizard, you win!
    Code:
    #include <iostream>
    
    
    template< typename T, T v >
    struct Value {
      static constexpr T value = v;
    };
    
    
    template< typename , typename = void >
    struct Bar : Value<bool, false> {};
    
    
    template< typename ... > using Foo = void;
    
    
    template< typename T >
    struct Bar< T , 
      Foo < decltype(std::declval<T>().foo()) >> 
        : Value<bool, true> { 
    };
    
    
    template<bool B, typename T = void>
    struct Cond {};
     
    template<typename T>
    struct Cond<true, T> { typedef T TT; };
    
    
    template<typename Direction>
    struct CallFoo {
      template< typename U = int > 
      typename Cond< Bar<Direction>::value, U >::TT foo() {
        return Direction().foo();
      }
      template< typename U = int >
      typename Cond< !Bar<Direction>::value, U >::TT foo() {
          return 42;
      }
    };
    struct Minus42{
      int foo() {return -42;};
    };
    
    
    int main() {
      CallFoo<Minus42> left;
      CallFoo<Value<int, 42>> notLeft;
      std::cout << left.foo() + notLeft.foo();
      return 0;
    }

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Slippery_Seal View Post
    Hi everyone,
    I am new to programming and I have started to learn C and I love it!
    However the main question I have is why is C++ used more than C for software development (making applications).
    Sorry if this is a stupid question.
    Thanks
    To answer the original question, why you use a hammer and nails when you can use an entire toolbox? C++ offers many more tools to the programmers that make development easier, faster and less expensive than C. C is mostly for embedded programming because its biggest advantage over C++ is that it's so much less complex, making it cheaper and faster to build a compiler for the language. The size of the standard library also makes sense in the embedded world when storage is a luxury. Bigger standard libraries can often mean bigger executables.
    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.

  7. #22
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by manasij7479 View Post
    You will eventually understand this
    But I am hoping to waste a lot of your time.

    What is happening here is easy to see, but the way it is achieved is ridiculously complicated!
    If you have an explanation immediately, kudos wizard, you win!
    Code:
    #include <iostream>
    
    
    template< typename T, T v >
    struct Value {
      static constexpr T value = v;
    };
    
    
    template< typename , typename = void >
    struct Bar : Value<bool, false> {};
    
    
    template< typename ... > using Foo = void;
    
    
    template< typename T >
    struct Bar< T , 
      Foo < decltype(std::declval<T>().foo()) >> 
        : Value<bool, true> { 
    };
    
    
    template<bool B, typename T = void>
    struct Cond {};
     
    template<typename T>
    struct Cond<true, T> { typedef T TT; };
    
    
    template<typename Direction>
    struct CallFoo {
      template< typename U = int > 
      typename Cond< Bar<Direction>::value, U >::TT foo() {
        return Direction().foo();
      }
      template< typename U = int >
      typename Cond< !Bar<Direction>::value, U >::TT foo() {
          return 42;
      }
    };
    struct Minus42{
      int foo() {return -42;};
    };
    
    
    int main() {
      CallFoo<Minus42> left;
      CallFoo<Value<int, 42>> notLeft;
      std::cout << left.foo() + notLeft.foo();
      return 0;
    }
    Cancer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Software Development Book?
    By DecoratorFawn82 in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2013, 09:17 PM
  2. Own application development with a software
    By Buster in forum C# Programming
    Replies: 1
    Last Post: 06-25-2012, 07:15 AM
  3. Software Development ideas!!
    By gaurav_13191 in forum Tech Board
    Replies: 2
    Last Post: 01-29-2011, 11:19 AM

Tags for this Thread