News for hackers. Stuff that matters.
Re:Hurl, the Exceptional Language by z3t4 on Sunday May 26, 2024 @05:12AM (#40480718)
For anyone designing a programming language, enforce namespace to includes/imports! and if possible, don't allow top level side effects.

    let foo = include "lib/foo.hurl"
    foo.init()
it's much easier to reason about then, for example:

    include "lib/foo.hurl" // side effects
    baz(buz) // function and variable that I have no idea if they are in the standard library, or included *somewhere*

That way it's much easier
Re:Hurl, the Exceptional Language by BoppreH on Sunday May 26, 2024 @08:16AM (#40481589)
This also allows one to pass parameters to `foo.init()`, something you cannot do with naked imports.
Re:Hurl, the Exceptional Language by Joker_vD on Sunday May 26, 2024 @08:51AM (#40481777)

    import foo(42, FULL_OF_EELS) as foo

    -:1:8: E0012: Initializer of module "foo" has 3 arguments, 2 were provided.
Re:Hurl, the Exceptional Language by endofreach on Sunday May 26, 2024 @04:33PM (#40485151)
In case we're still in the design phase of the language, named arguments would help around that (coupled with a good IDE)... but yeah, probably i agree with how i interpret your comment.

Shouldn't be like how parent proposed imports work. Would lead to too much pain.

Re:Hurl, the Exceptional Language by moomin on Sunday May 26, 2024 @05:29AM (#40480804)
I mean, it’s a language based around exceptions for flow control, I think the “easy to reason about” ship has sailed.

(Don’t confuse this with me thinking this project is worthless, I think it’s art.)

Re:Hurl, the Exceptional Language by andypants on Sunday May 26, 2024 @07:59AM (#40481493)
The imported files should really hurl their exported functions, and the importer needs to catch it into a variable.
Re:Hurl, the Exceptional Language by fmbb on Sunday May 26, 2024 @08:06AM (#40481533)
Oh, dependency injection?
Re:Hurl, the Exceptional Language by kdmccormick on Sunday May 26, 2024 @08:52AM (#40481787)
Ha!
Re:Hurl, the Exceptional Language by cobbal on Sunday May 26, 2024 @09:41AM (#40482115)
Maybe even dependency ejection.
Re:Hurl, the Exceptional Language by ntietz on Sunday May 26, 2024 @11:29AM (#40482900)
That’s a great idea. I’ll have to do that for the next version.
Re:Hurl, the Exceptional Language by groestl on Sunday May 26, 2024 @07:32AM (#40481359)
> I mean, it’s a language based around exceptions for flow control, I think the “easy to reason about” ship has sailed.

Sometimes I wonder if I'm exceptionally (haha) talented as I personally find the impact of exceptions on flow control pretty easy to grasp. But based on my understanding of other advanced computer language concepts, which is pretty lacking in some regards, I come to the conclusion that it can't be too hard, and people make a lot of fuss about it for no particular reason.

Re:Hurl, the Exceptional Language by eyelidlessness on Sunday May 26, 2024 @11:18AM (#40482805)
It’s largely difficult because either:

- you’re working in a language that doesn’t have checked exceptions, so the set of potential errors and the set of potentially error-raising calls is infinite but unknowable

- you’re working in a language that has checked exceptions, and you hate that it makes you do work, so you catch-rethrow runtime errors that recreate the first scenario

- you’re working in a language that has checked exceptions, but someone else did the second scenario so you’re in the first scenario anyway

Re:Hurl, the Exceptional Language by groestl on Sunday May 26, 2024 @11:50AM (#40483105)
Other programmers tend to be bad at reliably cleaning up resources such as file handles, locks etc, so I need to inspect the whole invocation tree anyways to have an understanding of what runtime implications I've summoned by invoking other people's code.

As for myself, I've lived through the hell the are checked exceptions in Java. You learn that compositionality and checked exceptions are at odds when you try to insert a remoting layer into an application that has grown without IOExceptions. Then you learn that it's actually not necessary to know the set of possible errors, just make sure that you're not a bad programmer as in my first paragraph, and everyone will be fine. This is also something that you can learn from Exceptional C++.

Re:Hurl, the Exceptional Language by fiddlerwoaroof on Sunday May 26, 2024 @01:28PM (#40483860)
Yeah, I’ve never understood the complaints about exceptions either: most of the time you want the exceptions to just bubble up anyway because, in that case, you only have to think about the contracts of the functions you interact with and not about the unusual states you might be in. Return-type or return-value based error handling has always seemed to me to be significantly worse.
Re:Hurl, the Exceptional Language by xboxnolifes on Sunday May 26, 2024 @11:29AM (#40482902)
The unchecked exception example doesn't seem any different than using a dynamically typed language and reading return values, and exceptions seem to get significantly more hate than those.
Re:Hurl, the Exceptional Language by eyelidlessness on Sunday May 26, 2024 @11:32AM (#40482930)
Because even in a dynamically typed language you can generally go look at what the function returns. You can’t look at what it throws without walking the entire call stack and inspecting the source code of the runtime.
Re:Hurl, the Exceptional Language by retrac on Sunday May 26, 2024 @11:51AM (#40483115)
Flow control involving recursion is already well into the weeds. Recursion and exceptions is probably a nightmare for someone not fond of ML or Lisp.
Re:Hurl, the Exceptional Language by groestl on Sunday May 26, 2024 @01:26PM (#40483844)
But why? I don't get it. You call something. It can break. It will break. Treat it as such wrt to resources you've allocated. You can ignore error details here.

At the highest level of your application (and at a few critical places, executors, retrying strategies etc) handle all the exceptions you know of, and implement a sane default for everything you don't know.

Done.

Re:Hurl, the Exceptional Language by moomin on Monday May 27, 2024 @04:37PM (#40494432)
Not really, what’s happened is that everyone’s so scared of exceptions they only use them in extremely confined ways. These ways are relatively easy to reason about. But the full fat arbitrary goto around your call stack is avoided.
Re:Hurl, the Exceptional Language by infogulch on Sunday May 26, 2024 @05:42AM (#40480840)
I agree, side-effecting imports add to the spooky action at a distance aesthetic.
Re:Hurl, the Exceptional Language by karma_pharmer on Sunday May 26, 2024 @06:53AM (#40481171)
i think you mean to to say "has sunk"
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.
Re:Hurl, the Exceptional Language by Wonton56 on Sunday May 26, 2024 @12:28PM (#40483363)
I do not disagree, but I use IntelliJ for work and it shows clearly where some reference is imported from and let you navigate to it with a shortcut. VSCode does similar things with plugins and LSP, just much worse. I cannot work in VSCode because navigating code is so slow. Is this suggestion only useful when you don’t have such tools? It seems impossible to me that people can live without them, at least in a professional setting.
Re:Hurl, the Exceptional Language by sspiff on Sunday May 26, 2024 @01:04PM (#40483642)
Let's not write software and especially programming languages which assume or depend on users having access to advanced tools that require a monthly subscription.
Re:Hurl, the Exceptional Language by kwhitefoot on Sunday May 26, 2024 @12:47PM (#40483510)
> I use IntelliJ for work and it shows clearly where some reference

Useful when writing the code but not much use when reading the code.

Re:Hurl, the Exceptional Language by packetlost on Sunday May 26, 2024 @04:09PM (#40484976)
This is the chief problem with Python and most Lisps
Re:Hurl, the Exceptional Language by manusachi on Sunday May 26, 2024 @04:11PM (#40484985)
Agree!

For that very reason in Elixir `import` is discouraged in favor of `alias`

Re:Hurl, the Exceptional Language by __jonas on Sunday May 26, 2024 @06:53PM (#40486140)
I enjoy Elixir but this situation is quite unfortunate, there is alias, import require and use for referencing / pulling in code external to a file in some way or another, plus the possibility of calling a function from another module directly by name without an import statement using the module name – and the most annoying part of it is that none of these give an indication of which file the other module is from, which is like 50% of the utility of an import statement for me.

Instead there is this pattern of naming modules based on the file path they are located in, which is not enforced.

Re:Hurl, the Exceptional Language by smj-edison on Sunday May 26, 2024 @07:27PM (#40486288)
Doesn't Elixir (and Erlang for that matter) specifically require a module to not be in a specific place in order to have hot reloading of modules? Though I suppose you could still have hot reloading and require a module to be in a specific place.
Re:Hurl, the Exceptional Language by throwawaymaths on Monday May 27, 2024 @01:11AM (#40487751)
Nope. Elixir doesn't care where your module lives. (You can even "nest" modules, though it's not a great practice)
Re:Hurl, the Exceptional Language by __jonas on Monday May 27, 2024 @03:50AM (#40488624)
Not sure, could be that Elixir stuck close to Erlang's module system yeah.

But for example gleam [1] is another language on the BEAM (compiles to Erlang), that has a much nicer approach: All imports must be declared explicitly, and the import path in your local project is based on the file structure so you always know where something is imported from [2].

[1] https://gleam.run/

[2] https://tour.gleam.run/basics/modules/

Re:Hurl, the Exceptional Language by lhfasufdowedfs on Sunday May 26, 2024 @04:44PM (#40485223)
Agreed 100%.

I forked Ruby to have require that didn't clobber the symbol table but then lost interest in Ruby itself because the ecosystem seems unhinged on shared global mutable state.

Re:Hurl, the Exceptional Language by djha-skin on Sunday May 26, 2024 @05:38PM (#40485620)
I mean, for anyone designing a programming language, don't use exceptions as the chief means of control flow.

Critiquing a joke design is of dubious usefulness, at best :)

Re:Hurl, the Exceptional Language by sergiotapia on Sunday May 26, 2024 @07:38PM (#40486318)
This is precisely why I stopped using Nim. I was going crazy trying to remember what functions were called etc. I could do from x import nil but it felt like fighting the language.
Re:Hurl, the Exceptional Language by xigoi on Wednesday May 29, 2024 @08:25AM (#40511190)
Requiring namespaces would break dot call syntax, which is one of Nim’s main features.
Re:Hurl, the Exceptional Language by firesloth on Saturday June 01, 2024 @08:34AM (#40545216)
It could be preserved if specifying the namespace used a different syntax.

Right now, if I have the `foo` module and `bar` function, I can call `arg1.bar()`, or `foo.bar(arg1)`. But if the namespace didn't also use `.`, then it wouldn't be an issue.

For sake of argument, lets choose `/` like Clojure. Then we'd get: `arg1.foo/bar()` so we can specify the namespace and uniform function call syntax is preserved.

Re:Hurl, the Exceptional Language by xigoi on Saturday June 01, 2024 @08:38AM (#40545237)
True. That said, would you find, say,

    "one,two".std/strutils/split(',')
more readable than this?

    "one,two".split(',')
Re:Hurl, the Exceptional Language by firesloth on Saturday June 01, 2024 @09:24AM (#40545545)
Maybe. First, you need the module name primarily for disambiguation for compiler or possibly for readability. I wouldn't recommend requiring it for everything, eg one of the arguments against requiring naming all imported symbols explicitly is for procs that use `[ ]`.

But I think the std/strutils/split counter example isn't strong for two reasons:

1. When you disambiguate in Nim, you use just the module name, not it's full path. So it would still just be `strutils/split`.

2. If we were to introduce such a syntax, we could also introduce an `import foobarbazqux as foo` alias syntax, which is present in many languages (eg JavaScript, Clojure, etc). This would also be useful if we ever had module name collisions, which has never happened to me in Nim, but doesn't seem impossible.