top | item 38798358

(no title)

mrblampo | 2 years ago

First example seems odd? The author acknowledges that the two proposed alternatives (printing "<function exit>" or actually exiting) aren't great. The fact that the Python REPL provides a helpful hint seems like extra effort to make your life easier. This is especially notable given that in the next example, the author's complaint is about a command _not_ providing special guidance about the thing the user is probably trying to do.

discuss

order

dale_glass|2 years ago

I'd have done both the hint and the actual result. Like this:

    >>> print
    <built-in function print>
    >>> exit
    <built-in function exit>
    Hint: Use exit() or Ctrl-D (i.e. EOF) to exit
    >>> 

This way, it does do the thing you literally asked for, but also does help a newbie out.

bvisness|2 years ago

Yes, I completely agree. If you want to teach the user the rules, then you follow the rules. The problem with the Python example is that they DID special-case it, but in an unhelpful way.

dmurray|2 years ago

It should print the first to stdout and the second to stderr. That's completely consistent with how stdout and stderr are usually used.

The regular Python REPL doesn't distinguish between stdout and stderr (perhaps it should!), but you can embed it in things like Jupyter notebooks that do.

ssgodderidge|2 years ago

> does help a newbie out

… or a long-time dev that switches languages fairly often :)

IshKebab|2 years ago

But really it should just exit. There's really no reason why it shouldn't.

I think telnet does something stupid along the same lines "I know you want to quit but please ask address me as Sir first".

pluc|2 years ago

Yeah. "I know it's not right, but it's not totally wrong and probably better than not doing anything" actions as maddening as the behaviour he describes. A world where that's the standard would be chaos.

When you work with _precise_ systems, they sometime take _precise_ input to work. That's kinda just part of the job.

phs318u|2 years ago

Except in the case of the 'exit' clearly this is accepting and parsing imprecise input in order to guide the user. If the code wasn't looking for 'exit' in order to correct the user (to use 'exit()'), it would just spit out some other error for 'I don't know what you're talking about'. Instead, they actually detect the intent by specifically coding for it... and then ignore it anyway. That's bloody minded.

imron|2 years ago

> A world where that's the standard would be chaos.

We saw this play it with web browsers in the late 90s early ‘aughts where they’d do their best to render what they thought you meant if your html was wrong, and it was indeed chaos.

Strict systems with strict inputs makes for a better overall ecosystem.

devjam|2 years ago

> The fact that the Python REPL provides a helpful hint seems like extra effort to make your life easier.

I agree; Python is actually helping you out here, since just typing `exit` doesn't actually call the callable.

Also, Python being Python, while not recommended, there's nothing stopping the user from assigning to `exit` then printing it in the repl:

    >>> exit = 42
    >>> exit
    42
What would the author expect Python to do in this instance?

MichaelDickens|2 years ago

I think the current behavior is worse simply exiting. The only concern with exiting when the user types "exit" is that perhaps the user actually wanted to see the value of the `exit` function. But the current behavior doesn't show the value of the `exit` function either, so it's useless for that use case.

nneonneo|2 years ago

Yeah, and it’s also useful to teach newbies about the usual syntax for doing things rather than introducing special-case magic. It would be _weird_ to just quit after writing a bare “exit”.

gizmo|2 years ago

ipython intentionally diverges from the regular python REPL. It just quits like you expect without crying about it.

andy99|2 years ago

Vim iirc has a similar hint telling you to exit when you try something that should exit. I don't remember how it's triggered, ctrl-q maybe (edit, ctrl-c). I see the point, if you know what someone is trying to do, better to just do it, or ignore it, not give a condescending "nudge". Though personally the hint doesn't bother me.