LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-12-2010, 06:52 AM   #16
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723

I just think that a lot of things in C++ are just plain stupid:

References. And the fact that you can't tell the difference between them and normal variables. Why not just use pointers?

Operator overloading. Is it really that hard to type a method call? Is it really worth adding so much confusion and complication to the language?

Duplication of C's features. WTF? Why do I need two ways of doing everything? The worst part is that if you use the (IMO better) C library, it's considered "evil".

Too much type casting. IMO the less type casting, the better.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-12-2010, 07:11 AM   #17
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
I just think that a lot of things in C++ are just plain stupid:

References. And the fact that you can't tell the difference between them and normal variables. Why not just use pointers?

Operator overloading. Is it really that hard to type a method call? Is it really worth adding so much confusion and complication to the language?

Duplication of C's features. WTF? Why do I need two ways of doing everything? The worst part is that if you use the (IMO better) C library, it's considered "evil".

Too much type casting. IMO the less type casting, the better.
Consider, for starters, 'cout' and overloaded '<<'.

Also consider string concatenation and '+'.

I would call operator overloading "dubious convenience".

FWIW, even in plain "C"/Perl/etc there is implicit operator overloading - strictly saying,

Code:
int1 = int2 + int3;
int1 = int2 + fp3;
fp1 = fp2 + fp3;
('fp' stand for floating point, 'int' stands for integer) are all different kind of 'plus', by the same token different underlying functions need to be called to perform the above additions, but for some reason in the above scenario implicitly overloaded '+' is taken favorably.

Last edited by Sergei Steshenko; 04-12-2010 at 09:33 AM.
 
Old 04-12-2010, 07:15 AM   #18
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
...
Too much type casting. IMO the less type casting, the better.
Actually, it's the other way round - both C/C++ are too permissive. I would prefer them to be much stricter not allowing, for example, addition of 'double' and 'float' without am explicit type cast.

It's probably time for you to learn yet another colorful Russian expression: "You are too young and inexperienced and haven't yet burnt in a tank".
 
Old 04-12-2010, 09:26 AM   #19
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by MTK358 View Post
References. And the fact that you can't tell the difference between them and normal variables. Why not just use pointers?
One use of references is to reduce side effects, if you want a function to have access to data but not to modify it then you need to pass the data by value, rather than by reference. However for a large data structure passing by value is expensive and so the C++ reference was introduced. From the perspective of the function it is just normal data which is why it is treated the same in all respects, except for the function signature.

Last edited by graemef; 04-12-2010 at 09:43 AM.
 
Old 04-12-2010, 09:40 AM   #20
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
The overwhelming flaw of C++ is that the language rules are too complicated for even above average programmers with years of experience to really know the rules. It also has a lot of other flaws.

The overwhelming flaw in every other language, including C, is that it lacks the expressive power of C++.

If you are building a big, complicated project where performance matters, C is a very poor second choice and I don't know another language close enough to even be considered a third choice. C++ is the clear best choice.

Projects, such as Linux itself and GCC, prove that you can stretch C far beyond the realm where it belongs into areas where C++ is the only reasonable choice. But I don't think the fact that you can indicates that you should.

The way references work in C++ is not one of the flaws. If you have more experience in big projects, you will understand why that is the way references should work. It is especially not a flaw that passing by reference uses the same syntax as passing by value both at the point where the value is passed and at the point where the passed value is used, and the syntax is only different at the point where the passing method is declared.

Similarly, operator overloading is not a flaw but an important strength of the language.
 
Old 04-12-2010, 10:01 AM   #21
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by johnsfine View Post
...
The overwhelming flaw in every other language, including C, is that it lacks the expressive power of C++.
...
C is a very poor second choice
...
"C" with a smart preprocessor might be a better choice than C++. C++ is very difficult to debug when it comes to templates.
 
Old 04-12-2010, 10:30 AM   #22
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
It's what I always thought:

C + preprocessor that understands OO constructs = C++ without all the bad stuff
 
Old 04-12-2010, 10:51 AM   #23
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
By the time you make your imaginary preprocessor to be able to do what C++ can, guess where you've ended up.

C++ is indeed an "expert-friendly" language. To be even just *decent*, you need a strong grasp of the idioms as well as enough compiler theory to know how the code will shake out. If you need to care about performance, it's about the highest-level language you can use that'll still let you pull off ridiculous things when you need to.

Why do I particularly like C++? It's one of the few languages that I consider to have a sane resource management paradigm (and no, it's not "manual" at all).
 
Old 04-12-2010, 11:04 AM   #24
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by tuxdev View Post
By the time you make your imaginary preprocessor to be able to do what C++ can, guess where you've ended up.
I am not talking about all the features of C++, just objects.
 
Old 04-12-2010, 11:45 AM   #25
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by tuxdev View Post
By the time you make your imaginary preprocessor to be able to do what C++ can, guess where you've ended up.
...
I already have Perl to do a lot of things C++ template engine does.

There are already preprocessors adding to "C" OO features, but still producing "C".
 
Old 04-12-2010, 06:06 PM   #26
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by MTK358 View Post
Operator overloading. Is it really that hard to type a method call? Is it really worth adding so much confusion and complication to the language?
I would say yes, at least if you expect people to be writing classes like BigDecimal. Without operator overloading, you get code like:

Code:
BigDecimal discrimant = b.pow(2).subtract(new BigDecimal(4).multiply(a).multiply(c));
Of course, if you're going to use operator overloading, you should use it right, and not do silly things like overloading a bitshift operator to print to a file.
 
Old 04-12-2010, 06:12 PM   #27
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by graemef View Post
One use of references is to reduce side effects, if you want a function to have access to data but not to modify it then you need to pass the data by value, rather than by reference. However for a large data structure passing by value is expensive and so the C++ reference was introduced. From the perspective of the function it is just normal data which is why it is treated the same in all respects, except for the function signature.
That's what a const reference is for, but why make the distinction between part of the language? Just have a calling convention in which large objects are passed by pointer.

For non-const references, it's not a good idea to make them look like normal variables.
 
Old 04-12-2010, 06:40 PM   #28
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
Lately I've been thinking of just dropping to asm. Sure, programs will take longer to write, but at least I'll know what the !@#$ is happening in the most literal terms possible.

I probably should've learned asm first, then C/C++, but no, I wanted to be on the "fast track"! So now I've got this convoluted mash-up of concepts from C/C++ and asm in my head, and it's such a headache to mix 'n match between the two. And it doesn't help when I haven't finished reading that asm guide yet...

Last edited by MrCode; 04-12-2010 at 06:42 PM.
 
Old 04-12-2010, 07:17 PM   #29
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by MrCode View Post
Lately I've been thinking of just dropping to asm. Sure, programs will take longer to write, but at least I'll know what the !@#$ is happening in the most literal terms possible.

I probably should've learned asm first, then C/C++, but no, I wanted to be on the "fast track"! So now I've got this convoluted mash-up of concepts from C/C++ and asm in my head, and it's such a headache to mix 'n match between the two. And it doesn't help when I haven't finished reading that asm guide yet...
I am actually glad I knew C first, because I could easily relate the asm code to how it's done in C and vice versa, also because a lot of things you can use in asm come from C (such as C library functions), and documentation for functions (such as Linux sys calls) often is written in C syntax.
 
Old 04-13-2010, 06:39 AM   #30
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,045

Rep: Reputation: 65
Quote:
Originally Posted by MTK358 View Post
I am actually glad I knew C first, because I could easily relate the asm code to how it's done in C and vice versa, also because a lot of things you can use in asm come from C (such as C library functions), and documentation for functions (such as Linux sys calls) often is written in C syntax.
How do you add asm code in a .c file?
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration