Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Php supports kebab-case variables:

    ${"variable-name"}=123;
Isnt it beautiful?


I agree that kebab variables aren't to my taste either, but I am partial to the notion of kebab-case keywords that I encountered in a JEP draft [0]. It suggests expanding the keyword vocabulary with a form that is otherwise invalid syntax, similar to how java treats module-info.java and package-info.java as valid files, but rejects any other hyphenated java class filename.

[0] https://openjdk.org/jeps/8223002


Pretty ugly. Scala does it like this:

    var `variable-name` = 123
    `variable-name` = 456
Looks much cleaner to me.


So does python I suppose

    locals()["kebab-case"]=123


Perl, too. (Probably not a coincidence.)

You can also put a newline in a variable name if you really want. Or a 0 byte.

Here's a demo. I've used the debugger because its "X" command can print the true name of the variable:

    $ perl -d -e 1

    Loading DB routines from perl5db.pl version 1.60
    Editor support available.

    Enter h or 'h h' for help, or 'man perldebug' for more help.

    main::(-e:1):       1
      DB<1> ${"variable-name"} = 123;

      DB<2> ${"variable\nname"} = 456;

      DB<3> ${"variable\0name"} = 789;

      DB<4> X ~variable
    $variable^@name = 789
    $variable^Jname = 456
    $variable-name = 123


How many languages support kebab case with any Unicode dash that isn't the ASCII one? :)


Probably any language that supports Unicode identifiers.


F# allows arbitrary names within double-backtick identifiers. The following is a valid declaration, where I've used a hyphen, en-dash, and em-dash:

    let ``foo-bar–baz—quux`` = 3


Agda does, but it also supports a plain ascii hyphen in identifiers. It allows operator characters inside identifiers and requires spaces around operators otherwise (as proposed in the article). So you can use x-y as an identifier:

    x-y : ℤ → ℤ → ℤ
    x-y x y = x - y
The Agda community also heavily uses unicode characters. I've even seen a unicode colon used for a custom syntax because the ascii colon was unavailable.


> The Agda community also heavily uses unicode characters.

Wise move.

Finally a language from the 21 century.

Still sticking to ASCII is madness. Especially as most people on this planet don't use ASCII as their native char set.


At the moment, the only one I know for sure is Agda.

I suspect java would work as well, not sure about golang unicode var naming.


play.golang wouldn't let me use figure (‒, U+2012), endash (–, U+2013) or emdash (—, U+2014) in a variable name directly.

But then the spec[1] says that only code points characterised as "Letter", an underscore, or characterised as "Number, decimal digit" are valid.

[1] https://go.dev/ref/spec#Identifiers


Coptic Small Letter Dialect-P Ni should work, looks like a hyphen.

Go Playground: https://go.dev/play/p/kxgOcEWsznz

https://www.compart.com/en/unicode/U+2CBB


Oh, neat catch!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: