Skip to content

Conversation

@wjt
Copy link
Member

@wjt wjt commented Jun 18, 2024

I think this is clearer than using instance variables, which persist beyond the call to generate_text, to store state which is transient to any given call to generate_text. It's also shorter!

wjt added 2 commits June 18, 2024 11:28
The parameter here is not necessarily the root of the tree.
The depth is a transient property of where in the tree we happen to be
generating code, so it should not be a persistent property of the class.
Pass it explicitly.
@wjt wjt requested a review from wnbaum June 18, 2024 10:36
From an efficiency point of view, repeatedly appending to an immutable
string probably involves repeatedly copying the string. (Some languages
have an optimisation where if `s` is the only reference to a string,
then `s += "foo"` modifies `s` in place; I don't know if GDScript
has that.)

From a clarity perspective, it is strange for the output buffer to be an
instance variable of the InstructionTree – it is a transient buffer used
during a call to generate_text().

Replace it with a PackedStringArray, passed through the recursive calls,
containing lines of code. Join it to produce the generated code as a
whole.
@wjt wjt force-pushed the simplify-instructiontree branch from 6b71011 to 5378c50 Compare June 18, 2024 10:39
Copy link
Contributor

@manuq manuq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@manuq manuq merged commit 06392d9 into main Jun 18, 2024
@manuq manuq deleted the simplify-instructiontree branch June 18, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants