• C or C++?
    200 replies, posted
[QUOTE=ROBO_DONUT;16494936] Also, I should mention that you can also do "void damage(playerstats &player) { player.hp--; }" in C++ before anyone freaks out about it.[/quote] Actually, in C++, we would do: [code] class playerStats { ... public: void damage() { hp--; } }; [/code] One of the reasons why I hate when C programmers give C++ advice. [quote]Using the ampersand in this context has an entirely different meaning than the usual "address of" operator. In this case, it's a shortcut that allows you to reference a value without treating it as a pointer. (Personally, these little syntactic inconsistencies irk me, but some find them convenient.)[/QUOTE] It's not syntactic sugar, it's a part of the language called "references". References were made to avoid situations where a pointer could end up NULL (there is no such thing as a NULL reference).
[QUOTE=nullsquared;16498283]Actually, in C++, we would do: [code] class playerStats { ... public: void damage() { hp--; } }; [/code] One of the reasons why I hate when C programmers give C++ advice.[/QUOTE] Yes let's completely ignore why he posted that example, give him dumb advice and insult him!
[QUOTE=nullsquared;16498283]-snip-[/QUOTE] He say you CAN do, pointing out references. Don't be an ass.
[QUOTE=nullsquared;16498283]Actually, in C++, we would do: [code] class playerStats { ... public: void damage() { hp--; } }; [/code] One of the reasons why I hate when C programmers give C++ advice.[/QUOTE] The idea was to express equivalent syntax without changing the structure of the code. Classes with methods are an entirely different subject.
[QUOTE=nullsquared;16498283]Actually, in C++, we would do: [code] class playerStats { ... public: void damage() { hp--; } }; [/code] One of the reasons why I hate when C programmers give C++ advice. It's not syntactic sugar, it's a part of the language called "references". References were made to avoid situations where a pointer could end up NULL (there is no such thing as a NULL reference).[/QUOTE] [code] class playerStats { ... public: void damage() { this->hp--; } }; [/code] Fixed it. Assuming hp is a private variable.
And you might as well remove the this->, too.
[QUOTE=Chandler;16503058][code] class playerStats { ... public: void damage() { this->hp--; } }; [/code] Fixed it. Assuming hp is a private variable.[/QUOTE] What part did you fix? hp-- is perfectly valid (and preferred) regardless of whether it's private/public/protected. [editline]04:22PM[/editline] [QUOTE=gparent;16503132]And you might as well remove the this->, too.[/QUOTE] Which gives you my original example :downs:
[QUOTE=nullsquared;16503557]What part did you fix? hp-- is perfectly valid (and preferred) regardless of whether it's private/public/protected. [editline]04:22PM[/editline] Which gives you my original example :downs:[/QUOTE] Think that was his point. I once had multiple instances of one class running. When one of the clases went to decrement a value, for some reason all of them decremented. I was able to rememdy it by using this->
[QUOTE=Chandler;16503598]When one of the clases went to decrement a value, for some reason all of them decremented. I was able to rememdy it by using this->[/QUOTE] You must've had a global variable with the same name as your member. Reason #1 why globals suck.
[QUOTE=nullsquared;16504113]You must've had a global variable with the same name as your member. Reason #1 why globals suck.[/QUOTE] Can't disagree with you there. Such is life when working on a project with other students :-/
[QUOTE=nullsquared;16503557]Which gives you my original example :downs:[/QUOTE] I know, why does it matter? :downs::downs::downs::downs::downs::downs:
:downs::downs::downs::downs::downs::downs:
[QUOTE=gparent;16505483]I know, why does it matter? :downs::downs::downs::downs::downs::downs:[/QUOTE] It matters because I said it first :downs:
there's a whole lot of downs goin' on in this topic.
[QUOTE=nullsquared;16505769]It matters because I said it first :downs:[/QUOTE] No, you didn't, you gave the original example, I told him the this-> was useless. Now just quit crying about it and go fix your serious case of :downs:, because nobody cares that some kid said it before some other guy.
[QUOTE=gparent;16505832]No, you didn't, you gave the original example, I told him the this-> was useless. Now just quit crying about it and go fix your serious case of :downs:, because nobody cares that some kid said it before some other guy.[/QUOTE] You're just jealous I said it first.
The order of facepunch post appearance while I am busy helping our Minister of Labor is of utmost importance. EDIT: And yes, I do realise (or at least hope) that you were sarcastic
[QUOTE=gparent;16506446]The order of facepunch post appearance while I am busy helping our Minister of Labor is of utmost importance.[/QUOTE] Gotta learn to hide your jealousy better :) I mean, it's OK, we all get jealous sometime, but it's OK to admit I got it first.
[QUOTE=BrokenGlass;16505786]there's a whole lot of downs goin' on in this topic.[/QUOTE] It's mostly nullsquared spam. He may be knowledgeable, but he can certainly be immature sometimes.
why not basic or lua? :buddy:
[QUOTE=nullsquared;16506892]Gotta learn to hide your jealousy better :) I mean, it's OK, we all get jealous sometime, but it's OK to admit I got it first.[/QUOTE] You sure got that example I didn't even post at all first :rolleyes: [quote]why not basic or lua?[/quote] Harr!
[QUOTE=Cathbadh;16508427]he can certainly be immature sometimes.[/QUOTE] Get Children Out
Matlab [editline]06:29AM[/editline] eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
[QUOTE=Cathbadh;16508427]He may be knowledgeable[/QUOTE] More like bombastic.
Wow, who can spot the lairy two in this thread?
[QUOTE=Pj The Dj;16516019]Wow, who can spot the lairy two in this thread?[/QUOTE] More like in this section
[QUOTE=HubmaN;16438636]Because I'm... too... lazy... to... write... C++... runtime... su-zzz. Well, first off, assume you don't get much in the way of built-in functions anyway, the standard library, static objects or global objects without hacking up code to support it, I suppose. (there's a section in The C++ Programming Language about the features of C++ that require a runtime) Wouldn't C++'s automagic memory allocation and corner cases (or just "overhead that comes with features") be a bitch, though? I'd suppose what'd you get could be easily rewritten into C anyway without having to futz over everything...[/QUOTE] Sorry, im a noob, but whats a runtime? But you mean like in C, you can communicate almost directly with hardware? [editline]05:49PM[/editline] [QUOTE=ROBO_DONUT;16380008]I know that "every language has its niche" is the "correct" thing to say, but I've always thought that C++, C#, Java, etc. were in this uncomfortable "middle-level" position, where they try to do everything and do very little well. At the low-level, OOP, operator overloading, encapsulation, etc. aren't at all useful. At the high-level, dealing with strict data typing and memory management is a pain. They're certainly popular right now, so they're probably the pragmatic choices if you want to get a cubicle farm job, but I think that there are better choices from a design standpoint. They certainly [I]can[/I] be used to write good software, but I don't think they're conducive to it. Not to mention you'd have to be completely out of your mind to write a library in any of the aforementioned languages since it would be completely unportable. A C++ library won't even work across [I]compilers[/I], let alone [I]platforms[/I]. Most interpreted languages expect bindings in C, so you can't simply expose a C++ class to a Python extension, it requires some trickery. You can't use them for writing code for resource-limited embedded platforms (I don't mean like your fancy-ass cell phone gadgetry, I'm talking $2 microcontroller), either. Personally, I like a clear separation between the low-level and high-level work. C is clearly a low-level language. You work with memory directly and C code translates almost directly to assembly instructions (unless you have optimizations turned on in your compiler). This is good for building core functionality of your application. Decoding files, intensive processing, rendering output, etc. The backend stuff. You can then use a higher-level language (such as Python) to do the organizational work and build a front-end for the core functionality. This way, you don't have low-level micromanagement seeping into your high-level organization or high-level metaphorical nonsense spilling over into your concrete, close-to-the-metal work. C is probably better to learn with because it makes it exceedingly easy to shoot yourself in the foot. You don't learn anything from success, and you don't learn to ride a bike without ever taking the training wheels off.[/QUOTE] And you mean you go on to C++ or something then? When you have learned C.
Runtime means that certain compiling and linking operations are performed by the program itself when it runs, not by the compiler. It can be convoluted and messy, but standard runtime operations like dynamic library linking is done simply and very often.
[QUOTE=ROBO_DONUT;16380008]you can't simply expose a C++ class to a Python extension, it requires some trickery.[/QUOTE] [url]http://www.boost.org/doc/libs/1_39_0/libs/python/doc/index.html[/url] :-)
[QUOTE=thf;16602801] And you mean you go on to C++ or something then? When you have learned C.[/QUOTE] That's a possibility. [QUOTE=Wyzard;16615852][url]http://www.boost.org/doc/libs/1_39_0/libs/python/doc/index.html[/url] :-)[/QUOTE] Trickery.
Sorry, you need to Log In to post a reply to this thread.