Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common common functions ;-) #699

Open
mojoaxel opened this issue Apr 2, 2022 · 4 comments
Open

common common functions ;-) #699

mojoaxel opened this issue Apr 2, 2022 · 4 comments
Labels
question Further information is requested

Comments

@mojoaxel
Copy link
Collaborator

mojoaxel commented Apr 2, 2022

In #548 (comment) 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?

@mojoaxel
Copy link
Collaborator Author

mojoaxel commented Apr 2, 2022

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 on enter. 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 spaces
  • random(max, min=0) - Returns random integer number [min...max].

@coding-horror
Copy link
Owner

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..?

@mojoaxel mojoaxel added the question Further information is requested label Apr 7, 2022
@ugurkupeli
Copy link
Contributor

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.

@drewjcooper
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants