News for hackers. Stuff that matters.
Re:Hurl, the Exceptional Language by remram on Sunday May 26, 2024 @10:07AM (#40482300)
Preferably enforce that the namespace matches the include/import statement, if the statement doesn't use an explicit name binding...

import "foo/bar" should make foo.* OR bar.* available, not bazz.*. I'm looking at you, Go.

Re:Hurl, the Exceptional Language by mikepurvis on Sunday May 26, 2024 @11:04AM (#40482703)
Python has this in a slightly different spot. Most pypi packages have the name and module aligned but it’s only a matter of convention, and there are some common deviations like the pyyaml package providing the yaml module.
Re:Hurl, the Exceptional Language by remram on Sunday May 26, 2024 @04:11PM (#40484995)
Ah yes, Python's package manager has it wrong also. But at least Python the language is clear, so you can know "import foo" or "from bar import foo" creates a name "foo" in your file. Go has no such limitation. Imagine doing "import pyyaml" and "yaml" is the name defined...
Re:Hurl, the Exceptional Language by jakewins on Sunday May 26, 2024 @04:18PM (#40485050)
Wait I’m so confused by this - this is the opposite of how I thought it worked? Go import creates exactly the symbol you mention in the import statement, like “import fmt” creates a symbol “fmt”?

Can you give an example of what you mean?

Re:Hurl, the Exceptional Language by sweeter on Sunday May 26, 2024 @06:38PM (#40486051)
Yea, this is correct.

    ```go
    import (
       "net/http"
       "os"

       "github.com/anacrolix/torrent"
       tstor "github.com/anacrolix/torrent/storage"
    )
```

would import as: http, os, torrent and tstor. That guy is mixed up.

Re:Hurl, the Exceptional Language by remram on Monday May 27, 2024 @10:44AM (#40491205)
I don't know what this proves. See example above for an example of exactly what I've said.
Re:Hurl, the Exceptional Language by thiht on Monday May 27, 2024 @02:21AM (#40488141)
The only example I have in mind is modules, which can have a different name from their root package.

For example you can have github.com/user/go-module as module name, and "module" as package name, so "import github.com/user/go-module" will be imported as "module.*".

There’s a linter that automatically aliases this kind of imports with their actual module name so that it’s non ambiguous when reading the import list.

Re:Hurl, the Exceptional Language by remram on Monday May 27, 2024 @10:42AM (#40491184)
Here's an example, a package bar under a totally different name:

    package main

    // imports 'bar', you couldn't possibly know from reading this line
    import "github.com/remram44/foo20240527"

    func main() {
        // ??? where does this function come from ???
        bar.SomeFunc()
    }
Re:Hurl, the Exceptional Language by d-z-m on Sunday May 26, 2024 @11:39AM (#40483006)
This is normally how it works, no?
Re:Hurl, the Exceptional Language by remram on Monday May 27, 2024 @10:52AM (#40491285)
What does that mean?
Re:Hurl, the Exceptional Language by d-z-m on Tuesday May 28, 2024 @12:49AM (#40497423)
it means: this is normally how imports in Go work, is it not?
Re:Hurl, the Exceptional Language by remram on Tuesday May 28, 2024 @01:09PM (#40502929)
What is how it works? How is it normal?

I posted a criticism of Go, I don't know what you mean by "this is how it normally works".

Re:Hurl, the Exceptional Language by d-z-m on Wednesday May 29, 2024 @08:32AM (#40511250)
I'm saying that when I import something, "foo/bar" "bar/baz" etc, The way I access the exposed functions and types in that package usually corresponds to the basename. e.g. bar.* for the first example, and baz.* for the second example. Is your criticism of Go that it is technically not required for this to be the case?
Re:Hurl, the Exceptional Language by amscanne on Sunday May 26, 2024 @03:03PM (#40484532)
> I'm looking at you, Go.

I’m so confused by this. Unless you use a dot import, isn’t this just bar.*?

Re:Hurl, the Exceptional Language by remram on Sunday May 26, 2024 @04:09PM (#40484973)
I'm not sure what you mean. The name binding created is whatever `package <...>` is in the target package's file, which can be anything.
Re:Hurl, the Exceptional Language by amscanne on Sunday May 26, 2024 @04:30PM (#40485139)
Ah got it. I think there’s such a strong convention there, that it would be exceedingly rare to see in pratice. It’s probably allowed just for compat reasons at this point — but I think your point is don’t make that mistake in the first place, not that Go is filled with flagrant violations of the convention.