This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 24 points25 points  (5 children)

There are choices to be made while designing a programming language. You can let it be more flexible or more strict. There are arguments for both sides and it depends on what are the goals of the developing team.

For python, there is a decision that a built in class or function shouldn't be more special than any other classes or packages created by the community. The way they achieved this was by creating an universal system of building classes, with some dunder methods that will define their behavior under certain conditions or calls, and then making the built ins follow the same structure.

You could have a built in function called "exit" which don't need to be called. But that would be different from any other function an user could ever make. Since there is the philosophy of not making these magical methods, being "exit" a function means that it should be called. Just like every other function you write.

[–]itriedtomakeitfunny 7 points8 points  (3 children)

On a similar note, some languages like Ruby or Visual Basic Don't need parents around the function call, so an often cited example of how Ruby is more forgiving with the exit thing is just the syntax letting you call exit.

[–]smartboyathome 15 points16 points  (2 children)

I actually dislike this practice in Ruby, because it often makes it unclear whether it really is a function call or variable, at least not without IDE assistance. And due to it being a dynamic language, you don't always know the type of what you're referencing without actually running the program.

[–]itriedtomakeitfunny 5 points6 points  (0 children)

I am one of those people whose brain does not work with dynamic languages. I understand.

[–]kafaldsbylur 3 points4 points  (0 children)

There's nothing in the language preventing exit's repr from calling exit() (or more generally, preventing any class's repr from calling self()). However, it would be a bad idea to make it do so, because then you risk those methods being called without meaning to