-
Notifications
You must be signed in to change notification settings - Fork 64
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
add (syntax-only) modules for functions #145
Comments
Big +1 to this and also to the |
Yes, good idea. It happens to every language (apart from emacs lisp) sooner or later! You make no mention of adding a If we do add a |
I should have mentioned this in the issue. I purposefully left this out of scope, as I think it's 1) something we could add later, but also 2) something that might just not be worth doing at all (it's that fine balance between making the language convenient and simple, vs. making it complex and powerful).
I would definitely not be favouring this solution. Leaving aside the potential future changes a separate The biggest advantage at the start is that we don't introduce accidental typo's, and also that any new modules that are added are easily visible to PR reviewers (and thus potentially worth a discussion). |
Noting, we are going to finish vectordotdev/vector#3740 before doing this. I'd like to see how far good naming and guidelines get us. My concern with this change is the complexity and adding to the learning curve. The simplicity of a list of functions is very nice. |
We haven't done anything with this proposal so far, and we might never, but the one place where we do start to see some desire for a feature like this, is with functions that can act on both strings and bytes, and behave differently depending on the input. For example, we have Other than that though, the lack of modules hasn't been a major issue thus far, so it's unlikely this one example will make this worthwhile, but it is a data point for a potential future decision on this feature. (there's also the possibility that we'll differentiate between valid UTF-8 strings and bytes at the |
Now that we're cranking out more and more functions, I'm worried it'll become more difficult to know the distinction between all of them.
Take for example the newly proposed
to_level
andto_severity
. On their own, they make total sense, but when you put them next toto_string
,to_int
and the otherto_*
functions that convert to a concrete value, they can be confusing.A similar situation arises with functions such as
parse_aws_vpc_flow
andparse_aws_elb
.We've already started categorizing the functions in our Cue documentation precisely because the list of functions is becoming longer still, and you need some way to more easily find what you're looking for.
I propose we extend this categorization to the language itself, by introducing function modules.
The concept is simple:
Module
enum that has variants such asRoot
,Aws
,Syslog
, and more.Function
trait to include afn module(&self) -> Module
function.syslog::to_level(.foo)
, oraws::parse_vpc_flow(.bar)
instead.Root
module will stay as-is, so you'd still useto_int
,parse_json
, and other often-used functions.I'll leave it as an exercise to others to come up with the correct module names (I think the Cue files are a good starting point, and I'm sure @lucperkins has some good ideas for this list as well), but I do believe this would only add a small amount of syntactic noise to the language (especially since the most commonly used functions won't have a module prefix), while gaining a bit more structure in the ever-growing list of functions.
(note I used
<module>::<ident>
since it doesn't collide with other syntax we currently have, and it's also what I'm used to as a Rustacean (and it's not uncommon in other languages either), but we can entertain other forms of syntax for this)cc: @binarylogic @FungusHumungus
The text was updated successfully, but these errors were encountered: