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.
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...
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
@IA: Qt Creator is very popular for std C++ as well as Qt projects.
Edit: Snap chambord!
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.
Cheers, will check out what Qt Creator is like these days then, not tried it for years.
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.
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)
if (p1 == NULL)
Why the == NULL?
if (!p1)
and too many braces...
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]
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...
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.
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.
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.
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
Yes, but do you really need to do those things?
Never come across a situation in Java where I couldn't do something.
Written many device drivers in Java? 🙂Never come across a situation in Java where I couldn't do something.
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.
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.
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...
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 😀
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).
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]
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!
Ah yes - I'm sure I've seen commented out semi-colons in VB!
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 - 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.
Ah crap I'm now reading the rest of this at the bar and trying not to laugh out loud
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.
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 🙂
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.
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.
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.
<learns to code in Haskell>
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.
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.
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)
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.
No massive beard, so Erlang is crossed off the list.
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 🙂
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...
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.
[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.


