basic-computer-games
basic-computer-games copied to clipboard
common common functions ;-)
In https://github.com/coding-horror/basic-computer-games/issues/548#issuecomment-1079839924 it was decided to have a (minimal) set of common IO-functions so those don't need to be re-implemented in every game.
I propose we use the same function (same names) in every programming language (as far as possible!)
That way the code get's easier to read and compare.
What do you think?
To stay close to the original BASIC implementation I would propose the following functions (pseudo language)
writeLine(...messages)- Writes content to the terminal and finishes with a linebrank.async input(message)- prints out the message followed by a space and waits for an user input. The promise is resolved onenter. The result is a string without a newline at the end.
In addition it could be useful to have the following functions:
write(...messages)- Writes content to the terminal without a newline at the end.tab(length)- returns a string with the given length containing only of spacesrandom(max, min=0)- Returns random integer number [min...max].
yes! I think this is perfect. Just the minimum viable set of common functions, justified by at least 10 (ish) of the programs needing them..?
I have published a utility crate for rust users. Currently there are only functions for printing intro/instructions and different types of user prompts - but I think that is good for our purpose.
See the common library for .Net at 00_Common/dotnet for my rationale and implementation of this idea.
I like the idea of having a set of functions with names/signatures that are typical of the language's standard library, but provide the behaviour of the BASIC interpreter.
I don't like the idea of creating a DSL that looks like BASIC. Hence, I have not implemented a Tab(int) function in the .Net common library, or any of my game ports, preferring to stick to C#/.Net idioms.
What @mojoaxel said ;) .. "stay close to the original implementation"