Forum search & shortcuts

What is it about C+...
 

[Closed] What is it about C++?

Posts: 7127
Full Member
Topic starter
 
[#6612590]

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?

I've got a function with what seems to be a variable called 'p'. But it's clearly not a local, and it's not in the class, so I have to go hunting around for it in the fricking class hierarchy. And by the time I've found it, I've forgotten why I cared in the first place!


 
Posted : 05/11/2014 11:48 pm
Posts: 2007
Full Member
 

I hate C++. It's a massive, kludged together, bodged lean-to-upon-a-lean-to mish mash of ideas bolted together. It seems to encourage people to experiment with all its new shiny clever features when they really should be just getting on with engineering something.

It's a bit like democracy in that it's the worst option out there, apart from all the others... 🙂


 
Posted : 06/11/2014 12:02 am
Posts: 6259
Full Member
 

convert it to this...

http://en.wikipedia.org/wiki/Brain****

wondering if (a) that'll get past rude word filters, and (b) if I earn an infraction for attempting to get rude words on to the thread.

c++ is better than java
gimme plain ansi c any day though


 
Posted : 06/11/2014 12:05 am
Posts: 0
 

Sounds more a case of poor documenting/commenting in existing code.

I enjoyed c++ and Java.


 
Posted : 06/11/2014 12:07 am
Posts: 1472
Full Member
 

I love C++.

But if a solution to your problem is looking up a class hierarchy for a variable 'p' then its not c++'s fault but over enthiusiastic use of (deep) inheritance and bad variable naming. I'd find whoever wrote it and tell him he's a ****


 
Posted : 06/11/2014 12:09 am
Posts: 42
Free Member
 

I use it day in day out and it's not so bad (Python & C are tops). With a good coding-standard, code reviews, static-analysis (etc) and avoiding all the whizz-bang features it's ok. Without those checks in place it's a good language to make a mess with. It could always be worse, you could be using PHP.


 
Posted : 06/11/2014 12:15 am
 isto
Posts: 0
Free Member
 

Sounds more a case of poor documenting/commenting in existing code.

Prob already been linked to but examples of how commenting should be done:

[url= http://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered ]commentitus[/url]


 
Posted : 06/11/2014 12:36 am
Posts: 0
Free Member
 

instead I'm reading through mountains of poorly written jumbled up and incomprehensible C++

Or in other words normal C++ 🙂

At least with C you know where you stand e.g. foo[5] == 5[foo] and other such nonsense, but C++ gulls you into thinking this might be a fully fledged language, but no..


 
Posted : 06/11/2014 12:36 am
Posts: 0
Free Member
 

[quote=oldnpastit ]What is it about this language that encourages people to write utterly opaque code?

Because they can.


 
Posted : 06/11/2014 1:00 am
Posts: 10654
Full Member
 

The only variable I can recall from the C++ modules at uni was at which point to fall asleep. 🙂


 
Posted : 06/11/2014 1:09 am
Posts: 0
Free Member
 

C++ is almost designed be to opaque by its very nature, geekiness in the extreme for geekiness's sake. Combine that with the programmers who make no effort to document what they've done (job preservation ?) and you have a recipe for an impenetrable jungle


 
Posted : 06/11/2014 1:12 am
Posts: 2887
Full Member
 

..?..

and

..?..

What you all talking about..?..


 
Posted : 06/11/2014 1:27 am
Posts: 0
Free Member
 

C++ makes me feel like a real programmer.


 
Posted : 06/11/2014 1:28 am
Posts: 6259
Full Member
 

:(){ :|: & };:


 
Posted : 06/11/2014 1:41 am
Posts: 0
Free Member
 

[quote=IanMunro ]At least with C you know where you stand e.g. foo[5] == 5[foo] and other such nonsense

for(int i=0;i<100;printf((++i%15)?(i%5)?(i%3)?"%d\n":"fizz\n":"buzz\n":"fizzbuzz\n",i));


 
Posted : 06/11/2014 2:16 am
Posts: 4954
Free Member
 

I'd agree with jonnock. I'm not a c++ master but I think many of the problems are caused by people tryign to be too clever and use every feature. KISS. Give classes and functions good interfaces and it should be easy.


 
Posted : 06/11/2014 3:23 am
Posts: 10337
Full Member
 

🙂 @ aracer


 
Posted : 06/11/2014 8:05 am
Posts: 7127
Full Member
Topic starter
 

many of the problems are caused by people tryign to be too clever and use every feature.

It seems to be encouraged by the language though. With C you have to keep things fairly simple. With C++ there seems to be a tendency to create wildly over-elaborate frameworks. The code I'm looking at has just vast pits full of pointless glue code. I spend my days wading through this gloop looking for the nuggets of code that actually do anything useful. It's so baffling that even though there's this wonderful framework for making everything super generic and flexible, it's impossible to change it. All I want is to draw some fairly simple widgets on a screen reasonably quickly.

KISS

+1


 
Posted : 06/11/2014 8:08 am
Posts: 0
Free Member
 

[quote=oldnpastit said] With C++ there seems to be a tendency to create wildly over-elaborate frameworks.

The curse of OO ? (see Java for this also)


 
Posted : 06/11/2014 8:49 am
Posts: 1472
Full Member
 

KISS

Note this applies to all languages not just c++. I can make code that is hell to debug in any language. Just employ me and give me a month or so without any code reviews.

The OP's problem is all oop's fault, see post above.

c++'s template metaprogramming allows the creation of fantastic interfaces - see std::vector (or anything in the stl) for example. Try doing that with a messy deep nest of inheritance and overloading.


 
Posted : 06/11/2014 9:18 am
Posts: 0
Free Member
 

[quote=oldnpastit ]It seems to be encouraged by the language though. With C you have to keep things fairly simple. With C++ there seems to be a tendency to create wildly over-elaborate frameworks.

Maybe I benefit from being a C programmer who writes C++ code then. I know full well how to do it horribly in C (see above) and simply use the added features of C++ to add some structure rather than the structure being the whole point.

Though as always, and as discussed above the issue is control over the environment in which coding takes place rather than anything intrinsic to the language.


 
Posted : 06/11/2014 9:20 am
Posts: 0
Free Member
 

C++ is almost designed be to opaque by its very nature, geekiness in the extreme for geekiness's sake

and languages like Perl are OK then ?

C++ is like it is for very valid reasons - wanting to extend the power of C and utilise the standard C compilers and linkers that were on all the different flavours of Unix around at the time.

And it has evolved with time and has let people experiment with different design and programming paradigms - a vast amount of what is in C# and Java now is based on ideas that were prototyped in the C++ language.

Some old code has suffered because of this - for a while it was considered good design to have massive and deep class hierarchies and then design ideas changed to more aggregation and composition.

it is perfectly possible to write modern style code in C++ which is very similar to modern Java or C#, but because of the legacy growth of the language it is also possible to write sloppy code in a mix of poor styles, and in my experience there are a lot of very mediocre C++ programmers around who do this.

The transactional nature of object construction and destruction in C++ is something I still miss when working with C# and Java and the expertise you need to overcome some of the memory and non-deterministic performance characteristics in those languages means that they aren't much of an advantage at all over C++.


 
Posted : 06/11/2014 9:29 am
Posts: 1409
Free Member
 

As a programmer that has progressed from assembler to c, and looking at potentially moving to C++ in the future. Anyone know of any good books that describe the way C++ can be used in a KISS fashion? Most books I come across just explain what C++ does, rather than how best to use it. I guess I'm really asking about OO, rather than C++. What I'm after is some guiding text that will help me use it wisely rather than just use it the first way that springs to mind.

PS before anyone suggests not using C++, and going for a different language, that is out of the question for a multitude of reasons. Not least that in the embedded world that I live, its assembler, C or C++!


 
Posted : 06/11/2014 9:41 am
 isto
Posts: 0
Free Member
 

I haven't coded in C++ since university. Since then I have used Delphi and C# with a few bits and pieces thrown in along the way. Is it not possible (even easy) to write spaghetti code in all languages?

Or do you think C++ and the framework lends itself spectacularly well to this outcome?

Favourite comment from link above:
//Dear future me. Please forgive me.
//I can't even begin to express how sorry I am.


 
Posted : 06/11/2014 9:42 am
Posts: 1472
Full Member
 

Urbanhiker have a look at [url= http://www.amazon.co.uk/gp/aw/d/0201704315?pc_redir=1414054070&robot_redir=1 ]Modern C++ Design[/url]

Note: This will not satisfy your OO needs - maybe look at [url= http://www.amazon.co.uk/gp/aw/d/0201633612?pc_redir=1414237553&robot_redir=1 ]Design Patterns[/url] for that.


 
Posted : 06/11/2014 9:45 am
Posts: 0
Free Member
 

C++ is a powerful language for making things do exactly what you want them to do

By its nature it doesn't tolerate fools

I love it


 
Posted : 06/11/2014 9:48 am
Posts: 11402
Free Member
 

Anyone know of any good books that describe the way C++ can be used in a KISS fashion?

[url=

in c++[/url]

[url=

2[/url]


 
Posted : 06/11/2014 9:49 am
Posts: 12089
Full Member
 

Urbanhiker try Accelerated C++, despite being 13 years old it's still fairly current.


 
Posted : 06/11/2014 9:53 am
Posts: 0
Free Member
 

Isto,

That stackoverflow thread is the funniest thing I have seen for a long, long time.

Thanks!


 
Posted : 06/11/2014 9:56 am
 kcal
Posts: 5450
Full Member
 

Never been a fan of C++, fine with C, and C# as well - but not C++. Not sure exactly why..


 
Posted : 06/11/2014 9:58 am
Posts: 7097
Free Member
 

Anyone know of any good books that describe the way C++ can be used in a KISS fashion?

Generally speaking you don't need a good book to do that.

The only rule I've ever gone by (many years ago now, as most embedded still seems to live on C) was "if you can do it simpler in C, don't use the C++ feature".


 
Posted : 06/11/2014 10:00 am
Posts: 0
Free Member
 

Yes, Modern C++ might not be a good choice as it is heavy on the template metaprogramming style, which is important and useful, but more advanced.

Accelerated C++ might be a good bet - I haven't read it but it is by Andrew Koenig and Barbera Moo and their other books are excellent.

Also Bjarne Stroustrup has a Tour of C++ and also the C++ programming language, I have read a few editions of the latter and, although it is not a great a book as a lot of the AT&T derived books on C were, it is worth reading as he was the inventor and you can see an essence of why he designed the language.

The Herb Sutter books are excellent as well.


 
Posted : 06/11/2014 10:01 am
 isto
Posts: 0
Free Member
 

That stackoverflow thread is the funniest thing I have seen for a long, long time.

No problem, first time I read it in work I was laughing like a maniac. It does make you want to get more creative with your comments....after all they are going to be viewed by a somewhat limited audience.


 
Posted : 06/11/2014 10:06 am
Posts: 92
Full Member
 

I think C++ and the like is behind the existence of so many "Esoteric" programming languages - invented to keep programmers human and sane. Brain**** already mentioned above but my favourite was always INTERCAL with the wonderful COME FROM instruction and the invitation to preface instructions with PLEASE.


 
Posted : 06/11/2014 10:11 am
Posts: 31206
Full Member
 

Yes you can write horrible code in any language, but C++ seems to be specifically designed around that goal!

And it is only getting better at it with each new standard.

Ah... template meta-programming that'll screw them up.

Ooh for [url= http://en.wikipedia.org/wiki/C%2B%2B11 ]C++11[/url] lets add automatic types. And lambda functions. And attributes.

Still not complex enough? Ok. For [url= http://en.wikipedia.org/wiki/C%2B%2B14 ]C++14[/url] let's add automatic return types, generic lambdas, and lambda capture expressions and variable templates.

That should keep them busy while we work on [url= http://en.wikipedia.org/wiki/C%2B%2B17 ]C++17[/url]...


 
Posted : 06/11/2014 10:49 am
Posts: 31206
Full Member
 

"Thinking In C++"

[img] [/img]


 
Posted : 06/11/2014 10:50 am
Posts: 52609
Free Member
 

The software we sell and work with uses C++ under it's own language based on C++, if there is one thing I teach on training courses is if you send me something without comments for support I'll send it back. Of course I always give up half way through a project. I'm currently working with a guy in France on something, I'm just commenting
///MIKES BIT
////END MIKES BIT
when I step into his stuff.


 
Posted : 06/11/2014 10:55 am
Posts: 401
Free Member
 

Qt was a revelation for us allowing nice clean code and a lot of highly abstracted classes to do neat stuff. Seems a shame the OP's colleague cocked it all up.


 
Posted : 06/11/2014 10:59 am
Posts: 1472
Full Member
 

And it is only getting better at it with each new standard.

Yes other languages never add new features with new releases.


 
Posted : 06/11/2014 11:03 am
Posts: 0
Free Member
 

Never been afan of C++,fine with C, and C# as well - but not C++. Not sure exactly why..

You should try Managed C++ 😈


 
Posted : 06/11/2014 11:07 am
Posts: 31206
Full Member
 

Yes other languages never add new features with new releases.

Yes but the motivation seems different.

Other languages [i]try[/i] to add features which improve them, that make them simpler, more elegant or more powerful.

The C++ Working Group seem intent on adding features that are impenetrable to average programmers and only fully understood by people on the C++ Working Group. (Who then write books explaining it!)


 
Posted : 06/11/2014 11:09 am
Posts: 31206
Full Member
 

You should try Managed C++

We use Embedded C++ with no heap allocation.

I think it actually makes it easier 😀


 
Posted : 06/11/2014 11:10 am
Posts: 0
Free Member
 

Oh I wasn't suggesting it was easier - once had the pleasure of having to use it to interface hardware with C style interfaces into .Net system. Interesting because it gives you full access to all the standard low level C stuff, so allows you to break managed .Net code if you're not careful!


 
Posted : 06/11/2014 11:29 am
Posts: 0
Free Member
 

On the comments front, I'm doing some moonlighting for an old employer at the moment and 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". I thought that was a silly situation so I figured I'd work out what was going on. So it was that after 6 billable hours I've amended it to "I still don't know what this does but if I take it out nothing works".

Bloody Mivascript.


 
Posted : 06/11/2014 11:33 am
 IA
Posts: 563
Free Member
 

There are worse things than C++.

I have some prototype code that features a webserver implemented in Matlab.


 
Posted : 06/11/2014 11:34 am
Page 1 / 4