Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 12 13 [14] 15 16 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100597 times)

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Programming Help Thread (For Dummies)
« Reply #195 on: July 03, 2011, 08:59:20 pm »

@Angle:
Actually, Virex is mistaken. True, all things in C++ are passed by value (not all mainstream languages do this; Java is purely pass-by-reference with the exception of primitives, C# is about half-and-half (sort of), and most scripting languages do pass-by-reference for objects). While moving objects around in a vector will not cause objects to be created or destroyed, there is definitely different behavior between a vector that is holding objects by value and one that is holding objects by reference.


...

Java is always pass by value. period. There isn't actually a way to do pass by reference with java, at all. The reason you are confused is that everything that isn't a primitive is an object. When you pass an object to a method, you are actually passing a copy of the value of its handle. That handle is effectively a reference, but you can't pass it directly to a method.

http://javadude.com/articles/passbyvalue.htm
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #196 on: July 03, 2011, 09:10:25 pm »

Ah, I was unaware of the technical difference between a pointer and a reference, and I always assumed that passing a pointer by value was just called passing by reference in common practice (which is a rather widespread misconception, apparently).

Blame common usage and semantic drift!
« Last Edit: July 03, 2011, 09:13:21 pm by Normandy »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #197 on: July 03, 2011, 11:31:52 pm »

As for finding whether something is by value or by reference in C++, you can always tell it to output various parts and pointers to those parts to get sort of an idea of how they link up. Then it's just an issue of matching up memory addresses from the various pieces.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #198 on: July 04, 2011, 12:01:22 pm »

@Angle:
Actually, Virex is mistaken. True, all things in C++ are passed by value (not all mainstream languages do this; Java is purely pass-by-reference with the exception of primitives, C# is about half-and-half (sort of), and most scripting languages do pass-by-reference for objects). While moving objects around in a vector will not cause objects to be created or destroyed, there is definitely different behavior between a vector that is holding objects by value and one that is holding objects by reference.
Arg, yep you're right. I forgot for a moment that C++ doesn't implicitly handle references like most other languages do (you can see I rarely use it), which leads to the confusion that Nadaka pointed out. To C++ a variable containing an object has that object as it's value and thus it copies the object when you pass it somewhere. To for example Java, a variable containing an object contains a reference to that object and so it copies the reference, but the reference is handled implicitly so the variable usually behaves as if it contained the object itself.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #199 on: July 19, 2011, 10:13:19 am »

In that train of thought, what's actually the use of references in C++, other than "->" is two keystrokes more than "."?
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #200 on: July 19, 2011, 10:40:50 am »

Well, it makes it easier to access memory-mapped IO on systems for which no libraries are available yet, and you can do pointer arithmetic which can be faster then what the compiler generates in some cases. Other then that, I don't really know. It's not necessary to be able to access pointers directly form manual memory management, as pascal does that too and doesn't allow you to alter the pointers directly (IIRC).
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #201 on: July 19, 2011, 10:49:17 am »

I think you just summed up the benefits of pointers. I'm actually wondering what the benefits of references are.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #202 on: July 19, 2011, 11:01:08 am »

The culprit is mainly in garbage collection. You can't run a mark-and-sweep or reference counting algorithm without knowing what the references are, and for that you need to be able to differentiate pointers from integers.


Another point is that if references are separated from other kinds of data, then it's possible to do some aggressive optimizations by precomputing the values of variables whenever possible. If however the compiler cannot differentiate between a pointer and an integer it becomes much more difficult to make those optimizations IIRC.
Logged

freeformschooler

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #203 on: July 19, 2011, 11:20:34 am »

Alright, I'm doing this slightly fancy side-view Flash RPG system. I got my design doc about half completed, and I did a from-scratch RPG system before (using nothing but highly manipulated MovieClips and regular ol' AS3/Adobe Flash/FlashDevelop). However, I'm looking for a library that'll allow the UI to be more dynamic with less work (plus one that has better handling of animated images, doing that with MovieClips was a nightmare in pure code so I'm going to also be using bitmaps). I'm currently torn between my two favorite libraries, Flixel and Flashpunk (which was in some way derived from Flixel I believe?). However I'm open to suggestions.
Logged

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: Programming Help Thread (For Dummies)
« Reply #204 on: July 19, 2011, 11:46:57 am »

In C++, I think the main use of references is to pass things to functions. I know that's what I use them for. C++ has no garbage collection, so I doubt they're used for that.
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #205 on: July 19, 2011, 02:03:15 pm »

In C++, I think the main use of references is to pass things to functions. I know that's what I use them for. C++ has no garbage collection, so I doubt they're used for that.
That's not an unique use for references though. Both pointers and references enable a function to modify itīs input arguments (as any Lisper who accidentally used nconc instead of append somewhere can tell you ;) ). Although I donīt know much about C++ (BURN THE HERETIC), it seems to me like references are a syntactic abstraction layer over pointers, making it easier to work with them but slightly less powerful (no pointer arithmetic with references for example, which could also be seen as a good thing btw)
Logged

RenoFox

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #206 on: July 19, 2011, 06:41:32 pm »

I'm currently making a flash program for adding new words into DF, but right now I have two problems about it:

How do I write a new line into a text file? I have tried /n in the text as well as setting a textfield to multiline and writing <BR> into its htmltext, but neither of them starts a new line when saved into a text file with FileReference.

When I try to import CheckBox via "import fl.controls.CheckBox;", I get: "Error: Definition fl.controls:CheckBox could not be found". Yet when I use "public var nouncheck:CheckBox;", I get the error: "Error: A file found in a source-path must have the same package structure '', as the definition's package, 'fl.controls'."

I'm using FlashDevelop. I also dont now much about packages so this can possibly have a simple solution to it.


Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #207 on: July 19, 2011, 06:44:47 pm »

References IIRC just have a stricter set of conditions than pointers, thus allowing you to make more assumptions about them. For example, a reference cannot change what it is pointing to (so it is similar to int * const in that regard), and it cannot be initialized with a NULL or uninitialized value (making it even more dependable than an int * const), so you can make the same assumptions with a reference as you can a normal variable (for the most part).
Logged

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: Programming Help Thread (For Dummies)
« Reply #208 on: July 19, 2011, 10:13:50 pm »

I'm working on a project, and could use some advise.
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

Ehndras

  • Bay Watcher
  • Voidwalker
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #209 on: July 19, 2011, 10:47:54 pm »

Hmm, I barely understand a lot of this.


For someone with little-to-no prior programming experience, what would be the most efficient way to pick up C++ and such, for coding in 2D/Text roguelikes/RPGs like DF, Cataclysm, etc? I know there's C++ books for sale but I'd like to know if I should stick to books or should I try some basic do-it-yourself rpg-making with some good google-work, or...

*shrug*
Logged
Quote from: Yoink
You're never too old to enjoy flying body parts.  
Quote from: Vector
Ehndras, you are the prettiest man I have ever seen
Quote from: Dorsidwarf
"I am a member of Earth. I enjoy to drink the water. In Earth we have an internal skeleton."
Pages: 1 ... 12 13 [14] 15 16 ... 91