Question: does anyone ever use __ as a variable name?

I know in Lua it is idiomatic to use _ as a throwaway variable name, and thus any other use should be avoided (i.e. you don’t want to use _ as a global variable name). I’m working on a Codea-specific library similar to underscore.js, and since I shouldn’t use _, I am considering using __ as the global name for the library.

Mainly I’m wondering, if I released this library, would the __ variable cause naming conflicts in your code?

I don’t use the double underscore myself and haven’t seen it used in any of the projects I have checked out. After doing a search for it in the forums here I found one project that may conflict with it.

The project above uses double underscore as the first two characters in some variables, so its not exactly the same as using just __. Not sure if that would be affected or not. Just thought I’d toss it in as a heads up since other people may be using the code from that project in their own projects.

I actually thought that the underscore was a special thing that avoided assigning a variable at all, saving on the memory and assignment time.

I just checked, and it is a genuine variable. I’ll not be so rigorous in using it in future!

Anyway, no I don’t know of using __ as a variable name.

I never use __ as a variable, some times a single _ if there are too many and I can’t think of a reasonable name…

I don’t use __ at all as a variable name either apart from for private vars when they’re not hidden with a closure. I usually avoid really short names they can get a little cryptic if there’s lots :slight_smile: If you want to protect against potential conflicts what about including a mechanism like jquery.noconflict() to unbind it?

Sweet, it seems like __ will be safe :slight_smile:

@XanDDemoX good idea :slight_smile:

@Slashin8r: variable names prefixed with __ will be ok. I want to use just the 2 underscores as a global variable name, since it’s short, has little chance of conflicting with external code, and because it borrows a lot from underscore.js:

__.bind(self, "doStuff")

@toadkick one problem I have with underscores is that they are difficult to type on the iPad software keyboard. Something to keep in mind (especially if you personally use a hardware keyboard).

@Simeon: That is a very good point. It had occurred to me, but I didn’t think it was that much of a pain until I just tried it (yeah, I use a hardware keyboard).

It’s enough of a pain that I’m definitely open to a new name that is more software-keyboard-friendly but still somewhat obscure. I’d prefer it to be no longer that 2 characters if possible. Here’s some ideas I’ve had so far:


Right now I’m kind of liking xe or xo. I could consider capitalizing the first letter as well, like Xe, though that will mean hitting the shift key.

Not knowing underscore.js and being a curious sort of fellow, I searched and found Is this the sort of thing that your library will do?

xe for xenon sounds … cool, but irrelevant! But then I’m not sure what underscores have to do with that library either so xe is as good as any and probably of the lot the most memorable.

I also like xe all in lowercase. Though it’s not as easy to type as ax (or xa) due to the relative positions of the keys.

@Andrew_Stacey: I looked at that one for reference, and also this one: There’s some good stuff there, but ultimately I decided to roll my own. I saw a lot of room for optimization (after all, an interpreted language on an iPad needs all the cycles it can get), and wanted to do some things differently than those did. In short: yes, that’s the sort of thing it does, but I’m more interested in it being useful and thorough than being a direct 1:1 port of underscore.js.

I’ve also borrowed the Events mixin from backbone.js, and deferred objects a la jQuery. I’ve added other things that are more specific/helpful for Lua/Codea (like timing/scheduling mechanisms), and removed/changed some bits from underscore.js that aren’t as relevant in Lua/Codea as they are in JS.

I’ve still got some work to do on it (mainly the chainable syntax that underscore supports), and I want to test and document it thoroughly, so I’m probably 1-2 weeks out from releasing it.

Really the name isn’t that relevant, as long as it’s easy to remember, easy to type, and short :slight_smile: Unless someone comes up with something better, the working name is now xe.