Coffeehouse Thread

33 posts

A quick self-reminder why I did not pursue native development

Back to Forum: Coffeehouse
  • androidi

    With all the "reneissance" talk I wanted to see if I could do a hello world in C without consulting the web. This would mean reading arbitrary length line from console where the user might or might not input "hello world" and then outputting it and freeing the memory and there should be no feeling left after that something might still be buggy. And of course this should all happen in at most 5 lines since that's more than enough for this sort of task in my opinion. Well I gave up immediately because I'm not that glutton for punishment. Just like years ago (before C#) when I first tried it.

    In any case I then went to look what would it take, potentially*. There's a question on SO with bunch of initially wrong answers each with bunch of edits to make them more correct. While C++ and what not libraries may be huge improvement over C, how can you get past the risk analysis step of linking 3rd party native code with such huge possibility of bugs?

    Or was this all a lazy excuse to continue being able to only (barely if C++) read and not write native code? (yes) I need to justify continuing my dedication to C# and if a lazy excuse will do it over a tediously long wall of text one then I guess I'll use the time saved to implement some cool features in C#! Ok, you got me, this is all a bit desperate agony over this C++ reneissance and seeing only async in the list of cool things for C#. What's beyond Roslyn?

    If anyone is now wondering how to read a line in C, here it is. *Probability that the "correct answers" are finally correct is... left to the readers rigorous analysis and memorization of relevant specifications. http://stackoverflow.com/questions/314401/how-to-read-a-line-from-the-console-in-c

  • a235301

    C++ is a very different beast to C#, even if it bares some resemblance to it via syntax.  C++ is a very difficult language to master.  It's one thing to be able to read it, it's another to write it and write it effectively.  It is much, much easier to go from C++ to C# than it is the other way around.

    You need to ask yourself why you need to work in C++.  C++ as a development language is used for very specific reasons(performance is the chief one).  Use the right language for the job, don't try to shoehorn in one language or another simply because you know the language or you want to learn a different one.

    I would not say C++ is a encountering any sort of renaissance.  It's more that, despite the last decade or so of VB, C# and Java, where at many points in the past it's been popular to state "C++ is dead", C++ is very much alive and well.  There simply is no language out there that will replace C++ for certain applications or pieces of certain applications. Microsoft recognizes this fact and thus is smart in ensuring that C++ continues to be a first class citizen in the suite of Windows development tools.

    I will say that to know C++(eh, rather master it), in addition to C#, will open up many more opportunities for you in your career.  There is a much smaller pool of C++ experts out there.  And in the recent past C++ has been dropped as a requirement for graduation by many CS university programs, further constraining the supply of good C++ programmers. 

  • Cream​Filling512

    Also C++11 is yet another beast.  I'm pretty good with C++, although a bit rusty, but C++11 brings new keywords, syntax, operators, features and it's like a whole new language.

  • figuerres

    It's Funny to me ...   way back when I learned C and Assembler and Basic and Pascal and COBOL

    then Perl and other stuff  

    I saw the early C++ and i *NEVER* cared for it.

    I loved C

    later I saw C# and it was like "Wow this rocks!"

    to this day I have the same feel, C is good and C# is good but to me C++ is a mess.

  • Frank Hileman

    You only have to look at the size of Stroustrup's "C++ Programming Language" to realize how complex it is.

    The biggest turn-off for me is debugging heap or stack corruption.

  • W3bbo

    ,Frank Hileman wrote

    You only have to look at the size of Stroustrup's "C++ Programming Language" to realize how complex it is.

    The biggest turn-off for me is debugging heap or stack corruption.

    So long as you don't do anything silly with pointers, you should be okay...right? Big Smile

    My biggest problem with C++ is the libraries. Any language, no matter how backward or difficult can be made all the better with decent libraries. Qt is great if you want to use C++ as though it were C#, but that's a whole other thousand-page book to memorise before you become any good at it.

    I'm getting conflicting information about the nature of WinRT on non-metro applications. Can C++ applications consume WinRT for traditional desktop, console, and service/daemon applications or not?

  • Frank Hileman

    @W3bbo:

    ,W3bbo wrote

    *snip*

    So long as you don't do anything silly with pointers, you should be okay...right?Big Smile

    My biggest problem with C++ is the libraries. Any language, no matter how backward or difficult can be made all the better with decent libraries. Qt is great if you want to use C++ as though it were C#, but that's a whole other thousand-page book to memorise before you become any good at it.

    Sometimes I have to help clients debug memory corruption created in their code, but occurring in our data structures. You can't force a client to use discipline. I see all kinds of code...

    Non-.net developers seem to think .net libraries are pretty hairy as well.

     

  • Sven Groot

    If anyone is now wondering how to read a line in C, here it is. *Probability that the "correct answers" are finally correct is... left to the readers rigorous analysis and memorization of relevant specifications.http://stackoverflow.com/questions/314401/how-to-read-a-line-from-the-console-in-c

    Yes, you're making it intentionally difficult by allowing any length string, which in C becomes complicated because there is no built-in support for an automatically growing string that you can use for input from stdin. Of course, there may be third party libraries that do allow this. If you add "it's okay to truncate any input longer than N characters", it becomes a lot easier.

    Fortunately, "native code" doesn't have to mean C. If you broaden your scope to C++ your goal becomes amazingly easy (because C++ does have such a string in its standard library, and the facilities to use it for input):

    #include <iostream>
    #include <string>

    int main()
    {
    std::string input;
    std::getline(std::cin, input);
    std::cout << input << std::endl;

    return 0;
    }

     

    (The code block on this bloody forum was stripping my newlines again)

    This takes, all told, three lines of real code. There's no bugs, no memory leaks, no fuss. Just clean, safe, simple code. It'd be exactly the same in C#.

    Go watch Herb Sutter's talk from Build. There wasn't anything in there that I wasn't already doing, but if you're not that familiar with C++, haven't used it recently, or are stuck in the "C with classes" style of using it, it should be very enlightening.

  • Sven Groot

    ,Cream​Filling512 wrote

    Also C++11 is yet another beast.  I'm pretty good with C++, although a bit rusty, but C++11 brings new keywords, syntax, operators, features and it's like a whole new language.

    Too bad we're getting almost no new C++11 language features with VC11. VC10 already had auto and lambdas, but all that VC11 adds is scoped enums. No variadic templates, no ranged for-loop, no constexpr, no uniform initialization or initializer lists... it's amajor disappointment.

    (Note that I said language features; we are getting pretty much all of the C++11 std library, including <thread> and <atomic>, which is good).

  • JoshRoss

    ,Sven Groot wrote

    *snip*

    Too bad we're getting almost no new C++11 language features with VC11. VC10 already had auto and lambdas, but all that VC11 adds is scoped enums. No variadic templates, no ranged for-loop, no constexpr, no uniform initialization or initializer lists... it's amajor disappointment.

    (Note that I said language features; we are getting pretty much all of the C++11 std library, including <thread> and <atomic>, which is good).

    I remember hearing from one of STL's videos that the next version of VS would have veridic templates. Are you sure it's not just arriving in a later build? 

    -Josh

  • Sven Groot

    ,JoshRoss wrote

    *snip*

    I remember hearing from one of STL's videos that the next version of VS would have veridic templates. Are you sure it's not just arriving in a later build? 

    -Josh

    In Herb Sutter's video that I linked to he said they were working on it, but it turned out to be far more difficult than they expected, so they can't deliver it in time for VC11 (even the final). So because they spent their time on this one feature that won't be shipped, we're barely getting anything.

    He did imply that we wouldn't have to wait 2 years for the next VC version to get some of these new compiler features (maybe in a service pack or feature pack?), so here's hoping. Smiley

  • felix9

    variadic template for visual c++ is the 'Duke Nukem Forever' of Microsoft, the ultimate 'vaporware' Devil

  • AndyC

    ,W3bbo wrote

    *snip*

    I'm getting conflicting information about the nature of WinRT on non-metro applications. Can C++ applications consume WinRT for traditional desktop, console, and service/daemon applications or not?

    No they can't.

  • cheong

    I can read C++, port C++ code to other languages, and even assist in debugging C++ code, but never write anything in C++ beyond the level of elementary C++ class homework.

    So I won't pursue native development either. Tongue Out

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • felix9

    ,AndyC wrote

    *snip*

    No they can't.

    Yes they can.

    8:30 ~ 11:00 http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-876T

    and people has done that. http://ermau.com/using-winrt-from-net/

  • AndyC

    Interesting, I'm sure the opposite was said during the keynotes, but I'll take that as a more authorative resource. Still the majority of the really neat stuff like charms and contracts will presumably require appcontainers so I'm not sure there will be quite the same benefit (although .NET developers will probably be glad not to have to PInvoke quite as much).

  • Richard.Hein

    @androidi:  With all the talk of the C++ renaissance, why are you writing it in C?  Perplexed  Did you think it should make C programming easier as well?

  • spivonious

    @androidi: using win32 console app project in VS2010:

     

    #include "stdafx.h"
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {    
        string entry = "";
        cout << "Please enter your name.";
        cin >> entry;
        cout << "Hello, " << entry;
        return 0;
    }

    I haven't coded in C++ for probably 6-7 years. Not too different from the C#:

    using System;
    
    namespace TestingCSharp
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Write("Please enter your name:");
                string name = Console.ReadLine();
                Console.WriteLine("Hello, " + name);
            }
        }
    }

     

    edit - oh wait, you wanted C and not C++? For a quick and dirty app, just use printf() and scanf().

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.