Viewing 40 posts - 81 through 120 (of 160 total)
  • What is it about C++?
  • GrahamS
    Full Member

    Pfffft… all you really need is ed 😉

    Also xkcd

    mrmonkfinger
    Free Member

    seems to use the form i++ instead of ++i even

    better than “i = i++”

    which I have seen used in anger, once.

    chambord
    Free Member

    better than “i = i++”

    Isn’t that undefined?

    aracer
    Free Member

    😀 Started off using emacs (actually umacs, but it’s close enough to count) and was once fluent in that – then I did a lot of work on minimalist systems where that wasn’t installed, so ended up having to learn how to use vi(m) which I loathe, but will defend to the death to anybody who dares criticise it. Though I’ve not recently come across a system which doesn’t include nano – the main advantage of which is it’s better than vi 😉

    aracer
    Free Member

    I’m fairly sure it results in i++ as that’s a postincrement operator so the assignation should happen first. I’m not sure I’d want to rely on it though. Let’s test…

    Edit: Yep – using gcc in the latest raspbian it works as I suggest.

    chambord
    Free Member

    Well the result will depend on your compiler.

    GrahamS
    Full Member

    I’ve not recently come across a system which doesn’t include nano

    You need to work on embedded systems more 😀
    I’ve had the pleasure of creating (small) text files using cat or echo because that was all we had room for on the install.

    Yes please Mike

    And by “Mike” I mean “aracer”

    #readingfail

    toby1
    Full Member

    And there we were thinking all this forum was middle management in IT, but this suggests we still have some technical people around!

    aracer
    Free Member

    I think it’s that the ones I’ve worked on are either at a similar level to RPi where you have stuff like that, or far smaller and not running on OS at all.

    Oh, and the code also works as I suggested in VS2008 which is the other platform I have immediate access to, so I’ve covered the two most widely used C(++) compilers. Don’t think I CBA to start a VM to prove it also works in a different flavour of Linux.

    Edit: oh what the heck <fires up Atmel Studio>

    aracer
    Free Member

    Here you go, Graham:

    Ok, here is a snipet of code that is much cleaner with the GOTO than
    without (BTW it’s the only goto in several thousand lines of code
    belonging to the same project).

    // direct_declarator:
    // identifier
    // | '(' declarator ')'
    // | direct_declarator '[' constant_expression ']'
    // | direct_declarator '[' ']'
    // | direct_declarator '(' parameter_type_list ')'
    // | direct_declarator '(' identifier_list ')'
    // | direct_declarator '(' ')'
    // ;

    p1 = parse_identifier();

    if (p1 == NULL)
    {
    p1 = parse_lparen();

    if (p1 != NULL)
    {
    ITEM *p2;

    p2 = parse_declarator();

    if (p2 != NULL)
    {
    ITEM *p3;

    p3 = parse_rparen();

    if (p3 != NULL)
    { p1 = p2;
    goto lab1;
    }

    push_item(p2);

    p2 = NULL;
    }

    push_item(p1);

    p1 = NULL;
    }
    }

    lab1:

    TurnerGuy
    Free Member

    yes but that is goto in effectively C, not C++, where its use is even more unwise.

    I arranged a code review of some guys code once as it was leaking resources all over the place because it was using a goto to handle errors, then I found the MSDN code examples it was modelled on and they had the same leaks in.

    IA
    Full Member

    So, as there’s a bunch of C++ aficionados in one place here, any recommendations for an IDE to deal with a series of gnarly unix/linux C++ projects that’s better than the CDT in Eclipse?

    The only thing drowning out the wails of despair fading into tears when the indexer decides to run is the sound of my laptop’s fans…

    chambord
    Free Member

    Every time I google this I read that QtCreator is your best bet in Linux (It does normal c++ as well as Qtey stuff).

    Otherwise people recommend code::blocks

    nullpointer
    Free Member

    @IA: Qt Creator is very popular for std C++ as well as Qt projects.

    Edit: Snap chambord!

    epicyclo
    Full Member

    oldnpastit – Member
    It’s late. I’d like to be at home. But instead I’m reading through mountains of poorly written jumbled up and incomprehensible C++ (looking at you, Qt).

    What is it about this language that encourages people to write utterly opaque code?…

    Simple. Guarantees future employment, probably as an extortionately paid consultant to fix it about 3-4 years after your original employer sacked you for writing incomprehensible garbage.

    IA
    Full Member

    Cheers, will check out what Qt Creator is like these days then, not tried it for years.

    GrahamS
    Full Member

    Here you go, Graham

    Blimey! See that right there is a great example of code that is a tangled mess of logic paths, mostly by the way it is structured and by the use of goto.

    Okay give me a minute and I’ll see if I can make sense of it.

    GrahamS
    Full Member

    Yeesh that was horrible, okay aracer how is this:

    ITEM* p1 = parse_identifier();
     
    if (p1 == NULL)
    {
        ITEM* plparen = parse_lparen();
        
        if (plparen != NULL)
        {
            ITEM* pdecl = parse_declarator();
            
            if (pdecl != NULL)
            {
                if (parse_rparen() != NULL)
                {
                    p1 = pdecl;
                }
                else
                {
                    push_item(pdecl);
                    push_item(plparen);
                }
            }
            else
            {
                push_item(plparen);
            }
        }
    }
     
    // whatever the code at lab1 was going to do...

    (Note: in a real situation I’d refactor that completely and slap whoever wrote the original)

    mogrim
    Full Member

    if (p1 == NULL)

    Why the == NULL?

    if (!p1)

    TurnerGuy
    Free Member

    and too many braces…

    GrahamS
    Full Member

    Why the == NULL?

    I just kept it the same as the original for clarity.

    Also some strict standards forbid logical operations on anything other than booleans.

    and too many braces…

    Again some strict standards (rightly IMO) forbid the use of single line expression blocks – we always put braces for every block.

    Avoids nasty stuff like this:

    if(a)
      if(b) x=y;
    else x=z;

    nwallace
    Free Member

    the problem is rarley the langauge and much more likely the eejit that wrote it in the first place, often trying to be too clever… I’ve even seen someone rewrite the .net framework because they could…

    molgrips
    Free Member

    C++ is the programming equivalent of lots of rope. You may hang yourself with it if you want, or just get it all horribly tangled up.

    Java is an attempt to prevent you from doing this. It’s a lot nicer imo.

    GrahamS
    Full Member

    C++ is the programming equivalent of lots of rope. You may hang yourself with it if you want, or just get it all horribly tangled up.

    C gives you enough rope to hang yourself.

    C++ gives you enough rope to shoot yourself in the foot.

    TurnerGuy
    Free Member

    Java is an attempt to prevent you from doing this. It’s a lot nicer imo.

    it is like C++ with stabilizers you mean.

    It is worth learning to program idiomatic Java as it can improve your C++ style, but there are lots of design/programming paradigms you can do in C++ which you can’t do in Java or C#, mostly to do with generics.

    llama
    Full Member

    there are lots of design/programming paradigms you can do in C++ which you can’t do in Java or C#

    Such as?

    I’d say rather that the reverse is true

    molgrips
    Free Member

    Yes, but do you really need to do those things?

    Never come across a situation in Java where I couldn’t do something.

    rusty90
    Free Member

    Never come across a situation in Java where I couldn’t do something.

    Written many device drivers in Java? 🙂
    We have a desktop app that does some very low level stuff, to the degree that it includes inline assembler and direct kernel calls. C++ is still the tool of choice for such stuff.

    beej
    Full Member

    I once wrote a date conversion routine that ended up stopping all new connections to a UK mobile network for the month of December.

    Converting from 01, 02, 03… to JAN, FEB, MAR.

    In Fortran (comments indicated by a “!”), something along the lines of

    If 01 then month=JAN
    ELSEIF 02 then month=FEB
    ..
    ..
    ELSEIF 12 then month=DEC
    ELSE
    ! Something bad as the month isn’t 01-12, bomb out
    Throw fatal error

    All well and good(ish), however… I’d left a “!” in front of the final ELSE, turning it into a comment.

    I was late into the office 1st Dec, to be greeted by sniggers and “uh-oh, you’re in trouble” head shaking. We fixed it by about 11am. My one saving grace was I had the signed-off code review proving my mate had missed the extra “!” as well.

    TurnerGuy
    Free Member

    I’d say rather that the reverse is true

    only if you look at reflection and the support that gives.

    But you can do loads more in terms of generic programming and template metaprogramming in C++ which you wouldn’t be able to do in Java, or C#.

    But they are not comparible languages – you wouldn’t even consider writing an operating system in Java, for example…

    GrahamS
    Full Member

    beej: An obvious question would be “Why did your unit tests miss that?” – but given you were writing in Fortran I suspect the answer is equally obvious 😀

    jonnouk
    Free Member

    if (p1 == NULL)

    Why the == NULL?

    if (!p1)

    The second form, while it most likely compiles the same, is an implicit conversion from pointer to bool which could cause readability issues without a consistent naming scheme. That’s 3 MISRA rule violations in that slight difference. (MISRA != fun).

    aracer
    Free Member

    Well done Graham. By that point in the thread I couldn’t be bothered to work out the control flow, so just put it in a function with a return in place of the goto 😉

    I thought it interesting the comments suggesting removing the NULL and a set of braces – doing that is exactly the sort of thing which gets C++ a bad name, and coding standards tend to require you to write it just as Graham has for very good reasons. Personally I would never test for a null variable by using it directly as a boolean in the way suggested in code I expected anybody else to ever have to maintain, and I’ve been so brainwashed that I always use full sets of braces even in my own scratch code (unless I’m deliberately trying to minimise, confuse or obfuscate).

    Alternatively if you’re clever and careful

    chvck
    Free Member

    and I’ve been so brainwashed that I always use full sets of braces even in my own scratch code (unless I’m deliberately trying to minimise, confuse or obfuscate).

    I know a guy who uses them in python, he comments them out along with semi-colons!

    aracer
    Free Member

    Ah yes – I’m sure I’ve seen commented out semi-colons in VB!

    lemonysam
    Free Member

    I know a guy who uses them in python, he comments them out along with semi-colons!

    I do that when I’m struggling to understand someone else’s code (only the brackets, not the semicolons, that’s weird) 😳

    GrahamS
    Full Member

    More accurately:

    rusty90
    Free Member

    Alternatively if you’re clever and careful …

    Unfortunately I tend to get to work with stuff like this 🙁

    beej
    Full Member

    @GrahamS – We tested in November. Never bothered changing the system date.

    I was a) not massively experienced and b) never planning to write code for a living.

    That was about 1994-95. Scarily, some of my code is still running.

    mikewsmith
    Free Member

    Ah crap I’m now reading the rest of this at the bar and trying not to laugh out loud

Viewing 40 posts - 81 through 120 (of 160 total)

The topic ‘What is it about C++?’ is closed to new replies.