C++ Programmers...

Armitage

Banned
Feb 23, 2001
8,086
0
0
Was helping a guy with some C++ code recently and discovered that, despite claiming to be a "good" C++ programmer, he knew nothing about the STL or single inheritance/polymorphism! Claimed he had never needed them.

I find the STL indespensible, and single inheritance very useful as well. On the other hand, I rarely use templates, and have never used multiple inheritance. As in writing my own at least. Granted, I'm not a pro - but I do write alot of code as part of my job.

So what parts of the language do you use?
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
I use pretty much all features of C++ as needed. Most of the template usage (non-STL) is simple, although invaluable. I do not recall ever using multiple inheritance as part of my job (simply because it was unneeded). However, I have used it often in personal projects. I would probably not have as much use for C++ if it weren't for templates & STL.
 

SamurAchzar

Platinum Member
Feb 15, 2006
2,422
3
76
"Proper" C++ code can be a messy biatch. I dislike the langauge in general as well as its syntax. Granted, it has several good aspects (object orientation, obviously, as well as inheritance, etc) but C++ programs utilizing all features (like operator overloading, WTF?) look like an unreadable mess.
In the case of C++, I think that a generally less adept/experienced programmer will go full-tilt and use every single bit.

I therefore stick to C on my projects (hundreds of thousands of lines, usually), but do it in a very object-oriented fashion.

 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: SamurAchzar
"Proper" C++ code can be a messy biatch. I dislike the langauge in general as well as its syntax. Granted, it has several good aspects (object orientation, obviously, as well as inheritance, etc) but C++ programs utilizing all features (like operator overloading, WTF?) look like an unreadable mess.

What's not to like about operator overloading? I consider that to be a key feature.

In the case of C++, I think that a generally less adept/experienced programmer will go full-tilt and use every single bit.

I therefore stick to C on my projects (hundreds of thousands of lines, usually), but do it in a very object-oriented fashion.

 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
We still use Visual Studio 6 and MFC at work, and haven't seen any value in STL, multiple inheritance or templates for the code we write.

MFC has string and collecton classes that do enough for us, so mixing in the STL and overcoming the clashes hasn't been worth the effort.

Templates have a negative effect on maintainability for our code, which has many parts that are updated only a few times a year.

We use single inheritance to extend the MFC classes, but only a little bit in our own classes.
 

SamurAchzar

Platinum Member
Feb 15, 2006
2,422
3
76
Originally posted by: Armitage
What's not to like about operator overloading? I consider that to be a key feature.

Well, maybe my view is biased, as I only do embedded software/drivers development, but I like things to remain minimalistic and comprehensible. I write extremely clean code, and review what I write - even if I'm the only one to ever see that code - to see if it's totally understandable at a glance.
Overloading, whether function or operator, only add ambiguity IMHO, especially on large projects where you use many data types.




 

Stuxnet

Diamond Member
Jun 16, 2005
8,392
1
0
Originally posted by: Armitage
Was helping a guy with some C++ code recently and discovered that, despite claiming to be a "good" C++ programmer, he knew nothing about the STL or single inheritance/polymorphism! Claimed he had never needed them.

This is a very sore spot with me. 90% of the developers out there think they're "good" because they can write a piece of software that technically passes the spec. Take our most recent hire, for instance:

"I'm a VB.Net expert."
"I'm a little light on OO... never really needed it."

Can't have it both ways. BTW:

"light on OO" = "don't know what SINGLE INHERITANCE is, let alone interfaces, abstraction, polymorphism, encapsulation"

 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: SamurAchzar
Originally posted by: Armitage
What's not to like about operator overloading? I consider that to be a key feature.

Well, maybe my view is biased, as I only do embedded software/drivers development,

I don't know much about that environment, but is C++ even an option there typically?

but I like things to remain minimalistic and comprehensible. I write extremely clean code, and review what I write - even if I'm the only one to ever see that code - to see if it's totally understandable at a glance.
Overloading, whether function or operator, only add ambiguity IMHO, especially on large projects where you use many data types.

I think operator overloading makes for cleaner code - at least if the type has a clear analog for the operation in question. Vectors for example - I think it's much clearer to add vectors via an overloaded operator then expand my code by another 3 lines to do it with a loop (braces required on their own line in the coding style I work with).

Of course, you could define an add() function - but if the operation is clearly defined for the type I have no problem overloading it. On the other hand, I used to have a vector cross-product overloaded as the '*' operator - but in practice that analogy wasn't clear enough (confusion with dot product among other issues), so I ditched it in favor of named functions.

Function overloading ... it's convenient, but ripe for abuse especially when combined with default arguments. I tend to use it mainly for constructors.
 

SamurAchzar

Platinum Member
Feb 15, 2006
2,422
3
76
Originally posted by: Armitage
Originally posted by: SamurAchzar
Originally posted by: Armitage
What's not to like about operator overloading? I consider that to be a key feature.

Well, maybe my view is biased, as I only do embedded software/drivers development,

I don't know much about that environment, but is C++ even an option there typically?

Yep, as embedded can be anything from multi-processor networking cards to 8 bit microcontrollers, and even those have C++ in the recent years (through a simplifcation called EC++, IIRC). You see more and more embedded Linux as well as GCC. Proprietary compilers are usually the limiting factors with C++, as it's quite a burden, but tools are becoming better and more standartized. So no problem in using C++, if you like to.
PC drivers are a different thing, though...

I think operator overloading makes for cleaner code - at least if the type has a clear analog for the operation in question. Vectors for example - I think it's much clearer to add vectors via an overloaded operator then expand my code by another 3 lines to do it with a loop (braces required on their own line in the coding style I work with).

Function overloading ... it's convenient, but ripe for abuse especially when combined with default arguments. I tend to use it mainly for constructors.

You have a point, but think of glancing through codes. '+' suddenly gets an entirely different meaning when you overload it, it's confusing. It's not a problem in local terms, but when you're dealing with huge projects, it's a pain. And there's the issue of abuse you've very rightly mentioned. The world is full of crap programmers just waiting to obfuscate code. I wouldn't like to give them tools to do so.
 

watdahel

Golden Member
Jun 22, 2001
1,657
11
81
www.youtube.com
Originally posted by: jbourne77
Originally posted by: Armitage
Was helping a guy with some C++ code recently and discovered that, despite claiming to be a "good" C++ programmer, he knew nothing about the STL or single inheritance/polymorphism! Claimed he had never needed them.

This is a very sore spot with me. 90% of the developers out there think they're "good" because they can write a piece of software that technically passes the spec. Take our most recent hire, for instance:

"I'm a VB.Net expert."
"I'm a little light on OO... never really needed it."

Can't have it both ways. BTW:

"light on OO" = "don't know what SINGLE INHERITANCE is, let alone interfaces, abstraction, polymorphism, encapsulation"

and you still hired the guy
 

nova2

Senior member
Feb 3, 2006
982
1
0
"SamurAchzar: It's not a problem in local terms, but when you're dealing with huge projects, it's a pain."

operator overloading has its place and pros/cons like many things.

so simply put, if you're coding a large project and don't want to use it, then don't

@Armitage:
yeah I will pretty much make use of all that, but it depends on the project at times.
 

SamurAchzar

Platinum Member
Feb 15, 2006
2,422
3
76
Originally posted by: nova2
"SamurAchzar: It's not a problem in local terms, but when you're dealing with huge projects, it's a pain."

operator overloading has its place and pros/cons like many things.

so simply put, if you're coding a large project and don't want to use it, then don't

Yep, I stand corrected. My opinion anyway, and probably applies to very specific kind of coding

 

Neverm1nd

Member
Jul 3, 2006
42
0
0
After writing this, I realized that it became more of a rant about common complaints about C++ than an on-topic reply to the OP's questions. Sorry for derailing the thread.

One tends to see a lot of critisism of C++'s more powerful features. Here's my take on a few of them, and a few of the questions in the original post.

Operator overloading:
Of course it can be abused, just like any other feature in a language. That doesn't mean that it isn't useful. On the contrary, operator overloading (properly used) makes code much more readable. Do you really prefer java's string.equals to an overloaded == operator? If you write a class where size is clearly defined, do you really think instance1.IsGreaterThan(instance2) is more readable than instance1 > instance2? Would you prefer the same treatment of primitive datatypes?

Function overloading:
What's polymorphism without it? The ability to write one base class which implements the basic features of a set of classes saves tons of time, not to mention code repetition (and thus maintainability). Function overloading is great if you want one type of object to behave slightly differently to the others, or return custom data. As an example, I write an app which, among other things, have a few different types of objects like text boxes, pictures, charts, etc which can be dragged around the window to change places, etc. Each of these objects inherits the same base class, which contains functions like GetMinimumSize. Now, because of function overloading, I can have an array containing all the objects, independent of their types, and recalculate the layout without caring about their type. A text box will have a different implementation of GetMinimumSize than a picture, but it all looks the same to the layout calculator. Trying to do this without inheritance would be a real pain.

Classes:
Really, who writes C++ code longer than a few dozen lines without classes?

STL:
I don't use it much myself, mostly because I already have other libs which contains standard functions so one more is just redundant. Not using premade libs greatly increases your workload, because you have to reinvent every wheel yourself (and likely, quite a few of them will be square). Most likely the three dozen or so standard libraries which contain implementations of complex numbers are all better than what one person could produce in a reasonable time anyway.

Single Inheritance:
Again, if you have two very similar classes, why implement all their common functionallity twice?

Templates:
A great tool when you use it right, even if it has a few quirks (especially with visual studio). Not one I use often, but when I need it it's there.

STL strings:
Actually, one of the worst things about C++ (and many other languages) is the string handling. If you use some MFC, some ATL, som STL, etc. you're going to wind up with three dozen different kinds of strings, most of which you'll have to write your custom casting functions between. A quick look in our code reveals ATL::CString, char*, wchar*, wchar_t*, LPOLESTR, LPCTSTR, LPWSTR, TCHAR, PCXSTR, and there's a lot more, not to mention most of these can hold unicode, ascii, etc. And just for kicks, some of these change when you upgrade your compiler and libraries. What I wouldn't give for a single, universal string class, no matter how bad it was.

Multiple Inheritance:
This is also a usefull tool, but careful, careful, it can be a bit tricky at times. On a side note, one of the worst flaws with MFC is that you can't do multiple inheritance if more than one base class inherits from CWnd. And disambiguating CObject members can be a real pain too. Maybe I'm just incompetent, but it seems to me that the language tools for MI is somewhat lacking.

Pointers:
Somehow, on any programming forum, there's allways someone moaning about how difficult pointers are. Huh? Not only can't I really undestand what the problem is (once you've grasped the basic concept that the pointer contains a memory address, what's the difficulty?), I also can't see how doing away with them won't complicate some types of code greatly.

In closing, I'd like to make three points:

Any tool can be abused. Removing or restricting a language feature just because some programmers can't use it properly just punishes those who can. Also, the fact that a tool can be abused doesn't mean that it doesn't have good uses, or that it's use should be considered bad practice.

Noone is forcing you to use any language feature. If you don't like it, don't use it, it's as simple as that.

Use the right tool for the job. C++ is a great multi-purpouse language, but no language is the be-all and end-all of tools. Sometimes batch scripts fit the job better, sometimes javascript is the tool to use. Because a language isn't optimally suited for each and every concievable application doesn't make it useless.
 

Cooler

Diamond Member
Mar 31, 2005
3,835
0
0
I use STL /Strings all the time. Some of the built in sorting algorithms for sorting heaps can not really be beat in efficiency unless you have a week or so to write your own. I use a lot of Inheritance for typecasting objects to a singular parent type so they all fit within a single array.
 

itachi

Senior member
Aug 17, 2004
390
0
0
Originally posted by: Neverm1nd
Function overloading:...
polymorphism without function overloading is polymorphism. it has nothing to do with inheritance, where a virtual method is overriden by a subclass.

Single Inheritance:...
thats the kind of mentality that has led to its overuse. composition can be a more practical solution.

STL strings:...
if you're gonna complain about C++'s handling of strings, don't bring up other proprietary libraries.. the STL is a part of the C++ standard, MFC and ATL are proprietary libraries. blame microsoft, not iso.

Pointers:...
to that same extent.. i could argue that anyone who complains about how difficult coding in assembly is doesn't really understand the foundations. fact of the matter is, it doesn't matter how well you understand the underlying architecture or concepts, it won't make it any less complex.

that's not to say that assembly has no use anymore.. there's numerous situations where writing assembly can be beneficial or necessary. same goes for pointers, especially with object-oriented languages. in java and c#, all objects are allocated on the heap. in other words, object variables refer to a location in memory. the only difference is that the user can't manipulate the pointer or use them in an obfuscating manner (like int (*(*fv(int)))[13]; to access the ctype functions).
 

Cooler

Diamond Member
Mar 31, 2005
3,835
0
0
One feature that C/C++ that very few languages have is pointer arithmetic. Basically you can scan memory with it and find variables in other programs and hook into them. You can do this in asm as well but it not as easy on the eyes.
 
Sep 29, 2004
18,656
67
91
Havn't used C++ in atleast 2 years. Well before STL was common.

And never used multiple inheritance except one proof of concept project i did at work. Involved the TCP/IP stack ...... was elegant but slightly confusing at hte same time.

Keep in mind that alot of old timers have trouble undertanding new concept.s Doing structured programming for 10 years then having to understann OO is not an easy thing. It will happen to you one day ... so just remember that. You will eventually have trouble picking the latest concepts up.

Took me 5 years to really udnerstand OO. I thought I understood it 5 years ago though. Never stop learning I guess.
 

Neverm1nd

Member
Jul 3, 2006
42
0
0
Originally posted by: itachi
polymorphism without function overloading is polymorphism. it has nothing to do with inheritance, where a virtual method is overriden by a subclass.
I missunderstood the term function overloading, sorry (English isn't my first language). Just move this to inheritance then.

Function overloading can still be usefull though, but it seems most of the time it's used templates would have been a better way.

Originally posted by: itachi
thats the kind of mentality that has led to its overuse. composition can be a more practical solution.
Yes, it can. It can also be a considerably less practical solution. I've seen very few examples where subclassing was incorrectly used instead of composition, but a lot of the opposite.

Originally posted by: itachi
if you're gonna complain about C++'s handling of strings, don't bring up other proprietary libraries.. the STL is a part of the C++ standard, MFC and ATL are proprietary libraries. blame microsoft, not iso.
I'm not blaming anyone, I'm just whining. MFC predates the inclusion of STL into the ISO standard, so you can't really blame them for trying to provide a useable string class.

Originally posted by: itachi
to that same extent.. i could argue that anyone who complains about how difficult coding in assembly is doesn't really understand the foundations. fact of the matter is, it doesn't matter how well you understand the underlying architecture or concepts, it won't make it any less complex.
Pointers aren't inherently more complex than any other kind reference variable, and their mathematics isn't any different from an int. Again, just because you can do complex things with pointers doesn't neccesarily mean that you should.

Assembly is 'difficult' to code in because it requires many lines of code to do simple things, and because it doesn't have all of the tools which makes programming in higher level languages quicker and easier. I would argue that assembler is very simple, but very time consuming to code.

Originally posted by: itachi
that's not to say that assembly has no use anymore.. there's numerous situations where writing assembly can be beneficial or necessary. same goes for pointers, especially with object-oriented languages. in java and c#, all objects are allocated on the heap. in other words, object variables refer to a location in memory. the only difference is that the user can't manipulate the pointer or use them in an obfuscating manner (like int (*(*fv(int)))[13]; to access the ctype functions).
Are you arguing that object variables in these languages are fully equivalent to pointers? I admit I'm not an expert in any of them, but it seems to me many of pointers' uses would be hard to emulate in this way. I'll take another example from our app: there's potentially a lot of data gathered in channels, and the user can define custom channels by inputting mathematical functions, something like channel3 = channel1*channel2. The app then allocates a block of memory and writes assembly code (in binary, of course. This is a quick pseudocode, so it's most likely wrong. Assume that channel3 has been allocated and channel1 has been copied to it):
pusha
mov eax, 0x3333 // addr of &channel3[0]
mov ebx, 0x2222 // addr of &channel2[0]
mov ecx, 10000 // loop counter, size of channels
mul [eax], [ebx]
inc eax
inc ebx
loopnz (address of line 4)
popa
jmp (caller address)

and then this block is executed.
How this could be done quickly without pointers is beyond me.


 

itachi

Senior member
Aug 17, 2004
390
0
0
Originally posted by: Neverm1nd
Yes, it can. It can also be a considerably less practical solution. I've seen very few examples where subclassing was incorrectly used instead of composition, but a lot of the opposite.
can you give some examples where you feel composition is used incorrectly?
most of what i've seen is having a class inherit from another simply because they provide similar functionality.. not because the tighter coupling benefited the design.

Pointers aren't inherently more complex than any other kind reference variable, and their mathematics isn't any different from an int. Again, just because you can do complex things with pointers doesn't neccesarily mean that you should.
the concept is simple, but using them opens up pandora's box.

Assembly is 'difficult' to code in because it requires many lines of code to do simple things, and because it doesn't have all of the tools which makes programming in higher level languages quicker and easier. I would argue that assembler is very simple, but very time consuming to code.
it's not difficult simply because of the amount of code you need to write to do something simple.. it's the amount of effort that needs to be put in writing (referring back to the isa manual constantly), testing/debugging, and maintaining the code.

Are you arguing that object variables in these languages are fully equivalent to pointers? I admit I'm not an expert in any of them, but it seems to me many of pointers' uses would be hard to emulate in this way. I'll take another example from our app: there's potentially a lot of data gathered in channels, and the user can define custom channels by inputting mathematical functions, something like channel3 = channel1*channel2. The app then allocates a block of memory and writes assembly code (in binary, of course. This is a quick pseudocode, so it's most likely wrong. Assume that channel3 has been allocated and channel1 has been copied to it):
that's the closest way to describe them. except unlike c/c++, the address is stored in a symbol, not a variable.

the main thing about pointers that you can't emulate is the lack of type safety.. in c, you can do - void * vp; char * ptr = *((char **) &vp); and not get an error.
also.. depending on how large each block is and where in physical memory they're allocated.. a managed language can be faster than c++ for the example you gave.
 

Neverm1nd

Member
Jul 3, 2006
42
0
0
Originally posted by: itachi
can you give some examples where you feel composition is used incorrectly?
most of what i've seen is having a class inherit from another simply because they provide similar functionality.. not because the tighter coupling benefited the design.
I see something like this fairly regularly:
class Foo
{
...
};
class Bar
{
public:
Foo m_Foo;
};
class Baz
{
public:
Foo m_Foo;
};
....
// do this for all Bars
for(int i = 0; i < arrBars.GetSize(); i++)
arrBars.GetAt(i)->m_Foo.DoStuff();
// do this for all Bazs
for(int i = 0; i < arrBazs.GetSize(); i++)
arrBazs.GetAt(i)->m_Foo.DoStuff();

... and a lot of similar desings, where you'll need a separate code block for each type because they don't inherit.

Originally posted by: itachi
the concept is simple, but using them opens up pandora's box.
No, using them in incorrect or confusing ways opens up pandoras box, just like any other feature of any programming language. Sanely used, I maintain that they are Good For You (TM).

Originally posted by: itachi
it's not difficult simply because of the amount of code you need to write to do something simple.. it's the amount of effort that needs to be put in writing (referring back to the isa manual constantly), testing/debugging, and maintaining the code.
Precisely, it's not difficult, just very time consuming.

Originally posted by: itachi
the main thing about pointers that you can't emulate is the lack of type safety.. in c, you can do - void * vp; char * ptr = *((char **) &vp); and not get an error.
You could but should you? Of course it takes very little effort to shoot yourself in the foot intentionally, but sane programming practices, like avoiding void pointers unless they are absolutely neccessary (and using dynamic_cast when dealing with pointers unless performance is absolutely critical), avoids these kinds of messes.

Originally posted by: itachi
also.. depending on how large each block is and where in physical memory they're allocated.. a managed language can be faster than c++ for the example you gave.
As I said, I don't know very much Java, but I'd love to see how you can write and execute arbitrary assembler in runtime. If you could provide a bare-bones example, I'd be very interested.

 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |