this post was submitted on 11 Dec 2023
1168 points (98.9% liked)
Programmer Humor
32558 readers
489 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
“exit”
✈️: Use exit() or Ctrl-D (I.e. EOF) to exit
I mean if they can see that we type exit and show us this message, why could they not just start the exiting when we type exit?
Because exit might be a variable you use to determine if you should exit. exit() is a function that actually does the exiting.
It’s the difference between pointing at a jogger and saying “run” and actually running after them.
If you have a variable called
exit
you've overwritten the function in that scope, and won't be able to execute it.e.g.
Reminds me of setting pi = 3 in my friends matlab subroutines in school.
wow it does do that. cool
Guessing at what the programmer wants instead of implementing consistent behaviour is what Javascript does. Do you want Python to become Javascript?
Just once I want
'1' + '2'
to equal'3'
. Is that so much to ask?You want to remove the string concatenation operator? Cause that'll do it
I think every language needs a
please
operator, which acts to enforce human expectation of a statement:I kinda like that
Yes. Yes it is.
This is the code (Github link):
What happens is that the python repl calls
__repr__
automatically on each variable/statement that you type into the repl (except assignments e.g.x = 1
). But this basically only happens in the repl. So "executing" onlyexit
wouldn't work in a python script as it is not calling__repr__
automatically, so better you learn how to do it right than using justexit
in your python scripts and scratching your head why it works in the repl but not in your code.Because python has strong opinions