Suggestion: new abstraction level Python API

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
Cjkjvfnby
AI Contributor
Posts: 539
Joined: Tue Jun 24, 2014 9:55 pm

Suggestion: new abstraction level Python API

#1 Post by Cjkjvfnby »

Hi, we already have C++ API but I suggest to add one more abstraction level with python API.

Advantages:
  • - remove any knowlege about ID from user space. User need objects to operate with, but c++ api accepts and returns only ID. This make code more simple and readable
    - make auto documentation for API (I missed it so much)
    - easy extend of game objects. (add __str__ and other methods)
    - C++ API can be simplified
    - need less recompilation for developing (in certain cases)
    - magic import placed only once
    - can be done in chunks
Disadvantages:
  • - little decrease of perfomance
    - need to be done
If you dont mind I can make patch.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: Suggestion: new abstraction level Python API

#2 Post by Dilvish »

After my pm to you trying to clarify a number of aspects of AI Client processing you may already share my major concern about this, but for the benefit of anyone else following this thread I'll repeat the part most relevant here, that since for both human and AI clients the universe and objects get replaced/superseded each turn, to my knowledge the only reliable way for a client to track objects from one turn to the next is via ObjectID.

Since adding an extra layer into the AI seems to be of interest to you regardless of the ObjectID issue, and it might be possible (though ungainly) to deal with some or all the superseded object issues by some kind of preprocessing at the start of each turn, I'll explain some additional concerns/questions I have.

"[User] [AI?] need objects to operate with"Although it is true that to get details about the object you need to retrieve that at least initially pull up the object, there are many cases where it seems pretty convenient to me for the AI to organize info as lists of objectIDs, and others where it is very convenient for the AI to index dictionaries of various info by the object ID. In addition to the turn-to-turn coherence issue mentioned above, it's been my experience that the C++ objects exposed via boost cannot be serialized by python and therefore can't go into the AI savegame state. Also, I seem to recall running into an issue using them as keys for dicts.

"C++ API can be simplified" It seems to me that overall the interface would be tremendously more complicated; I'm not sure what you're trying to get at here.

"need less recompilation for developing (in certain cases)"I suppose it might be possible, but I'm not actually seeing what those cases might be.

Now, probably none of this will reduce your interest in "make auto documentation for API". I agree that extra documentation being available for IDEs would be valuable, but I'm rather wary of adding an extra layer to the interface just for that. Do you have any example of the kind of changes you'd be proposing for this?
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Cjkjvfnby
AI Contributor
Posts: 539
Joined: Tue Jun 24, 2014 9:55 pm

Re: Suggestion: new abstraction level Python API

#3 Post by Cjkjvfnby »

Dilvish wrote: "[User] [AI?] need objects to operate with"Although it is true that to get details about the object you need to retrieve that at least initially pull up the object
I want to hide this thing from user.
there are many cases where it seems pretty convenient to me for the AI to organize info as lists of objectIDs
Only thing you can do with it is to iterate over, or pass it as is as argument. List of objects can be filtered and processed in one line (it more readable and need less local vars).
and others where it is very convenient for the AI to index dictionaries of various info by the object ID.
In addition to the turn-to-turn coherence issue mentioned above, it's been my experience that the C++ objects exposed via boost cannot be serialized by python and therefore can't go into the AI savegame state. Also, I seem to recall running into an issue using them as keys for dicts.
It is not trouble for python objects.
Now, probably none of this will reduce your interest in "make auto documentation for API". I agree that extra documentation being available for IDEs would be valuable, but I'm rather wary of adding an extra layer to the interface just for that.
Documentation not for IDE, documentation is for users in html format. It can be extracted via tools.
Do you have any example of the kind of changes you'd be proposing for this?
I will make an example.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Post Reply