larskanis/eventbox

`€value` notation is massive problem

Opened this issue · 5 comments

@SamSaffron:
Hi Lars,

I had a quick look at eventbox, my #1 piece of feedback is that
€value notation is massive problem. Most non european keyboards
don't even have an easy way of entering this. Highly recommend you
come up with something else if possible, even an extra param, I don't
know. enq(val, copy: true) or just enq(val.dup)

Maybe an alternative could be to wrap arguments into some special monad that sneeks the value past the sanitization. The obvious downsides are that this has to be done when calling the method, so it'd be a bit less convenient.

Thank you both for your reviewing!

I did a bit of google'ing before picking the € sign for this task. The following Wikipedia topic (section "Entry methods") got me the impression, that almost every keyboard layout has a shortcut for the € symbol: https://en.wikipedia.org/wiki/Euro_sign . Isn't that true?

Just to clarify: Marking values as to be wrapped not only works with positional arguments but also with optional and keyword arguments as well as splat and double splat variables. They all can be marked on a per argument basis.

Alternative solutions to the € symbol could be:

  1. Use an ASCII character to mark the argument as to be wrapped: We could use _value, but _ already has the specialty of not being warned if not used. So this would be an unwanted implication.
  2. Use an ASCII character sequence: All other ASCII characters either can't be used or have a special meaning already in ruby. So we might use a sequence like w_value or wrapped_value. But it doesn't look intuitive to me.
  3. Use of other Unicode characters: As far as I know we could use any Unicode character as a starting character, since they don't have any special meaning. German keyboards for instance have °, § and µ as first class symbols on the keyboard. But I think they aren't any better than the symbol when it comes to international support.
  4. Interpret any starting Unicode character in the argument name as an indicator: Probably any keyboard around the world has some Unicode character on it, so that this improves the writeability of code but decreases the readability, since it's confusing if everyone picks a different character.
  5. Use a different way to mark arguments as to be wrapped: something like async_call :value, def enq(value)
  6. Adding the wrapping mark to the method signature (as proposed by @SamSaffron): Something like async_call def enq(value, copy: false). This mixes Eventbox options into the users method signature, so that it's difficult to divide them apart.
  7. Explicit wrapping of arguments (as proposed by @DarkWiiPlayer): This is already supported by Eventbox#shared_object (although they don't have exactly the same semantics). However the intention behind €-arguments is just to avoid wrapping on the caller side.
  1. looks nice, but I think it would look a bit nicer if the symbols were wrapped in an array, so the square brackets would 1. visually delimit it some more and 2. make it a bit more intuitive that this has to do with the arguments, as square brackets are used throughout ruby for similar purposes (like calling lambdas, etc.)
async_call [:value, :something], def foo(value, bar, something)
  # do some stuff here
end

@DarkWiiPlayer Yes that doesn't look too bad. I added a comma to my and your example, which looks ugly, but is required to make it valid ruby syntax. Another variation of this proposal is using a hash:

async_call value: :wrap, something: :wrap, M: def foo(value, bar, something)
  # do some stuff here
end

This is more verbose, but also more expressive and could allow other kinds of argument processing beneath deep copies and and argument wrapping in the future. Something like :unsafe passing of values (for performance etc).

The uppercase key M: def foo avoids possible conflicts with argument names (arguments must be lowercase).

gjvnq commented

How about using $EUR$ as a pentagraph for ?

It's a bit like the trigraphs in the C language but in a more readable form.