We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
  • Pages:
  • 1
  • 2
C/C++ Discussion
Topic Started: Sep 17 2008, 09:05 PM (2,067 Views)
Fission
Member Avatar
Uguu
[ *  *  *  *  * ]
C++ has a few extra features and minor differences from C, but syntactically they are the same. Also, Python is not better than C (in sheer speed and ability) and the person who said so should be beaten with a heavy club of some kind.
Offline Profile Quote Post Goto Top
 
FinalKiller0
Member Avatar
OVER 1,000!!
[ *  *  *  *  * ]
Dyegov
Sep 20 2008, 11:01 PM
Argh, I don't even know what to learn. I want to learn a programming language. Someone recommended Python to me; he said it was way easier that all other languages sucked, including java and C,C++. How are C/C++ better than Python? What's the difference between C and C++? Which one is better? :-/
C++ & related are the most powerful of them all.
Java is not as powerful.
Pyton is in between.

It all depends on what you want to do and which one(s) you like to work with better. So far, by computer science teacher is boasting about how awesome Pyton is as he teaches his comp sci seminar class.
Offline Profile Quote Post Goto Top
 
Fission
Member Avatar
Uguu
[ *  *  *  *  * ]
Actually, you'd be surprised how powerful Java is. One of a few major flaws is that its runtime environment is a bit heavy on computer resources.
Offline Profile Quote Post Goto Top
 
FinalKiller0
Member Avatar
OVER 1,000!!
[ *  *  *  *  * ]
Well, I dunno how powerful anything is as C++ is only my second language, and the fisrt one I learned was a beginner's language.

That list is according to my comp sci teacher.
Offline Profile Quote Post Goto Top
 
Fission
Member Avatar
Uguu
[ *  *  *  *  * ]
Anyway...

Has anyone here ever experimented with integrating Lua scripting (or any scripting, for that matter) into a program?
Offline Profile Quote Post Goto Top
 
Dyegov
Member Avatar
D . r . e . a . m . i . n . g
[ *  *  *  *  *  * ]
So you suggest I learn C++ instead of Python since it's better? That person said that one of the advantages of Python was that I didn't have to compile it, but I don't even know if that's an advantage... Also, what is a good place to learn C++? (Internet wise, I mean)
Offline Profile Quote Post Goto Top
 
FinalKiller0
Member Avatar
OVER 1,000!!
[ *  *  *  *  * ]
If you are talking to me, all I said was which ones are powerful and which ones are not. A language is better if you think it is better and if it is better for the type of work you are doing. For example: you may use BASIC for programming your calculator, but you won't use it to program the next big video game.

You can't ask me which one is better as I am still learning how to program on my first widely-used language.
Offline Profile Quote Post Goto Top
 
Dyegov
Member Avatar
D . r . e . a . m . i . n . g
[ *  *  *  *  *  * ]
I'm not referring to anyone in particular, since I don't even remember who said to me Python was better (It was actually more than one person in more than one board). I just want to know if C++ is worth it in the long run, and if it's suitable for a beginner (Though I got the basics of variables, if-else statements and all of that long ago).
Offline Profile Quote Post Goto Top
 
Fission
Member Avatar
Uguu
[ *  *  *  *  * ]
C++ is sort of easy to get the hang of if you know the basics of programming. "Hello world" example for C++, with comments:

Code:
 

// preprocessor command
// " " includes from program directory, < > includes from compiler's include directory
#include <iostream> // input/output library
using namespace std; // not required, but should always be used, from my experience

int main(int i, char **c) { // the beginning of main(), the central function for a C program.
// the two parameters are standard with a few libraries, such as SDL, but are not required.

cout << "Hello world!"; // bitshifts "Hello world" to cout, which is a variable that holds the output for a standard C DOS-like window
// prints "Hello world!"

system("pause"); // wait for input before continuing
return 0; // end the program.
}


If you want, I can make a simple tutorial on C++ basics in here, my blog on this board, or through PM.
Offline Profile Quote Post Goto Top
 
Dyegov
Member Avatar
D . r . e . a . m . i . n . g
[ *  *  *  *  *  * ]
Well, that surely looks way more confusing to me than Python. I would appreciate an explanation of the basics, because I don't seem to get it with the comments. It doesn't resemble anything I have seen before :s
Offline Profile Quote Post Goto Top
 
FinalKiller0
Member Avatar
OVER 1,000!!
[ *  *  *  *  * ]
This would Hello World IMO:
Code:
 
#include<iostream.h>

void main(){
cout<<"Hello World.";
}

I used Pascal as my beginning language:
Code:
 
program helloworld;

begin
write('Hello World.');
end.
Offline Profile Quote Post Goto Top
 
mcteeth
Member Avatar
Oh, Comely.
[ *  * ]
"FinalKiller0"
 
This would Hello World IMO:

Take care though: iostream.h has been deprecated since < 1996 and main() returning void is considered harmful. Fission's example is correct, but I disagree that "[using namespace ...] should always be used" because it moves everything into the global namespace. I'm kind of iffy about system("PAUSE") as well...

"Fission"
 
C++ has a few extra features and minor differences from C, but syntactically they are the same.

The differences between C and C++ are actually kinda major when you consider more than syntax and features at face-value. C is renown for its compactness -- it's a very small language, and a lot of people consider it "syntactic sugar for assembly." C++ is pretty large in contrast and has several newer concepts and paradigms. More importantly, the way that you think in C is not the way you should be thinking in C++.

It's important to remember that C++ isn't just "C with classes." Posted Image

"FinalKiller0's teacher?"
 
C++ & related are the most powerful of them all.

I disagree with your teacher. In the article "beating the averages," Paul Graham reasons that power doesn't come from the "brute force" that the language has or from requiring you to work out verbose details, but from the expressiveness of the language. I consider this true for two reasons:

  • There are corner-cases, but for 90% of code you're going to write (that's a conservative guess), speed of development is more important than speed of execution; and
  • expressing thought as code is more important than boilerplate.

You don't have to agree, but it's certainly something to think about. (By the way, everyone should give that article a go. It's a very good read! Posted Image)
Edited by mcteeth, Sep 22 2008, 03:57 PM.
Offline Profile Quote Post Goto Top
 
Fission
Member Avatar
Uguu
[ *  *  *  *  * ]
Well, you could just do:

Code:
 

#include <iostream>

int main (int i,char **c) {

cout << "Hello world!";

return 0;
}


or, if you were really feeling crazy, this:

Code:
 

#include <iostream>
int main(){cout<<"Hello world!";return 0;}


However, in some libraries (most notably SDL) cout, cerr, and cin (standard input and output streams defined in iostream) are redefined. In a non-SDL program written in C/C++, cout and cerr print to the screen (a DOS-like window) and cin gets input (via: cin >> var;) from data written by the user, but in SDL, cout and cerr print to stdout.txt and stderr.txt, while cin obtains values from stdin.txt, though it is rarely used.
Offline Profile Quote Post Goto Top
 
mcteeth
Member Avatar
Oh, Comely.
[ *  * ]
That doesn't compile. Posted Image cout is defined in the std namespace. If you don't want to prepend things with std::, it's safer to use using std::x (where x is what you want to use, eg. cout or cin) rather than the all-encompassing using namespace x. You can even use it inside a function if you want to:

Code:
 
#include <iostream>

int main(int argc, char *argv[])
{
using std::cout;
using std::cin;

cout << "Press < enter > to exit!\n";
cin.get();
return 0;
}
Offline Profile Quote Post Goto Top
 
Fission
Member Avatar
Uguu
[ *  *  *  *  * ]
Fine then:

Code:
 

#include <iostream>
int main(){std::cout<<"Hello world!";std::cin.get();return 0;}


I'd rather just use "using namespace std" as it makes doing that a heck of a lot easier. Then again, I rarely have a need to deal with things like namespaces.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Technology Chat · Next Topic »
Add Reply
  • Pages:
  • 1
  • 2