Be a Supporter!

C++ Pawns all other Languages

  • 6,032 Views
  • 130 Replies
New Topic Respond to this Topic
VigilanteNighthawk
VigilanteNighthawk
  • Member since: Feb. 13, 2003
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to C++ Pawns all other Languages Jun. 26th, 2012 @ 04:25 PM Reply

Ah, I could just see it now:
Client: But that Ruby developer said he could develop my website for a 1/4 of the cost and in a 1/4 of the time.
apocalypseven: cuz C++ is teh best, and that Ruby develop is teh newbz.
Client: Why is it the best?
apocalypseven: bcuz tehy use it for video games because it's super fast!!!!!!!! and only super 1337 coderz likz me can user it!!!!
Client: Then why will it take it so much longer and so much more money to build my site?
apocalypseven: cuz Ruby coderz are gay. tehy likz other menz!!!!111!!!!
Client: Well, I don't care what they do in the privacy of their own bedrooms. I just want a website, and besides, that doesn't even answer my question.
apocalypseven: -.- ????????

(real answer: Because it lacks facilities built into Ruby like memory management, and there is not as much support in the form of libraries and frameworks for web development that other languages have. )

Client: I think I'm going to hire someone else. Thank you for your time.
apocalypseven: FAG!!!!! bowz to mi gr8tness!!!111!!1111!!!!!
Client: Leave now, before I call the police.

At 6/26/12 12:27 PM, apocalypseven wrote:
At 6/26/12 09:01 AM, Diki wrote: hello!
C# is garbage.

And you fuck goats.

I don't really care about you or your ill informed opinions, but I figured I'd humor you by bringing this down to your level.

The Internet is like a screwdriver. You can use it to take an engine apart and understand it, or you can see how far you can stick it in your ear until you hit resistance.

apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 26th, 2012 @ 05:45 PM Reply

At 6/26/12 04:25 PM, VigilanteNighthawk wrote: Ah, I could just see it now:

10/10


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
TapSkill
TapSkill
  • Member since: Aug. 21, 2011
  • Offline.
Forum Stats
Member
Level 04
Gamer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 03:54 AM Reply

At 6/11/12 10:33 PM, apocalypseven wrote: You can code anything in C++, even websites, websites are purposely coded in half ass languages to make them slow to keep you hooked on the websites and keep you coming back.

Websites are typically not programmed at all. The interactive sites use a server-friendly language, like PHP or Python. PHP is very similar to C++, but it is used more for server side programming. Python is used for both use cases, and it is not much slower than PHP. C++ is typically much faster because it enforces exact programming rather than quick and messy code.

Now, as for your other theory of why websites use these languages, they are not used to make pages load more slowly. They load slow due to bandwidth. C++ is not an efficient web development language, because you would have to build your code directly into the host server rather than have the server run your code. Basically, you would have to code your own server. That that point, I would question whether you still use MySQL or write your own database server from scratch.

TapSkill
TapSkill
  • Member since: Aug. 21, 2011
  • Offline.
Forum Stats
Member
Level 04
Gamer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 03:59 AM Reply

At 6/26/12 12:27 PM, apocalypseven wrote:
At 6/26/12 09:01 AM, Diki wrote: hello!
C# is garbage.

C# is a great language, but the .NET Framework is not open source, so C# loses points for that. Unity uses C# but also uses an open source alternative to .NET Framework called Mono. C# is better than C++ for the programmer's sanity but worse than C++ for the performance of the created application. Efficiency is a two-way street. You can be an efficient programmer and use a faster, easier development tool, or you can be the less efficient programmer and churn out faster applications that require less processing power.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 09:23 AM Reply

At 6/27/12 03:54 AM, TapSkill wrote: Websites are typically not programmed at all. The interactive sites use a server-friendly language, like PHP or Python.

Which are programming languages.
Websites are very much programmed; that's what developers do for a living, and is precisely what I do for a living.

At 6/27/12 03:54 AM, TapSkill wrote: PHP is very similar to C++, but it is used more for server side programming.

PHP is a C-like language, but it is nothing like C++.
The very notion of that is absurd.

Do you even know C++?

At 6/27/12 03:54 AM, TapSkill wrote: Python is used for both use cases, and it is not much slower than PHP.

Python is a lot faster than PHP.
Sources here, here, and here,

At 6/27/12 03:54 AM, TapSkill wrote: C++ is typically much faster because it enforces exact programming rather than quick and messy code.

A programming language's execution speed is not determine by its allowed paradigms.
C++ is faster because it is a compiled, low level, highly optimised, language.

And what does "exact programming" even supposed to mean?

At 6/27/12 03:54 AM, TapSkill wrote: Now, as for your other theory of why websites use these languages, they are not used to make pages load more slowly. They load slow due to bandwidth.

Most websites load slowly due to being poorly programmed and making redundant requests to uncompressed media assets, most typically images.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 09:27 AM Reply

At 6/27/12 03:59 AM, TapSkill wrote: C# is better than C++ for the programmer's sanity

Had to double-post to respond to this, because you are missing one of the very fundamental concepts of programming: choosing the right tools for the right job.
Languages are not better than others (poorly developed languages such as PHP excluded). Languages are better at certain tasks than other languages.

Yes, C# is a much better choice for a GUI-based application. GUI programming in C++ is a nightmare.
However, what if you wanted to make your own simple scripting language? C++ would make far more sense to use than C#.

Basically: don't just blindly choose a language because "it's better"; choose the right tool for the right job.

everette00
everette00
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 11:08 AM Reply

At 6/27/12 09:27 AM, Diki wrote: ...
Basically: don't just blindly choose a language because "it's better"; choose the right tool for the right job.

See, this is what makes you a good dude on these forums. Spreading the word of truth!

liljim
liljim
  • Member since: Dec. 16, 1999
  • Offline.
Forum Stats
Staff
Level 28
Blank Slate
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 12:45 PM Reply

At 6/27/12 09:23 AM, Diki wrote:
At 6/27/12 03:54 AM, TapSkill wrote: Websites are typically not programmed at all. The interactive sites use a server-friendly language, like PHP or Python.
Which are programming languages.

Okay.

At 6/27/12 03:54 AM, TapSkill wrote: Python is used for both use cases, and it is not much slower than PHP.
Python is a lot faster than PHP.
Sources here, here, and here,

So why are you talking about websites and then linking to benchmarks that are based on the cli version of PHP (that's run on the console), rather than its web modules like mod_php? The outcome of those benchmarks might or might not be similar, but please don't start comparing chalk with cheese, because cli and the web modules are two very different animals.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 01:02 PM Reply

At 6/27/12 12:45 PM, liljim wrote: So why are you talking about websites and then linking to benchmarks that are based on the cli version of PHP (that's run on the console), rather than its web modules like mod_php? The outcome of those benchmarks might or might not be similar, but please don't start comparing chalk with cheese, because cli and the web modules are two very different animals.

This is one giant strawman argument, but I'll still respond in a rather lethargic fashion.
The claim "PHP is faster than Python" was made.
Evidence contradicting claim provided.
Claim is false QED.

If you wish to extrapolate his claim to "PHP running via Apache is faster than Python using Django/Flask/Pyramid/Some custom crap" go for it I guess?

P.S.
I do know exactly what you're saying, it's just irrelevant to my point, which is that Python is faster than PHP.
Does PHP become faster after web shit is tacked on? I doubt it but don't have evidence for that, but if you do, by all means share it.

liljim
liljim
  • Member since: Dec. 16, 1999
  • Offline.
Forum Stats
Staff
Level 28
Blank Slate
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 01:14 PM Reply

At 6/27/12 01:02 PM, Diki wrote: I do know exactly what you're saying, it's just irrelevant to my point, which is that Python is faster than PHP.

You've provided evidence of that on a CLI basis, but not to the contrary when it comes to its use on the web. And THAT was my only point. I'm not leaping to the defence of PHP, but it's important that OTHER people understand the difference between the environments, even if it's something YOU already know.

Does PHP become faster after web shit is tacked on?

No idea.

I doubt it but don't have evidence for that

Then that's really just jumping to conclusions, isn't it?

I honestly don't understand what you stand to gain by complaining about one language or the other, or why you spend so much time doing so. Do you really think that's going to have any effect on anything? Many languages have bizarre quirks, but you work with what you have and deal with what you're dealing with and move on.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 01:41 PM Reply

At 6/27/12 01:14 PM, liljim wrote: You've provided evidence of that on a CLI basis, but not to the contrary when it comes to its use on the web. And THAT was my only point.

Fair enough.
Although I'd be pretty damn surprised if the speed difference didn't remain consistent even when in a web-based context.

At 6/27/12 01:14 PM, liljim wrote: I'm not leaping to the defence of PHP, but it's important that OTHER people understand the difference between the environments, even if it's something YOU already know.

This is actually a good point that I didn't really consider.

At 6/27/12 01:14 PM, liljim wrote: Then that's really just jumping to conclusions, isn't it?

I never concluded that Python is faster than PHP in a web-based context. I just seriously doubt that.

At 6/27/12 01:14 PM, liljim wrote: I honestly don't understand what you stand to gain by complaining about one language or the other, or why you spend so much time doing so.

I like ripping on PHP; it's fun and easy, and sometimes I convince people to try Python.

At 6/27/12 01:14 PM, liljim wrote: Do you really think that's going to have any effect on anything?

Nope.

SeeD419
SeeD419
  • Member since: Mar. 24, 2003
  • Offline.
Forum Stats
Member
Level 27
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 03:01 PM Reply

At 6/27/12 01:14 PM, liljim wrote: I honestly don't understand what you stand to gain by complaining about one language or the other, or why you spend so much time doing so. Do you really think that's going to have any effect on anything? Many languages have bizarre quirks, but you work with what you have and deal with what you're dealing with and move on.

Diki was just sharing actual benchmarks he's read.

If anyone is spending too much time mindlessly complaining about one language over another it's OP


Minecraft server: proxa.co
PortalWatch 0.1 Alpha - Download
Sig by illicit

BBS Signature
apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 03:26 PM Reply

At 6/27/12 03:01 PM, SeeD419 wrote:
If anyone is spending too much time mindlessly complaining about one language over another it's OP

I'm not complaining, I just don't see the point of using the other ones.


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 04:36 PM Reply

At 6/27/12 03:26 PM, apocalypseven wrote: I'm not complaining, I just don't see the point of using the other ones.

I just thought about what would happen if you actually tried to write C++, since I'd be willing to bet you don't even know it, and that made me smile.

apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 06:34 PM Reply

At 6/27/12 04:36 PM, Diki wrote:
I just thought about what would happen if you actually tried to write C++, since I'd be willing to bet you don't even know it, and that made me smile.

I have been writing you twat, I am still learning, its a very articulate language.


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
VigilanteNighthawk
VigilanteNighthawk
  • Member since: Feb. 13, 2003
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 06:44 PM Reply

At 6/27/12 06:34 PM, apocalypseven wrote:
At 6/27/12 04:36 PM, Diki wrote:
I just thought about what would happen if you actually tried to write C++, since I'd be willing to bet you don't even know it, and that made me smile.
I have been writing you twat, I am still learning, its a very articulate language.

Then post an example and explain it and allow the rest of us to ask questions.


The Internet is like a screwdriver. You can use it to take an engine apart and understand it, or you can see how far you can stick it in your ear until you hit resistance.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 07:17 PM Reply

At 6/27/12 06:34 PM, apocalypseven wrote: I have been writing you twat, I am still learning, its a very articulate language.

What precisely about it is articulate?
What have you made using its templating system?
What practical uses have you found for pointers?
What do you think about C++11?
What frameworks have you worked with?
What IDE do you primarily use? What compiler?
What platform do you develop for (i.e. 32bit or 64bit) and why?
What method do you prefer to including external libraries into your applications?
What practical uses have you found for the pre-processor?

Feel free to answer any of those.
Let's see why you love C++ so much.

apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 07:53 PM Reply

At 6/27/12 07:17 PM, Diki wrote:
What precisely about it is articulate?

It uses numbers more than letters thus making it more accurate.

What have you made using its templating system?

Penis

What practical uses have you found for pointers?

Pointers are for homos.

What do you think about C++11?

no comment

What frameworks have you worked with?

Frameworks are not necessary.

What IDE do you primarily use? What compiler?

Any.

What platform do you develop for (i.e. 32bit or 64bit) and why?

64 bit, I don't why

What method do you prefer to including external libraries into your applications?

There is no method, your over thinking, you just include them anyway you can.

What practical uses have you found for the pre-processor?

I don't know what that is.


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 07:57 PM Reply

At 6/27/12 07:53 PM, apocalypseven wrote: There is no method, your over thinking, you just include them anyway you can.

I like how this is the only serious answer and it's false.
There is more than one way bub.

Here's one:

#pragma comment(lib, "myLibrary.lib")

I don't expect you to know any others.
Like I said, you don't actually know C++.

apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 08:03 PM Reply

At 6/27/12 07:57 PM, Diki wrote:
I don't expect you to know any others.
Like I said, you don't actually know C++.

Your coding is jacked.

I will not show my code, I will never source it, I will never share it with anyone.


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 08:16 PM Reply

What is jacked coding? Does that mean it's really buff like Jack Lalanne?
Or like it's raised up off the ground like a jacked up car?

I don't want my code to be too buff or high off the ground. tia

VigilanteNighthawk
VigilanteNighthawk
  • Member since: Feb. 13, 2003
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 08:17 PM Reply

At 6/27/12 08:03 PM, apocalypseven wrote:
At 6/27/12 07:57 PM, Diki wrote:
I don't expect you to know any others.
Like I said, you don't actually know C++.
Your coding is jacked.

I will not show my code, I will never source it, I will never share it with anyone.

Oh come on now. It doesn't have to be anything special. It could be a sorting algorithm or data structure. There is hardly any need for you to show any of your super special awesome secret patented code to us. ;)


The Internet is like a screwdriver. You can use it to take an engine apart and understand it, or you can see how far you can stick it in your ear until you hit resistance.

apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 08:25 PM Reply

At 6/27/12 08:16 PM, Diki wrote: What is jacked coding?

It means its inconsistent.

At 6/27/12 08:17 PM, VigilanteNighthawk wrote:
Oh come on now. It doesn't have to be anything special. It could be a sorting algorithm or data structure. There is hardly any need for you to show any of your super special awesome secret patented code to us. ;)

Sorry, I can't show you one character, you can scoff all you want, but you know da gamez are coming!

Super 1337 coderz fo life.


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
VigilanteNighthawk
VigilanteNighthawk
  • Member since: Feb. 13, 2003
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 08:28 PM Reply

At 6/27/12 08:25 PM, apocalypseven wrote:
At 6/27/12 08:16 PM, Diki wrote:

Sorry, I can't show you one character, you can scoff all you want, but you know da gamez are coming!

Super 1337 coderz fo life.

Yes, the avoider game that you copy and pasted will be coming, but of course, it will be written in ACTIONSCRIPT. Well, thanks for the laugh.


The Internet is like a screwdriver. You can use it to take an engine apart and understand it, or you can see how far you can stick it in your ear until you hit resistance.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 08:28 PM Reply

At 6/27/12 08:25 PM, apocalypseven wrote: It means its inconsistent.

A single pre-processor (that thing you don't know about) command is inconsistent you say?
I'm curious. Inconsistent with what?

apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 08:37 PM Reply

At 6/27/12 08:28 PM, Diki wrote:
A single pre-processor (that thing you don't know about) command is inconsistent you say?

I don't give a fuck if its divorced, your code was fucked.

I'm curious. Inconsistent with what?

Coding is not a game, "Hey, look at me, I made a code!" It has to be extremely accurate and triple checked, or you program is a pile of dog shit.

1337


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 08:47 PM Reply

Help guys my C++ code is jacked and fucked oh god what do I do:

#define JACK int main()
#define FUCK return
#define PISS 0

JACK {
	FUCK PISS;
}
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 09:25 PM Reply

At 6/27/12 07:17 PM, Diki wrote:
At 6/27/12 06:34 PM, apocalypseven wrote: I have been writing you twat, I am still learning, its a very articulate language.
What precisely about it is articulate?
What have you made using its templating system?
What practical uses have you found for pointers?
What do you think about C++11?
What frameworks have you worked with?
What IDE do you primarily use? What compiler?
What platform do you develop for (i.e. 32bit or 64bit) and why?
What method do you prefer to including external libraries into your applications?
What practical uses have you found for the pre-processor?

Feel free to answer any of those.
Let's see why you love C++ so much.

I've just started learning C++, but if I may give it a shot (correct me if i'm wrong on any of these):

I don't know if "articulate" is the right word - lightweight, certainly; and maybe practical.
Hmm... I've never heard of that.
I don't know if you count this as "practical", but I use pointers when referencing any variable, since C++ only sends a copy of the variables passed to a function rather than the memory address of the variable itself. I know it's probably a horrid way of doing it, but sadly it's the only way I know how as of yet.
Again, never heard of it.
None.
NetBeans or Code::Blocks with MinGW (though i've tried Cygwin)
32-bit, as it gets a wider target audience (some people still use 32-bit systems like Windows XP)
I use #include with a namespace - again, this is the only way I know how.
None yet, but i've only just started actually looking at pre-processing.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 10:00 PM Reply

This is a pretty long ass post, so bear with me.

At 6/27/12 09:25 PM, egg82 wrote: I don't know if "articulate" is the right word - lightweight, certainly; and maybe practical.

Oh yeah it's not the right word at all; it doesn't make any sense.
Other than him trolling I don't know why he would use it to describe a programming language.

At 6/27/12 09:25 PM, egg82 wrote: Hmm... I've never heard of that.

Templates are incredibly useful.
Here's a pretty basic example of using them:

#include <iostream>

// Create a Pair class
// Will allow you to store any two values of any type
template <class Ty1, class Ty2>
class Pair
{
public:
	typedef Ty1 first_type;
	typedef Ty2 second_type;
	
	first_type first;
	second_type second;
	
	Pair(Ty1, Ty2);
};

// Pair constructor
template <class Ty1, class Ty2>
Pair<Ty1, Ty2>::Pair(Ty1 f, Ty2 s)
: first(f), second(s)
{}

// Function for making pairs
// This is easier then doing Pair<int, float>(42, 3.14f)
template <class Ty1, class Ty2>
Pair<Ty1, Ty2> make_pair(Ty1 f, Ty2 s)
{
	return Pair<Ty1, Ty2>(f, s);
}

// main
int main()
{
	Pair<int, float> foo = make_pair(42, 3.14f);

	std::cout << "First: " << foo.first << std::endl;
	std::cout << "Second: " << foo.second << std::endl;

	return 0;
}

Source on Ideone: http://ideone.com/5NViv

This is a rudimentary implementation of the pair container found in the STL.
Templates are kind of like the * type in AS3 on steroids.

If you're new to C++ then I wouldn't recommend trying to learn them just yet.
Once you get pretty comfortable with C++ then dive into them and fall in love.

At 6/27/12 09:25 PM, egg82 wrote: I don't know if you count this as "practical", but I use pointers when referencing any variable, since C++ only sends a copy of the variables passed to a function rather than the memory address of the variable itself. I know it's probably a horrid way of doing it, but sadly it's the only way I know how as of yet.

If you just need to reference a variable then you should use a reference instead:

void changeFoo(int& val)
{
	val = 1234;
}

int main()
{
	int foo = 42; // Make some foo
	changeFoo(foo); // foo now equals "1234"
	
	return 0;
}

Generally speaking, if you're not sure if you need to use a pointer or not, you probably don't and can use a reference instead.
However, if for example, the value that you're referencing could be NULL for some reason then you should use a pointer.

Pointers are incredibly complicated and far outside the scope of this post.

At 6/27/12 09:25 PM, egg82 wrote: Again, never heard of it.

It's the newest version of C++.
You can read about the new features that it adds here.

Personally I haven't had a chance to work with it yet, but I really like the auto type and uniformed initialisers. They look handy dandy.

At 6/27/12 09:25 PM, egg82 wrote: I use #include with a namespace - again, this is the only way I know how.

That's for including header files, which may themselves include libraries (though probably not, though still it depends, who knows?).
Libraries are .LIB files are static libraries compiled through your IDE that allows you to re-use your code (i.e. the code in the .CPP files) efficiently.

If you're just starting out with C++ then I wouldn't worry about this.

At 6/27/12 09:25 PM, egg82 wrote: None yet, but i've only just started actually looking at pre-processing.

The pre-processor allows you to define values and such that are inserted into your code prior to being compiled.
Example:

#define THE_ANSWER 42

int main()
{
	return THE_ANSWER;
}

You can define anything, and I mean anything:

#define MAIN int main()
#define BRACKET_OPEN {
#define BRACKET_CLOSE }
#define RETURN_KEYWORD return
#define ZERO 0
#define SEMI_COLON ;

MAIN BRACKET_OPEN RETURN_KEYWORD ZERO SEMI_COLON BRACKET_CLOSE

That will compile successfully, but don't ever do it. :)
As for a practical example of the pre-processor:

Getting the length of an array
An array does not contain any length property or anything remotely approaching one.
In fact it contains no properties at all!

So if you wanted to get the length of an array, and you know for a fact the value is an array, you could do this:

#include <iostream>
#define ARRAY_LENGTH(myArray) (sizeof(myArray)/sizeof(myArray[0]))

int main()
{
	int foo[10];
	
	std::cout << ARRAY_LENGTH(foo) << std::endl;
	
	return 0;
}

Note: This code is not type-safe, so passing something that isn't an array could cause your program to not compile.

Ensure class is only defined once
Once you start working with many, many classes you sometimes need to include one class more than once.
So you need to ensure it is only ever declared once, or your program will not compile.

Pre-processor to the rescue:

#ifndef _MY_BITCHIN_CLASS_
#define _MY_BITCHIN_CLASS_

class MyBitchinClass
{
	// ...
};

#endif

Those are just two example of the pre-processor.
It can do a helluva a lot things.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 10:55 PM Reply

At 6/27/12 10:00 PM, Diki wrote: This is a pretty long ass post, so bear with me.

okay. I've read the whole thing twice, with parts at count five+ times.

Templates are incredibly useful.
Here's a pretty basic example of using them:

this interested me. I had one hell of a time making it all out (with my limited C++ dictionary), but I think I can convert it to pseudocode. I think.

create a new template with classes Ty1 and Ty2
class Pair - public:
class Ty1 as first_type
class Ty2 as second_type
?? first ??
?? second ??
run function Pair(Ty1, Ty2)

(the pair constructor seems redundant, as it's pretty much the code above)

function Pair(Ty1, Ty2):
returns pair from template plus pair from constructor

main is self-explanatory

Though I wonder: is there any real benefit in not using the namespace? It seems like using std::cout would be a pain after a while. Why not namespace it so all you have to type is cout?

If you just need to reference a variable then you should use a reference instead:

int&? That's odd. I remember something about the ampersand, but I can't quite recall it.

Anyway, I didn't realize that you can pass by reference by... Well... Using a reference. All i've heard about was pointers and passing by value. Believe me, i've heard a lot about pointers. I literally used half a day learning about them via video tutorial. Was probably the longest section in the series.

Generally speaking, if you're not sure if you need to use a pointer or not, you probably don't and can use a reference instead.

good point (badum)

It's the newest version of C++.
You can read about the new features that it adds here.
Personally I haven't had a chance to work with it yet, but I really like the auto type and uniformed initialisers. They look handy dandy.

auto type - that sounds like it would be useful (just judging by the words "auto" and "type")

That's for including header files, which may themselves include libraries (though probably not, though still it depends, who knows?).
Libraries are .LIB files are static libraries compiled through your IDE that allows you to re-use your code (i.e. the code in the .CPP files) efficiently.

ah, whoops. You're right, I know nothing of .lib or .dll files :P

You can define anything, and I mean anything:

#define MAIN int main()
#define BRACKET_OPEN {
#define BRACKET_CLOSE }
#define RETURN_KEYWORD return
#define ZERO 0
#define SEMI_COLON ;

MAIN BRACKET_OPEN RETURN_KEYWORD ZERO SEMI_COLON BRACKET_CLOSE

I laughed so hard at that, and I have no idea why. Perhaps it was just the raw power of C++ that was silly? Or maybe the fact that the example was just weird. Hell, it may be both. Imagine programming like that o.o

In fact it contains no properties at all!

That's... Somewhat hard to imagine. What about sizeof? It seems that it's pulling SOMETHING from the array.

#define ARRAY_LENGTH(myArray) (sizeof(myArray)/sizeof(myArray[0]))

Yikes. What if the array is empty? You'd be dividing by zero o.o
Why do you even need to divide, anyway? It'd seem that sizeof() would get the size of the array object, would it not?

Ensure class is only defined once
Once you start working with many, many classes you sometimes need to include one class more than once.
So you need to ensure it is only ever declared once, or your program will not compile.

Pre-processor to the rescue:

I would assume that #ifndef and #endif means something to the C++ compiler, I just have no idea what.

Well, that explains a lot, as well as how much more there is to learn. I think i'll move on to the more advanced AS3 things and then call the language "learned" - after that I may take another shot or two at C++ before I learn ASP.NET and attempt to get it to work with CentOS


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature