Liking C++ discussion

Post updates of what you've been working on, make your development announcements, etc.

Moderator: samw3

User avatar
SSquared
Posts: 1351
Joined: Sun Dec 16, 2007 9:14 am
Location: The Beautiful Pacific Northwest
Contact:

Liking C++ discussion

Postby SSquared » Mon Nov 23, 2009 4:34 pm

To prevent the "Favorite Parts of Development" thread from going off-topic, I pulled out the end where I asked Mene-Mene what he likes so much about C++. I wanted to delve a little more into this so I figured I'd make a separate thread.
Mene-Mene wrote:It's code that is produced is beautiful. You can do so much with so little, the control you have is immense and the notations are so readable...
What do you mean the code "produced is beautiful"? And what do you mean by "You can do so much with so little"? Are you saying C++ is hardly anything, and yet you can build all sorts of things?

One thing I really like about C++ which sets it apart from some other languages is that it is Object Oriented. Writing in OO is one way I see the code as, perhaps, beautiful.
My quote: Have I mentioned I love C# and the iPad?
Another quote: Have I mentioned I love the iPad?
User avatar
ArchAngel
Posts: 1534
Joined: Sun Dec 16, 2007 12:23 am

Re: Liking C++ discussion

Postby ArchAngel » Mon Nov 23, 2009 4:39 pm

My favorite languages are C++ styled, but as with most languages each have their places.

I'd much rather code a windows application in C# and PHP my language of choice for server sided programming. C++ has a well rounded and powerful, but when it comes to beauty of code, I give that regard more to architect and programmer.
Algorithms define beauty far more than syntax does.
Q.E.D.
User avatar
jestermax
Posts: 398
Joined: Sun Dec 16, 2007 9:14 am
Location: Ontario, Canada

Re: Liking C++ discussion

Postby jestermax » Mon Nov 23, 2009 6:02 pm

I think the thing I like about C++ is that it's a simple interface to some cooler things (yes, I know C does the same thing).
I've been using it lately with NVidia's CUDA and OpenMP lately and it's fun. Writing CUDA code is much better in C/C++ than assembly and you can impress the ladies with it.
christo
Posts: 612
Joined: Sun Dec 16, 2007 11:38 am

Re: Liking C++ discussion

Postby christo » Mon Nov 23, 2009 6:03 pm

Note:Opinion based on possibly outdated experience. It has been years since I last tried to do anything independently in C or C++.

When I think of C++(or C) I tend to think of all those nasty include files and long lists of arcane constants. Also having to remember to tell the IDE where to find every file including the programs to compile and link the program while setting just the right flags on the compiler to get the program to run on my particular computer. Thankfully languages have improved since then(thinking C# and VB.Net) and I can now focus on coding instead of my headaches.
Mike
Posts: 923
Joined: Tue Dec 18, 2007 5:22 pm

Re: Liking C++ discussion

Postby Mike » Mon Nov 23, 2009 6:54 pm

christo wrote:Note:Opinion based on possibly outdated experience. It has been years since I last tried to do anything independently in C or C++.

When I think of C++(or C) I tend to think of all those nasty include files and long lists of arcane constants. Also having to remember to tell the IDE where to find every file including the programs to compile and link the program while setting just the right flags on the compiler to get the program to run on my particular computer. Thankfully languages have improved since then(thinking C# and VB.Net) and I can now focus on coding instead of my headaches.
Should look at Qt solves alot of that. It's free does sound, networking, 2d, 3d graphics, and course a great GUI.

The replace most the primitive types with Q versions so it cross compiles better. I don't cross compile myself but I have a friend that builds everything three ways. Linux, Windows, and Mac
christo
Posts: 612
Joined: Sun Dec 16, 2007 11:38 am

Re: Liking C++ discussion

Postby christo » Mon Nov 23, 2009 7:17 pm

I think I may take a look at that later.so far I have just gotten around to downloading it and I have another project in progress. Thanks for pointing me to it.
User avatar
Mene-Mene
TALKer!
Posts: 2760
Joined: Sun Dec 16, 2007 7:10 am
Location: Indiana, United States

Re: Liking C++ discussion

Postby Mene-Mene » Mon Nov 23, 2009 7:47 pm

Yes, in the simplicity of OOP C++ does show beauty, but mainly I find beauty in much with little while still being readable...

Code: Select all

int x;
int y = 2;
int* pint = &x;
*pint = 6&y;
cout<<x;
That to me is beauty... With that little code you can do so much...

By much with little I mean quantity of code over quality of production.

Another thing I like about it is the fact that the logical operators are | in an operation and || in an equation.

Edit:
Yes, I realize that I could just as easily do something like:

Code: Select all

cout<<(6&2);
and functionally that would perform the same thing...
M^2 out-
It's Time to get Terminal!
User avatar
SSquared
Posts: 1351
Joined: Sun Dec 16, 2007 9:14 am
Location: The Beautiful Pacific Northwest
Contact:

Re: Liking C++ discussion

Postby SSquared » Mon Nov 23, 2009 8:38 pm

I have to say, I am in the complete opposite camp of readable, I guess. Any time you have pointers and addresses, code starts to become tougher to read. I tend to find code like that forces me to sit back and think through what is happening rather than being simple and straightforward to read. Many (most?) will cringe as soon as they see pointers or '&'. Perhaps your view of beauty is the power behind what you are doing, and not necessarily the look or readability of it.

Also, it actually took me a bit to figure out what you were doing with '6&y'. Especially since it was right after the line with '&x', so my brain was thinking of that syntactically. Since there is already syntax of '&' followed by a variable name, when you want to do a bit-wise operand, it is actually easier to read if you separate things out: '6 & y' is easier to read and resolve in our heads.

And I think, other than the cout line, the rest can be done in 'C' as well. This is one reason I asked the question; to find out how much of your answers would be 'c'-related.

I am with ArchAngel on beauty being outside of syntax.
My quote: Have I mentioned I love C# and the iPad?
Another quote: Have I mentioned I love the iPad?
User avatar
JeTSpice
TALKer!
Posts: 2423
Joined: Sun Dec 16, 2007 10:39 am
Location: Coeur d'Alene, ID
Contact:

Re: Liking C++ discussion

Postby JeTSpice » Mon Nov 23, 2009 8:44 pm

i like the graphics.
User avatar
PFC
Posts: 633
Joined: Sun Dec 16, 2007 5:57 pm
Location: Canada

Re: Liking C++ discussion

Postby PFC » Mon Nov 23, 2009 10:51 pm

C++ readable???

well I suppose its more readable than assembly... but all those "{}" and ";" and the over use of double characters such as "<<" and ">>" and "//" make it very hard to follow and to program.

why have:

Code: Select all

int a,b;
a = 1;
b = 2;
cout << a << " " << b << endl ;    //print  "1 2" then goes to next line
when you can have:

Code: Select all

a, b = 1, 2
print(a,b)                      #print "1 2" and then go to next line
and not to mention those nested loops..... :evil:

C and C++ have their place, they are very powerful languages in terms of what they can do, however they are not easily readable and take allot of code to represent something that could be represented in a higher language with much less work for the programmer
Mike
Posts: 923
Joined: Tue Dec 18, 2007 5:22 pm

Re: Liking C++ discussion

Postby Mike » Tue Nov 24, 2009 3:57 am

PFC wrote:C++ readable???
C and C++ have their place, they are very powerful languages in terms of what they can do, however they are not easily readable and take allot of code to represent something that could be represented in a higher language with much less work for the programmer
Use C++ but yes I would argue basic is more readable. And going way back line numbers being more intuitive to how a new programmer would think. I do think C or C++ should be the second language they learn for many of the reasons listed above.
User avatar
Lazarus
Posts: 379
Joined: Sun Dec 16, 2007 4:11 pm

Re: Liking C++ discussion

Postby Lazarus » Tue Nov 24, 2009 4:17 am

PFC wrote: C and C++ have their place, they are very powerful languages in terms of what they can do, however they are not easily readable and take allot of code to represent something that could be represented in a higher language with much less work for the programmer
Uhm. This.

C++ is about as beautiful as your 100 year old grandmother imo. -_-
User avatar
jestermax
Posts: 398
Joined: Sun Dec 16, 2007 9:14 am
Location: Ontario, Canada

Re: Liking C++ discussion

Postby jestermax » Tue Nov 24, 2009 9:50 am

COBOL IS MORE READABLE. ALL OF YOU ARE WRONG
User avatar
samw3
Site Admin
Posts: 1239
Joined: Sun Dec 16, 2007 2:00 pm
Location: Toccoa, GA
Contact:

Re: Liking C++ discussion

Postby samw3 » Tue Nov 24, 2009 10:44 am

Generally, I like C more than C++. If C was "human", C++ is Frankenstein. It was sort of a hodge-podge language created back when object-orientation was just getting established.

As for readability, I think it's just like spoken languages--it's about what you're familiar with.

Objective-C, imho, is a much more structured OOP language and yet coders often reject it early as ugly and unreadable (even I did).

I think the reason why C++ is still around is because it's so stinkin' fast.
User avatar
SSquared
Posts: 1351
Joined: Sun Dec 16, 2007 9:14 am
Location: The Beautiful Pacific Northwest
Contact:

Re: Liking C++ discussion

Postby SSquared » Tue Nov 24, 2009 12:00 pm

My first foray into OO was Obj-C on the NeXT. I don't recall much from it, though. I was going to write my Senior Project using it, but ended up using Turbo Pascal on the Mac.

My real entry into OO was Smalltalk which is a much more OO language than C++. Maybe similar to Obj-C in this sense? C++ still has too much procedural thinking/syntax/formatting with it as opposed to actions (sending messages). As with Obj-C, many may find Smalltalk different enough to make it difficult to read.

Some code earlier in this thread can be simplified to: int a = 1,b = 2; One line instead of three.

> If C was "human", C++ is Frankenstein. It was sort of a hodge-podge language created
> back when object-orientation was just getting established.

Can you please explain this a bit more? I was going to respond to this, but want to know if how I'm reading this is actually what you are trying to say.
My quote: Have I mentioned I love C# and the iPad?
Another quote: Have I mentioned I love the iPad?
User avatar
samw3
Site Admin
Posts: 1239
Joined: Sun Dec 16, 2007 2:00 pm
Location: Toccoa, GA
Contact:

Re: Liking C++ discussion

Postby samw3 » Tue Nov 24, 2009 12:24 pm

I mean that it doesn't have the cohesiveness of modern day languages. It's build on top of C and, in my opinion, is visually unstructured. Consider these classes. One in C++(2 files, 40 lines) one in java(1 file, 22 lines):

Code: Select all

Header File: cube.h

#ifndef CUBE_H
#define CUBE_H

class Cube{
public:	
	Cube();	
	~Cube();	
	void setSide(double s);	
	double getSide();	
	double Area();	
	double Volume();	
	void Properties();
private:	
	double Side;
};
#endif

Source File cube.cpp

#include <iostream.h>
#include "cube.h"

Cube::Cube(){}
Cube::~Cube(){}
void Cube::setSide(double s) {	
	Side = s <= 0 ? 1 : s;
}
double Cube::getSide() {
	return Side;
}
double Cube::Area(){
	return 6 * Side * Side;
}
double Cube::Volume(){	
	return Side * Side * Side;
}
void Cube::Properties(){
	cout << "Characteristics of this cube";	
	cout << "\nSide   = " << getSide();	
	cout << "\nArea   = " << Area();	
	cout << "\nVolume = " << Volume() << "\n\n";
}

Code: Select all

public class Cube {
	private double	Side;
	public void setSide(double s) {
		Side = s <= 0 ? 1 : s;
	}
	public double getSide() {
		return Side;
	}
	public double Area() {
		return 6 * Side * Side;
	}
	public double Volume() {
		return Side * Side * Side;
	}
	public void Properties() {
		System.out.println("Characteristics of this cube");
		System.out.println("Side   = " + getSide());
		System.out.println("Area   = " + Area());
		System.out.println("Volume = " + Volume());
		System.out.println();
	}
}
The java one is considerably more concise. The C++ one can't be because it has to conform to C in a lot of ways. It's stuck in the past.
User avatar
vibrokatana
Posts: 42
Joined: Wed Apr 01, 2009 8:52 pm
Location: FL
Contact:

Re: Liking C++ discussion

Postby vibrokatana » Tue Nov 24, 2009 1:10 pm

samw3 wrote:I mean that it doesn't have the cohesiveness of modern day languages. It's build on top of C and, in my opinion, is visually unstructured. Consider these classes. One in C++(2 files, 40 lines) one in java(1 file, 22 lines):

Code: Select all

Header File: cube.h

#ifndef CUBE_H
#define CUBE_H

class Cube{
public:	
	Cube();	
	~Cube();	
	void setSide(double s);	
	double getSide();	
	double Area();	
	double Volume();	
	void Properties();
private:	
	double Side;
};
#endif

Source File cube.cpp

#include <iostream.h>
#include "cube.h"

Cube::Cube(){}
Cube::~Cube(){}
void Cube::setSide(double s) {	
	Side = s <= 0 ? 1 : s;
}
double Cube::getSide() {
	return Side;
}
double Cube::Area(){
	return 6 * Side * Side;
}
double Cube::Volume(){	
	return Side * Side * Side;
}
void Cube::Properties(){
	cout << "Characteristics of this cube";	
	cout << "\nSide   = " << getSide();	
	cout << "\nArea   = " << Area();	
	cout << "\nVolume = " << Volume() << "\n\n";
}

Code: Select all

public class Cube {
	private double	Side;
	public void setSide(double s) {
		Side = s <= 0 ? 1 : s;
	}
	public double getSide() {
		return Side;
	}
	public double Area() {
		return 6 * Side * Side;
	}
	public double Volume() {
		return Side * Side * Side;
	}
	public void Properties() {
		System.out.println("Characteristics of this cube");
		System.out.println("Side   = " + getSide());
		System.out.println("Area   = " + Area());
		System.out.println("Volume = " + Volume());
		System.out.println();
	}
}
The java one is considerably more concise. The C++ one can't be because it has to conform to C in a lot of ways. It's stuck in the past.
The C++ one will also be 2-5x faster and use 10x less memory. Oh and BTW you can write a class and define the functions at the same time. It isn't recommended because it will make the compiler cry with large projects.

--

My biggest gripe with C/C++ is the includes. Try working with multiple libraries, some in the PATH, some local, etc. It only gets worst if you need to compile it on multiple systems. If it wasn't for this I would probably spend more time with C++. Compare it with something like .NET and python and the old include system is ugly and a PITA. Namespaces IMO make for a decent replacement for the old include system, but the language is old (and stable) so I don't think any of that will ever change.

IMO most interop sucks because C is the lowest common denominator for most languages. Each language implements things in their own way (which is sorta good in its own right) but it makes high level abstractions (like objects) virtually impossible to share. Programs rarely (if ever) talk to one another on even the same system, which is sorta sad.

[/rant]
User avatar
Mene-Mene
TALKer!
Posts: 2760
Joined: Sun Dec 16, 2007 7:10 am
Location: Indiana, United States

Re: Liking C++ discussion

Postby Mene-Mene » Tue Nov 24, 2009 2:18 pm

I still have a much better time reading C++ than C#, Java, or most other languages... I think it's one of those things that once you get over the intimidating aspect, it's much easier to read... Like Japanese has much better language structure than English, but is much more intimidating at first.

PFC: You don't have to use iostream.

katana: I have to agree with you about includes being a pain.
M^2 out-
It's Time to get Terminal!
User avatar
SSquared
Posts: 1351
Joined: Sun Dec 16, 2007 9:14 am
Location: The Beautiful Pacific Northwest
Contact:

Re: Liking C++ discussion

Postby SSquared » Tue Nov 24, 2009 2:31 pm

Thanks Sam. That *is* a bit different than how I read your post.

> Oh and BTW you can write a class and define the functions at the same time.

I was going to re-write Sam's C++ example all in the header but then figured he probably knows that already and I would have basically done it to be a smart aleck anyway.

No doubt about includes.

> I still have a much better time reading C++ than C#, Java, or most other languages

That's interesting Mene. Glad you find it easier to read. I'm not really sure how it is any easier to read than, say, C#, but if you find it that way, then great. Keep at it.

BTW, as much as I feel I am a dinosaur knowing C++, that knowledge has been one of the deciding factors in me getting my last four jobs. C++ developers are becoming harder and harder to find...or those who know it, don't want to continue in it. C# and the .NET API are by far, my favored choice though.
My quote: Have I mentioned I love C# and the iPad?
Another quote: Have I mentioned I love the iPad?
User avatar
samw3
Site Admin
Posts: 1239
Joined: Sun Dec 16, 2007 2:00 pm
Location: Toccoa, GA
Contact:

Re: Liking C++ discussion

Postby samw3 » Tue Nov 24, 2009 3:13 pm

vibrokatana wrote:The C++ one will also be 2-5x faster and use 10x less memory. Oh and BTW you can write a class and define the functions at the same time. It isn't recommended because it will make the compiler cry with large projects.
Just to be clear, I'm not advocating Java over C++ in terms of it's efficiency, just merely stating that Java syntax is clearer and more cohesive.

And if the C consortium, or whatever it's called would start making some decisions and implementation we wouldn't have to wrestle with this dinosaur. C++ is just.. old.

Who is online

Users browsing this forum: No registered users and 7 guests

cron