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

Move println to io #655

Open
dorian3343 opened this issue May 24, 2024 · 4 comments
Open

Move println to io #655

dorian3343 opened this issue May 24, 2024 · 4 comments

Comments

@dorian3343
Copy link
Collaborator

Most languages don't have Println builtin (with the notable exception being rust). The rest have them in an Io / Console or other package. I think we should follow this.

@emil14
Copy link
Collaborator

emil14 commented May 24, 2024

Most languages don't have Println builtin

Actually many do

  1. Python
  2. Javascript
  3. Kotlin
  4. Lua
  5. Swift
  6. PHP
  7. Ruby
  8. ...etc.

I think we should follow this.

What will we get from this except the need to import? I personally never like the need to import fmt in Go to make basic IO stuff.

BTW Go has builtin print function (it's never used tho)

@dorian3343
Copy link
Collaborator Author

I think we should keep builtin as small as possible and packages more grouped. We should decide what package is for what and break off pieces into those packages.

@emil14
Copy link
Collaborator

emil14 commented May 25, 2024

I agree that some stuff could (and maybe should) be moved from builtin somewhere else, but I'm not sure about Println.

builtin package currently serves 2 purposes:

  1. compiler is aware of that package and uses knowledge about its structure in analyzer and desugarer
  2. things that are used frequently (I personally think that printing comes to this section)

Also, if there would be strong arguments for moving println out of builtin, then the question arise - should it be io? Why not e.g. create fmt like Go does? I believe there are other languages with this structure (e.g. Odin)

@swork1
Copy link
Contributor

swork1 commented Jun 3, 2024

Also, if there would be strong arguments for moving println out of builtin, then the question arise - should it be io? Why not e.g. create fmt like Go does? I believe there are other languages with this structure (e.g. Odin)

builtin.go actually has a println also. These builtins are meant for simple printing/debugging and the others under fmt have error handling and more sophisticated things happening.

// implementation-specific way and writes the result to standard error.
// Print is useful for bootstrapping and debugging; it is not guaranteed
// to stay in the language.
func print(args ...Type)

// The println built-in function formats its arguments in an
// implementation-specific way and writes the result to standard error.
// Spaces are always added between arguments and a newline is appended.
// Println is useful for bootstrapping and debugging; it is not guaranteed
// to stay in the language.
func println(args ...Type)

Maybe this would be a good approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants