Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2] 3

Author Topic: DF in python?  (Read 9903 times)

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: DF in python?
« Reply #15 on: October 02, 2012, 12:00:49 pm »

This board's font makes my eyes bleed when trying to read code.
Logged

Starver

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #16 on: October 02, 2012, 12:06:21 pm »

I think you could probably also blame the way I wrote my code... ;)

("//" probably also looks better as a comment separator than "#", and there are better commenting/PODding options in Perl, but I still tend to use "#".  And I could have put some extra space separations in, in addition to where I deliberately aligned things.)
Logged

Akjosch

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #17 on: October 02, 2012, 02:13:09 pm »

You say call-by-sharing, I say non-visible pass-by-reference. :P (or reference-passed-by-value).

If Python would pass a reference, this code ...

Code: [Select]
def setX(arg): arg="Two"

val="One"
setX(val)
print(val, "\n")

... would print "Two". It prints "One".
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: DF in python?
« Reply #18 on: October 03, 2012, 07:37:10 am »

Yes, that would be non-visible pass-by-reference. It means assignments to the argument aren't visible by the caller. ;)

Alternatively, reference-passed-by-value is pretty straightforward. It's a reference (ie, a pointer) passed as a value. Assigning anything to the argument wouldn't work wouldn't be seen in the caller's scope.

Quite frankly, I'm not a fan of people coining new terms when things already fall into another category which would describe the mechanism better.
Logged

Akjosch

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #19 on: October 03, 2012, 07:59:10 am »

Yes, that would be non-visible pass-by-reference. It means assignments to the argument aren't visible by the caller. ;)

Alternatively, reference-passed-by-value is pretty straightforward. It's a reference (ie, a pointer) passed as a value. Assigning anything to the argument wouldn't work wouldn't be seen in the caller's scope.

Quite frankly, I'm not a fan of people coining new terms when things already fall into another category which would describe the mechanism better.

That's ... quite ironic, given that "non-visible pass-by-reference" is something you just coined yourself (no, seriously - Google says "No results found for "non-visible pass-by-reference".", try it out). :D

Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: DF in python?
« Reply #20 on: October 03, 2012, 10:01:00 am »

I coined nothing. I simply described what was going on. "Sharing," however, is not very descriptive.
Logged

Helgoland

  • Bay Watcher
  • No man is an island.
    • View Profile
Re: DF in python?
« Reply #21 on: October 03, 2012, 10:20:15 am »

[1] There's a tale from some war or other (Korean?) where a British commander was asked by a US general how he was doing with his part of the front-line.  "It's a bit sticky here", or similar, was the reply, which was taken as "Not bad, could be better", but was actually supposed to indicate that things weren't going well at all.  Anyway, maybe a bad example, but just came to mind.
Vietnam war, I think - and that unit was pretty much wiped out completely before air support arrived.
Logged
The Bay12 postcard club
Arguably he's already a progressive, just one in the style of an enlightened Kaiser.
I'm going to do the smart thing here and disengage. This isn't a hill I paticularly care to die on.

Archereon

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #22 on: October 03, 2012, 10:30:06 am »

For actual games in Python, there's always pygame, which apparently uses "omtpimized C and Assembly" code for its core functions. I'm not entirely sure how that works though.
Logged
I want to tell you they were bad men, cephalo.  I want to tell you that with a better overseer the Fortress never would've gotten so bad someone would get offed in a pointless fisticuffs.
But the sad truth charlie?
It was inevitable.

SethCreiyd

  • Bay Watcher
  • [VESPERTINE]
    • View Profile
Re: DF in python?
« Reply #23 on: October 03, 2012, 11:12:24 am »

Yes, that would be non-visible pass-by-reference. It means assignments to the argument aren't visible by the caller. ;)

Alternatively, reference-passed-by-value is pretty straightforward. It's a reference (ie, a pointer) passed as a value. Assigning anything to the argument wouldn't work wouldn't be seen in the caller's scope.

Quite frankly, I'm not a fan of people coining new terms when things already fall into another category which would describe the mechanism better.

That's ... quite ironic, given that "non-visible pass-by-reference" is something you just coined yourself (no, seriously - Google says "No results found for "non-visible pass-by-reference".", try it out). :D




Call-by-sharing is the common description.  In Python, strings are immutable, so when you assign  (arg = 'One')  you're only creating a new string for arg to reference within the function, and val remains unchanged since it's still referencing the 'Two' string.

If a variable is passed as a function argument, then changes to that variable are visible to the caller only if the object is mutable.  It's called 'by-sharing' because the function and the caller have equal access to the same argument object.

So setX won't work, but setY will:

Code: [Select]
>>> def setY(arg): arg[0] = "Two"

>>> val=["One"]
>>> setY(val)
>>> print (''.join(val))
Two

edit:  This works because it's mutating the argument.  If the setY code was (arg = ["Two"]), it wouldn't work.
« Last Edit: October 03, 2012, 11:27:04 am by SethCreiyd »
Logged

Akjosch

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #24 on: October 03, 2012, 11:40:20 am »

I coined nothing. I simply described what was going on. "Sharing," however, is not very descriptive.

"Call-by-sharing" doesn't mean to be descriptive since it's a technical term, one some 40 years old by now. Technical terms are by their nature not descriptive; they are short-hand notations used to not have to write down the full descriptions and definitions about exactly is being talked about every time. Thus as an example "compiler" doesn't just mean something which collects something else, it specifically means "a group of tools used to create machine-executable binary code out of human-readable source code", which the word itself doesn't describe at all either.
Logged

Froggie

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #25 on: October 03, 2012, 02:55:16 pm »

Hate to interrupt this terribly confusing debate but could anyone verify the usefulness of code-academy as a learning resource? :-\
Logged

Akjosch

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #26 on: October 03, 2012, 03:28:39 pm »

Hate to interrupt this terribly confusing debate but could anyone verify the usefulness of code-academy as a learning resource? :-\

You mean http://www.codecademy.com/ ? It looks fun at a first glance, and it will certainly teach you how to code. No idea if it will teach you how to program, but worth a few days, I guess.

Good general sites you should check out while you're at it:

http://gamedev.stackexchange.com/
http://www.gamedev.net/
Logged

Black_Legion

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #27 on: October 03, 2012, 09:09:47 pm »

I have just got interested in coding and after a few google searches i have deduced that the easiest language to start with would be python and my ability in said language is wanting to say the least, when my ability improves im hoping to be able to make at least simple rogue-likes and similar projects. but i understand toady uses C++ and was wondering would python be able to create something at all like DF?

Goblin Camp, a DF-like spinoff made using python and it is largely open source. This means you can crack it open and take a gander at what it does. Lagly though development has been suspended(seemingly) due to the code base largely growing out of the developers hands and the limitations in the language itself. DF is largely written in a strongly-typed, object orientated language like C++ with some good ways to manage the core memory instead of relying on a garbage collector like Java or C#.

Ideally I would recommend downloading GC: Goblin Camp to see how one person solved the particular problem and getting some ideas.

Next go to Rogue-like Development wiki  and look and some of the frameworks, business objects, structures, and algorithms you may need to implement. Essentially you will have to rely on google searching things you or unfamiliar with to gain better knowledge.

Stack Overflow is very good for a variety of programming problems with answers from a knowledgable community. As an IT professional I use this when my coworkers or the assets we have from the company don't really address what we need. Also google everything you don't understand.
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: DF in python?
« Reply #28 on: October 03, 2012, 11:03:53 pm »

"Call-by-sharing" doesn't mean to be descriptive since it's a technical term, one some 40 years old by now. Technical terms are by their nature not descriptive; they are short-hand notations used to not have to write down the full descriptions and definitions about exactly is being talked about every time. Thus as an example "compiler" doesn't just mean something which collects something else, it specifically means "a group of tools used to create machine-executable binary code out of human-readable source code", which the word itself doesn't describe at all either.
:/

 Yes, some jargon are not completely descriptive; however, it's a general goal to make it something as descriptive as possible for someone in the field, often by analogy, or to name it after the most prominent advocator/discoverer. My beef with the term is that it adds ambiguity without really bringing anything proportionally new to the table. Call-by-object, another name for the strategy, I find somewhat better. 

For descriptive jargon, look at unit testing: testing discrete units of a whole application in isolation.

All in all, it doesn't change the facts of the matter: Python passes a reference for which assignments of the argument cannot be seen by the caller.
Logged

Akjosch

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #29 on: October 04, 2012, 12:36:22 am »

Yes, some jargon are not completely descriptive; however, it's a general goal to make it something as descriptive as possible for someone in the field, often by analogy, or to name it after the most prominent advocator/discoverer.

I'd say your assertion isn't actually true, and never was. CS technical terms come from mathematics and its tradition, and look at the very basic terms like "magma" (which means: "set with an operation on its elements for which all results are also in the set") or "eigenvalue" (which I would need several sentences to describe the meaning of in the most basic terms, even if I were trying to go for the shortest possible explanation), where the second one's name doesn't come from being named after someone called "Eigen" - instead, it's from the German word for "self".

For a more software-relevant technical term (though eigenvalues are used quite a bit in physics engines too), try finding out what a "dual quaternion" is and what it's useful for by its name alone - even when knowing which of the many, many meanings of "dual" it refers to and what a "quaternion" is.

All in all, it doesn't change the facts of the matter: Python passes a reference for which assignments of the argument cannot be seen by the caller.

That's implementation-specific. Python implementations (there is more than one already) can implement the same call-by-sharing semantics by actually copying the argument values, then copying them back if they were modified in the function. This is useful if the function is running on a different computer from the calling environment.
« Last Edit: October 04, 2012, 04:06:23 am by Akjosch »
Logged
Pages: 1 [2] 3