codex-storage / questionable

Elegant optional types for Nim
Other
116 stars 5 forks source link

Use `scope` instead of `block` #28

Closed markspanbroek closed 1 year ago

markspanbroek commented 1 year ago

Introduces a template called scope that can be used instead of block statements, to work around the issue that block statements can influence break statements.

See also:

c-blake commented 1 year ago

Looks good to me and tracks what Araq might put in std/sugar (someday) as per that discussion.

arnetheduck commented 1 year ago

might put in

we tend to put std-lib-candidates in https://github.com/status-im/nim-stew/ as a staging ground to ensure that anything we propose has been battle-tested and doesn't have additional gotchas

c-blake commented 1 year ago

It comes up often enough to be in stew (or std/sugar) for higher visibility if nothing else. It seems presently questionable has zero external dependencies. I could also see why @markspanbroek may prefer to keep a copy here so questionable stays a leaf dependency.

arnetheduck commented 1 year ago

stays a leaf dependency.

this is a fine reason for personal projects - however, maintaining Nim as a preferred language becomes more expensive when this approach is taken for status-developed libraries, ie when two teams end up developing the same libraries with their own personal syntax preferences, this is a cost for us that we prefer to avoid - we strive to cooperate on finding a common ground recognising that maintenance, testing and audit by far make up the most significant cost compared to the rather small startup cost of an initial 80/20 effort - ie it's cheaper perhaps for the individual developer to go down the NIH route in the short tertm, but not for the Nim teams as a whole.

c-blake commented 1 year ago

A few more corner cases -

let z = (scope: 3) # EDIT: parsed as a tuple constructor w/field name "scope"
echo z  # "(scope: 3)\n"
echo (scope: 4) # both here & `z` above (block: [34]) leads to just [34]
# echo scope: 5 # does not compile, yet `echo block: 5` works.

Maybe at least worth documenting the difference from block. Might be fixable with a macro instead of template. Not sure.

markspanbroek commented 1 year ago

Thanks for your comments; I have opened a PR in Nim to get some broader feedback on this code: https://github.com/nim-lang/Nim/pull/20785. It includes documentation that about the different parsing of block and scope.

markspanbroek commented 1 year ago

Now that break without a label is officially discouraged, I think we can close this PR.