wren-lang / wren

The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.
http://wren.io
MIT License
6.86k stars 550 forks source link

Suspicious design around the max length of method names and max count of method parameters #1111

Open xiaoxiao921 opened 1 year ago

xiaoxiao921 commented 1 year ago

I have to interop with legacy C code that have some functions which have their names longer than 64 characters and have sometimes more than 16 parameters. if one of the main use cases for such projects is to interop with some parent hosting language code, why was the limit not equal to that parent language?

mhermier commented 1 year ago

Because 64 characters and 16 parameters should be enough for most use cases, and having more than this "should" be considered a bad practice. So wanting to reach the 4k characters limit or 127 arguments limits of C is futile.

From my point of view the interoperability is never a main use case, but more an unfortunate requirement. I mean no sane language implementation wants you to escape from their computational model, so implementors can't reason about what is going on. Having an interruption (of any form) in the language to do interoperability with some host bindings, is always a source of fragility.

For your specific use case, there is some possibility to mitigate the issue to some extents:

mwasplund commented 1 year ago

I was also very surprised by this when porting over some code. I have large container classes that move a large number of function parameters into a single class for easy passing around a lot of options and the constructor should contain all the values so I can make the struct read only.

If there is no physical/performance reason for this limitation I would prefer if it was removed. Simply having a limit because it is a bad practice is not a good reason because there are always exceptions to the rule. At a minimum this limitation should be well documented so it is not a surprise to new users.

PureFox48 commented 1 year ago

I can't say I've ever found these limitations a problem but a possible workaround would be to pack all parameters after the 15th into a Wren map or list.

You can then unpack them from the host and call your constructor normally.