-
Notifications
You must be signed in to change notification settings - Fork 2k
soaks on lhs of assignment #1642
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
Comments
Check out Coco's autovivification. |
Yep, Coco's I wouldn't mind seeing something similar in coffeescript, but I don't like that syntax. Just throwing out the first idea that came to mind, maybe a parametrised member access: |
Isn't |
@satyr: You're right, I didn't even think of that. |
To the contrary, I'm with Michael that autovivification would be nice, but I haven't seen a good syntax proposal yet. |
Autovivification--like its close cousin, destructuring assignment--is probably overly constrained by having to play nice syntactically with the overall language. I almost feel like CS should have an explicit mode for data-oriented code (where convenience of data transformations trumps all other concerns). At the very least, it would be nice to explicitly move in and out of autovivification mode. For example, at the top of a method, you might want all code to autovivify without any strange syntax, but once you get into the main processing, you'd want CS to generate code that fails hard when fields are messing. |
I don't get it. What was lacking with @satyr's suggested |
The problem with "(a.b ?= {}).c = 1" is that the syntax obscures the main intent of the code: you want to assign 1 to a.b.c (with autovivification as a side effect). The (?={}) syntax is hardly light--six punctuation characters and two extra spaces. If CS allowed you express it something like ":autovivify a.b.c. = 1", it would be more terse in terms of tokens, more human readable, and easier to type correctly. It would also be easier to turn autovivification on and off as you refactor the "convenience" up the call stack (letting lower-level methods fail hard if they aren't properly initialized). |
Modal autovivification is a bad idea. If that's what you want, we should have compiler directives and macros. |
I am not defending autovification, but to the extent that folks are gonna do it anyway, I'd rather have to read ":autovivify a.b.c = 1" than "(a.b ?= {}).c = 1" in other people's code. I firmly support compiler directives in CS, but my notion of a compiler directive might be different than yours. |
I personally don't mind I also think that |
I still haven't fully digested CS's mental model w/r/t destructuring assignment, existential assignment, and autovivification. The concepts don't seem to have an elegant unification under CS, but maybe they don't need to, or maybe they do, and I just don't get it yet. They seem like close cousins to me. |
Thank you, @vendethiel, for finding all related issues (actually, feature requests) and closing mine (really). Although this one is already closed for almost ten years already, I woud like to join and "refresh" the discussion mentioning that, for me, not having to declare a variable before it has a value assigned to it is a kind of a "autovivification", and if CS handles its variables this way, I see no reason for not behaving the same way for key-value pairs in objects, so no special compiler mode, directive or sintaxe should be needed to specify that autovivifaction is intended. For me, the absence of autovivification in CS signalled an inconsistent behaviour. At most, maybe turning off autovivification should be considered the exception, as it is the annotation of types on version 2.5.1. So, if @vendethiel or some of you guys enlisted as collaborators agree on my argument, maybe one of you would like to reopen this features request, or mine, or any one of the other related to them. |
It would be nice if this ...
did this ....
It is very intuitive, doesn't break anything, and matches soaks on rhs in terms of handling missing properties.
The text was updated successfully, but these errors were encountered: