nevalang / neva

🌊 Flow-based programming language with static types and implicit parallelism. Compiles to native code and Go
https://nevalang.org
MIT License
85 stars 7 forks source link

Move println to io #655

Open dorian3343 opened 1 month ago

dorian3343 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 3 weeks ago

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?