Be a Supporter!

C++ Pawns all other Languages

  • 6,389 Views
  • 131 Replies
New Topic Respond to this Topic
doodle-bread14
doodle-bread14
  • Member since: Jul. 25, 2012
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages 2012-08-04 15:33:37 Reply

At 8/4/12 01:13 PM, egg82 wrote: Thank Diki for pretty much all of the answers O.o

Diki is the best user on this forum.

It seems that learning C++ and Java at the same time may be a bit of an overload by themselves.

C++ and Java isn't a wise combination.


At least not a muffin.

BBS Signature
DjViking
DjViking
  • Member since: Apr. 21, 2009
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ Pawns all other Languages 2012-09-15 08:05:14 Reply

This thread is silly,.. OP is silly,
I'm a C++ programmer, been doing it for about 2 years, Still have a lot to learn, C++ was my first and only language, all self taught.

Here's an example of my cope to show my competence

void Load_MapDIR(int& counter = howmanymaps)
{
counter = 1;
std::string buffer;
std::string buffer2;
WIN32_FIND_DATA myimage;
HANDLE myHandle=FindFirstFile("maps\\*.*",&myimage);

if(myHandle!=INVALID_HANDLE_VALUE)
{
       FindNextFile(myHandle,&myimage);
       while(FindNextFile(myHandle,&myimage))
       {
                     buffer = myimage.cFileName;
                     ::buffer = buffer.substr((buffer.size()-3),3);
                    if (::buffer == "map")
                    {
                        ::buffer = buffer;
                        ::buffer.resize(buffer.length() - 4);
                        mapsindir[counter] = ::buffer;
                        ++counter;
                    }
              }
       }
}

it's a function that reads all the names of the files in a directory, then save the names minus the 3 letter extension into an array.
I know I probably shouldn't have named 2 different variables the same thing, but I wanted to try actually using the scope resolution operator in a function,

DjViking
DjViking
  • Member since: Apr. 21, 2009
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ Pawns all other Languages 2012-09-15 08:08:12 Reply

I totally forgot to mention what I had to say, lol.

so, yeah C++ is pretty boss, but I plan on learning Java and PHP as well.
I forgot about alchemy, I have a few C++ games I made that I guess I can transfer over to flash.

I enjoyed reading this thread, and I believe OP to be a 13 year old, 14 tops.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages 2012-09-15 10:20:44 Reply

At 9/15/12 08:05 AM, DjViking wrote: it's a function that reads all the names of the files in a directory, then save the names minus the 3 letter extension into an array.

You might want to change that. Not all file extensions are 3 characters long (and some files don't have any extensions).
Also, I highly recommend using the Boost Filesystem library for managing file I/O.

Why's your counter variable a reference though? Wouldn't it make more sense to copy the int by value instead?

DjViking
DjViking
  • Member since: Apr. 21, 2009
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ Pawns all other Languages 2012-09-15 18:17:05 Reply

At 9/15/12 10:20 AM, Diki wrote:
At 9/15/12 08:05 AM, DjViking wrote: it's a function that reads all the names of the files in a directory, then save the names minus the 3 letter extension into an array.
You might want to change that. Not all file extensions are 3 characters long (and some files don't have any extensions).
Also, I highly recommend using the Boost Filesystem library for managing file I/O.

Why's your counter variable a reference though? Wouldn't it make more sense to copy the int by value instead?

No, because it's a global variable that is used in other functions, and if I were to copy it by value, I wouldn't have a number representing how many files are in the directory that could be used elsewhere in the program.

and I know now all file extensions are 3 characters, it's just it only loads files that it makes, if there is a file in that folder that wasn't made by that program it won't show up in the list.

and yeah, I knew about boost library, but I'm too busy atm to learn it.

DefiledNH
DefiledNH
  • Member since: Sep. 20, 2012
  • Offline.
Forum Stats
Member
Level 03
Programmer
Response to C++ Pawns all other Languages 2012-09-26 01:22:17 Reply

Well, not really. C++ does have it's advantages, but I don't see how it's the best? JAVA seems a fair competitor, being object-oriented rather than functions-oriented. You can't just say "This language is the best". There's no viable reason as to why C is the "best". Most efficient? Maybe. Easiest? Not really :S

everette00
everette00
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages 2012-09-26 16:13:34 Reply

At 9/26/12 01:22 AM, DefiledNH wrote: Well, not really. C++ does have it's advantages, but I don't see how it's the best? JAVA seems a fair competitor, being object-oriented rather than functions-oriented. You can't just say "This language is the best". There's no viable reason as to why C is the "best". Most efficient? Maybe. Easiest? Not really :S

I just come back to see where this thread is going, but I don't really respond anymore. However, this post interested me quite a bit.

You're right that C++ isn't the best - other languages were built to address issues that C++ has. Java is one of those languages. The part the specifically interested me was how to label C++ as "functions-oriented" and Java as "object-oriented". I'd like to know why you say that, particularly because both C++ and Java use classes and subroutines in the same way. Both languages are OOP, and are C-based. The differences are both syntactical and environmental.

Here is an example of the differences between the two languages when it comes to using both classes and subroutines.

C++:

#include<stdio.h>
    class Player
    {
        public:
            int health = 50;
            int def = 2;
  
        public:
            Player(int, int);
            ~Player();   
    };

    int Player::Player(int Health, int Defense)
    {
        health = Health;
        def = Defense;
    }

    int main(int argv, const char *argc[])
    {
        Player playerOne(100, 6);
        cout << playerOne.health << endl;
    }

Java:

//All of the namespaces you need to do what ever in a simple Java application goes HERE.
    public class Player{
        public int health = 50;
        public int defense = 2;
        
        public Player(int Health, int Defense){
             this.health = Health;
             this.defense = Defense;
        }    
    }

    public static void Main(String[] args){
        Player playerOne = new Player(600, 3);
        System.out.println(playerOne.health.toString());
    }

As you can see, there are quite a bit of differences between the two language's syntax, but they both work with classes and subroutines pretty identically - thus, they are both structured similarly. The point I'm making here is they're both object-oriented programming languages and don't follow two separate paradigms.

I'd also like to say that I'm not a C++ developer, so any unsafe code should be overlooked as they're examples of the differences of C++ and Java - not real-world samples of code that one may or may not use, or should or should not use.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages 2012-09-26 18:33:14 Reply

Technically he is correct in calling C++ a functional programming language as C++ is multi-paradigm, and that is one of them. However most C++ I see is object-oriented though my perspective is probably biased.

At 9/26/12 04:13 PM, everette00 wrote: I'd also like to say that I'm not a C++ developer, so any unsafe code should be overlooked as they're examples of the differences of C++ and Java - not real-world samples of code that one may or may not use, or should or should not use.

Your C++ code isn't unsafe, but it won't compile. :)
There might be someone reading this who is interested as to why it won't compile, so here's a list of the issues:

#include <stdio.h>

Nothing wrong with this (though it is a C header, but will still work) but this does not include the cout/endl members; those are in the <iostream> header.

int health = 50;
int def = 2;

C++ doesn't allow you to do that. Only const members can be assigned a value within the class block.

~Player();

This destructor was declared but not defined, so it will throw an unresolved external error.

int Player::Player(int Health, int Defense)

I'm guessing that typing int there was just a typo, but anyways: constructors cannot have a return type.

cout << playerOne.health << endl;

There was no using namespace std or using std::cout/using std::endl so even if the <iostream> this would still produce errors (the compiler wouldn't know what cout/endl are).

Here's a rewritten version that will compile no problem:

#include <iostream>

using std::cout;
using std::endl;

class Player
{
	public:
		int health;
		int def;

	public:
		Player(int, int);
		~Player();   
};

Player::Player(int health, int defense)
    : health(health),
      def(defense)
{
	/* I like hotdogs */
}

Player::~Player()
{
	/* I like pizza too! */
}

int main(int argv, const char *argc[])
{
	Player playerOne(100, 6);
	cout << playerOne.health << endl;
}

Again, don't take this post the wrong way; not belittling you or anything, just offering an explanation as to why that will produce compiler errors.
Cheers. :)

everette00
everette00
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages 2012-09-27 08:14:48 Reply

At 9/26/12 06:33 PM, Diki wrote:

:...

Whoa, big facepalm on my behalf. LOL, that was some pretty shitty code. That's what I get with four hours of sleep, work and school and drama going on in my life. Sorry about that, folks. I swear, I don't write code that shitty IRL. And to you, Diki, I'm sorry too. You fixed my crap.

DefiledNH
DefiledNH
  • Member since: Sep. 20, 2012
  • Offline.
Forum Stats
Member
Level 03
Programmer
Response to C++ Pawns all other Languages 2012-09-30 03:10:08 Reply

At 9/26/12 04:13 PM, everette00 wrote: You're right that C++ isn't the best - other languages were built to address issues that C++ has. Java is one of those languages. The part the specifically interested me was how to label C++ as "functions-oriented" and Java as "object-oriented". I'd like to know why you say that, particularly because both C++ and Java use classes and subroutines in the same way. Both languages are OOP, and are C-based. The differences are both syntactical and environmental.

As you can see, there are quite a bit of differences between the two language's syntax, but they both work with classes and subroutines pretty identically - thus, they are both structured similarly. The point I'm making here is they're both object-oriented programming languages and don't follow two separate paradigms.

Ah, I see. My apologies, in theory [at school] we learnt C is function-oriented and java is object-oriented. Excuse my lapse, I'm not exactly an expert in the programming field, very novice in fact.

DjViking
DjViking
  • Member since: Apr. 21, 2009
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ Pawns all other Languages 2012-10-01 02:06:25 Reply

C != C++

Grr, it won't let me post a super short reply like that, so I had to add this dumb text here.