aardappel / lobster

The Lobster Programming Language

Home Page:http://strlen.com/lobster

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module with namespaces

hubertpnj opened this issue · comments

Is Lobster going to have modules with namespaces (lib.f), or prefixes (lib_f) are here to stay?

There are no plans to change it from _ to ., no. Other than personal preference, any reason?

Other than personal preference, any reason?

Doesn't seem to resolve collisions in a meaningful way, and it also makes things from namespaces look like regular identifiers, so you can't tell them apart. Makes code harder to read and to follow.

Also leads to misleading errors:

namespace foo

def derp():
	return 10
import foo

def foo_derp():
	return 200

print(foo_derp())
test.lobster(3): error: double declaration of `foo_derp`
in: def foo_derp():
at:               ^

That's misleading because there are in fact NOT two definitions of foo_derp. There's one of foo_derp, and one of derp, inside a namespace foo. The latter is a distinct definition of foo.derp or foo::derp or foo->derp, or whatever it could be referred as, which imo ought to be anything but foo_derp.

I've just only now started looking at Lobster, so I could be missing something, but it seems to me this could end up leading some users chasing after a definition that doesn't exist, until they realized it's just their function colliding with some lib that they're importing, but the error doesn't make that immediately clear, and the syntax doesn't prevent it.

Since this issue was originally posted, more people have mentioned their dislike for how namespaces use _, so I am indeed considering changing it, but it is an invasive change, so have to see how we can ease in to it.

Another big question is if all the gl_ functions should also become gl. functions, since it is essentially a namespace. That will cause a lot of churn for people.

There's now a poll going on in the Lobster Discord on what namespacing should be like :) https://discord.gg/szJPYdX