Forum search & shortcuts

What is it about C+...
 

[Closed] What is it about C++?

Posts: 0
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.


 
Posted : 06/11/2014 3:13 pm
 IA
Posts: 563
Free 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...


 
Posted : 06/11/2014 3:18 pm
Posts: 1472
Full 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


 
Posted : 06/11/2014 3:30 pm
Posts: 0
Free Member
 

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

Edit: Snap chambord!


 
Posted : 06/11/2014 3:31 pm
Posts: 17396
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.


 
Posted : 06/11/2014 3:50 pm
 IA
Posts: 563
Free Member
 

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


 
Posted : 06/11/2014 3:53 pm
Posts: 31206
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.


 
Posted : 06/11/2014 3:58 pm
Posts: 31206
Full Member
 

Yeesh that was horrible, okay aracer how is this:

[code]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...[/code]

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


 
Posted : 06/11/2014 4:25 pm
Posts: 12089
Full Member
 

if (p1 == NULL)

Why the == NULL?

if (!p1)


 
Posted : 06/11/2014 4:37 pm
Posts: 0
Free Member
 

and too many braces...


 
Posted : 06/11/2014 4:42 pm
Posts: 31206
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:

[code]if(a)
  if(b) x=y;
else x=z;[/code]


 
Posted : 06/11/2014 4:44 pm
Posts: 0
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...


 
Posted : 06/11/2014 4:45 pm
Posts: 91169
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.


 
Posted : 06/11/2014 5:00 pm
Posts: 31206
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.


 
Posted : 06/11/2014 5:05 pm
Posts: 0
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.


 
Posted : 06/11/2014 5:09 pm
Posts: 3323
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


 
Posted : 06/11/2014 5:18 pm
Posts: 91169
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.


 
Posted : 06/11/2014 5:18 pm
Posts: 0
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.


 
Posted : 06/11/2014 5:34 pm
 beej
Posts: 4219
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 s****s 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.


 
Posted : 06/11/2014 5:39 pm
Posts: 0
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...


 
Posted : 06/11/2014 5:41 pm
Posts: 31206
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 😀


 
Posted : 06/11/2014 5:42 pm
Posts: 42
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).


 
Posted : 06/11/2014 5:47 pm
Posts: 0
Free Member
 

Well done Graham. By that point in [url= http://www.piclist.com/techref/postbot.asp?by=thread&id=%5BPIC%5D+List+of+C+Questions&w=body&tgt=post ]the thread[/url] 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).

[quote=molgrips ]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.

Alternatively if you're clever and careful
[img] [/img]


 
Posted : 06/11/2014 5:48 pm
Posts: 349
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!


 
Posted : 06/11/2014 5:50 pm
Posts: 0
Free Member
 

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


 
Posted : 06/11/2014 5:53 pm
Posts: 0
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) 😳


 
Posted : 06/11/2014 5:54 pm
Posts: 31206
Full Member
 

More accurately:

[img] [/img]


 
Posted : 06/11/2014 6:04 pm
Posts: 0
Free Member
 

Alternatively if you're clever and careful ...
Unfortunately I tend to get to work with stuff like this 🙁
[img] [/img]


 
Posted : 06/11/2014 6:05 pm
 beej
Posts: 4219
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.


 
Posted : 06/11/2014 6:14 pm
Posts: 52609
Free Member
 

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


 
Posted : 06/11/2014 6:21 pm
Posts: 1014
Full Member
 

stumbled across a bit of code (in the middle of a trivial function to do with multiple currency support) which I'd commented as "I don't know what this does but if I take it out nothing works".

Been there done that, got the t-shirt and trip to Cebit 🙂

It's been a while but I do recall that C++ macros by certain gents of eastern origin were quite mindbending, all this while dealing with big endian to little endian changes and simulators.

I recall guys in my project found something like this couple of months ago:
// there should be error handling logic around here
It was commercial US product which claims to be "developer-friendly solution" but failed at random times.


 
Posted : 06/11/2014 6:31 pm
Posts: 0
Free Member
 

That's 3 MISRA rule violations in that slight difference. (MISRA != fun).

A hardcopy of the MISRA C and C++ rules along with pc-lint turned up on my desk this week. My cup runneth over 🙂


 
Posted : 06/11/2014 7:09 pm
Posts: 31206
Full Member
 

The good news is Lint can enforce most of the MISRA rules for you.

People moan about it - but code the lints cleanly and is MISRA compliant is notably less buggy IME.


 
Posted : 06/11/2014 7:13 pm
Posts: 42
Free Member
 

People moan about it - but code the lints cleanly and is MISRA compliant is notably less buggy IME.

If you start a project with a good pc-lint setup I'd imagine it's fine. If you suddenly apply it to a massive codebase 18mths into development (my only experience of applying it) - Oh sweet baby Jesus.


 
Posted : 06/11/2014 8:40 pm
Posts: 0
Free Member
 

http://crashworks.org/if_programming_languages_were_vehicles/

As a designer, I tend to stick to scripting languages like Lua and C#. My efforts often make proper coders (such as my husband) weep, generally due to iffy indentation.

T'husband has to use C++, C# and Java in his day job, and soon he'll be adding objective C to the list. Poor bastard.


 
Posted : 06/11/2014 9:05 pm
Posts: 0
Free Member
 

<learns to code in Haskell>


 
Posted : 06/11/2014 9:15 pm
 IA
Posts: 563
Free Member
 

http://crashworks.org/if_programming_languages_were_vehicles/

Oh god, such truths....

<learns to code in Haskell>

Haskell? Not nearly niche enough.... 😉

I did some development work on a language where the compiler for it was written in Haskell... trendy in limited circles, you probably haven't heard of it ... 😉

Very high level languages, especially functional languages can be way more mind bending than C/C++, just obscure in a different way.


 
Posted : 06/11/2014 9:32 pm
Posts: 6259
Full Member
 

Occam is probably the most obscure I've programmed in.
or perhaps BCPL (really have no idea why we did that at uni).

Ada is one I never learned to code in, but have had to debug fairly often in the past.

Contemplated Erlang and Haskell at times, but then changed my mind.


 
Posted : 06/11/2014 10:11 pm
 IA
Posts: 563
Free Member
 

Do you have a massive beard? In which case you should crack right into Erlang. For some reason all Erlang programmers I've met have massive beards, it seems to be in some way necessary.

Haskell (and other functional languages) are fun, they let you be properly clever (for good and bad!). Progol maybe takes this a bit too far though (literally the best description of how the language works, and coincidentally how it's spelt, is "ass backwards prolog" which pleases me)


 
Posted : 06/11/2014 11:09 pm
Posts: 0
Free Member
 

Go Forth and multiply (provided you've already put the variables you want to multiply on the stack). I think that's my most obscure language.


 
Posted : 06/11/2014 11:33 pm
Posts: 6259
Full Member
 

No massive beard, so Erlang is crossed off the list.


 
Posted : 06/11/2014 11:35 pm
Posts: 91169
Free Member
 

Alternatively if you're clever and careful

Yeah well done and all, but we just needed a washing line.

Written many device drivers in Java?

Don't be a smartarse*. I was comparing problem domains where both languages can be used.

* oh wait.. you're a geek, it's what you do 🙂


 
Posted : 06/11/2014 11:43 pm
Posts: 0
Free Member
 

Don't be a smartarse*. I was comparing problem domains where both languages can be used.

A mate (at CSFB) reckons that traders at CSFB can arbitrage prices off a internal system they know can be triggered into falling behind the 'market' with its price updates if they flood it with activity - and caus\e it to go into a gc cycle.

You need a managed language for that...


 
Posted : 06/11/2014 11:54 pm
Posts: 0
Free Member
 

Also a Fix engine we use is based on the C++ ACE engine - I asked if they had a pure .NET version - they said no as there is no way they could get it to go fast enough.

We use the .NET interface and they provide tips on how to use it in a performant way - like reusing objects so as not to trigger the GC.


 
Posted : 06/11/2014 11:57 pm
Posts: 0
Free Member
 

[quote=aracer ]Edit: oh what the heck <fires up Atmel Studio>

(re i = i++)

Well how strange - that doesn't result in i incrementing, despite being gcc which did increment i under raspbian. Can't be bothered to work out what the difference is.


 
Posted : 07/11/2014 12:49 am
Page 3 / 4