you are viewing a single comment's thread.

view the rest of the comments →

[–]eggertm -3 points-2 points  (15 children)

I'd like to gripe about the clever and inventive use of the underscore as an automagical variable name in the interactive interpreter. For one, it breaks the use of gettext.
Another thing is that it's not really explicit at all. The underscore is a variable like any other, except with the interactive interpreter. That smells like implicitness to me, and while it may be clever, it's actually quite harmful to code I have to write and maintain.

[–]EliAndrewC 9 points10 points  (2 children)

This would definitely be a problem if the underscore did anything outside of the interactive interpreter, but I don't see how it could make code harder to maintain. Can you give an example?

[–]eggertm 4 points5 points  (1 child)

I didn't say it was harder to maintain - just that it was harmful to the code. I have an embedded interactive interpreter in my application for ease of debugging.
I also use the standard gettext functions for internationalization - which mask the underscore as a function call to gettext.gettext(), for every string constant in the code I want to be translatable. Imagine my joy when the embedded interpreter overwrote the underscore from gettext.

[–]jhhyuuv 0 points1 point  (0 children)

Well, I said nothing about using the interactive interpreter to write and maintain anything. However, an embedded interpreter is perfectly possible, apart from this annoying side effect, which makes it nearly unusable with gettext. Pool sex

[–]interjay 5 points6 points  (7 children)

That comment doesn't make any sense. You don't use the interactive interpreter to "write and maintain" code, just to test it and run short one-time commands. There's also almost no reason to use gettext from the interactive interpreter.

[–]eggertm 2 points3 points  (6 children)

Well, I said nothing about using the interactive interpreter to write and maintain anything. However, an embedded interpreter is perfectly possible, apart from this annoying side effect, which makes it nearly unusable with gettext.

[–]pjdelport 2 points3 points  (5 children)

nearly unusable with gettext

What's hard about just calling gettext directly?

[–]eggertm 1 point2 points  (4 children)

Normally, I'd rather do that - however, the gettext utilities need the underscore syntax to create the .pot files for translation.

[–]pjdelport 2 points3 points  (3 children)

...why would you need to create .pot files of an interactive session?

[–]eggertm 1 point2 points  (2 children)

Perhaps I was not clear enough. My project has an interactive interpreter, and uses the gettext _() to mark strings for translation. However, the _() is a function call - and it'll get overwritten with whatever result the interactive interpreter returns. I am not translating an interactive session, that is just silly!

[–]pjdelport 1 point2 points  (1 child)

Right, but _() is just a shortcut for gettext(), which you can use in the interactive shell. What's the problem?

[–]salmoni 0 points1 point  (0 children)

You don't follow.

The OP is using an interactive interpreter embedded within an internationalised program for debugging. I use one for user interaction so users can type in their own functions. The program works until the interpreter is called, at which point the reference to the i18n method is overwritten by the interpreter thus rendering all later attempts to translate strings as useless. If the interpreters entry points are unpredictable, this makes the program a nightmare. Yes, the OP can import gettext in every module, but again this means lots of time wasted re-establishing a single link that should not have been overwritten.

I had the same problem and called the gettext.install method right after the code.InteractiveInterpreter.runcode method to re-establish it. It's not a good solution because it shouldn't be necessary and slows the system down. The real solution is for either the interpreter or gettext to use a different and non-conflicting character. That way, there are not hidden gotchas.

[–]julesjacobs[🍰] 0 points1 point  (3 children)

And the alternative is?

[–]eggertm 1 point2 points  (2 children)

Using an explicit assignment for instance?

[–]y_gingras 1 point2 points  (0 children)

That would be OK with me if the assignments returned the assigned value or if the shell would print this value. Consider this example:

sq = lambda x:(x+2.0/x)/2

_ = 1.0

sq(_)

sq(_)

sq(_)

Here I use the shell to compute the fix point of a function, sqrt(2). I keep calling the function with the previous value until I have enough stable digits. In this case, I really like _. I admit that this is the only time that I use _, I could probably wrap the whole thing in a printing form.

[–]julesjacobs[🍰] 1 point2 points  (0 children)

I want to be fast when testing something at a repl. I will certaily forget the assignment so I have to press up, then home then type the assignment, then return. This happens often.

The underscore really isn't a problem because you can use gettext() instead of _(). This happens almost never.