5 ms·
I disagree. Working through each keyword until you understand the full signature felt great when learning. It’s the Python if __name__ == __main__ trash that w
by jimbob45 2y ago
I disagree. Working through each keyword until you understand the full signature felt great when learning.
It’s the Python if __name__ == __main__ trash that was the worst. You’ll never understand it and it doesn’t fit in the language.
- Comma2976 2y agoIn my humble and correct (trumping anyone else's) opinion, they are both garbage.
- Quekid5 2y agoYou're not wrong... but for different reasons :)
- exe34 2y agoyou don't need it until you get to importing modules. hello world in python is literally just print("hello world!")
- dvdkon 2y agoYou don't even need it afterward, unless you want a file to be both an importable module and an executable script. Arguably you could be a happy Python programmer without this capability.
- jraph 2y agoI never understood why people bother with this when writing their python main file, which is never going to be imported because it doesn't make sense in the first place.
- elteto 2y agoBecause I dislike interspersing executable statements at module level with function definitions. I’d rather have all code live inside functions and have one main entry point for the script. It’s just a personal preference, nothing wrong with not doing that though.
- jraph 2y agoBut you could have a single main() call without the if statement, couldn't you?
- telotortium 2y agoREPL-based development. You might be developing a script, but notice a bug. If you import your script as a module, you can run the function you’re debugging, figure out what’s wrong, edit the file, and then reimport the module (using importlib.reload).
- jraph 2y agoOkay, that's quite convincing, thanks!
- usrusr 2y agoIsn't that hugely elaborate compared to languages where top level statements are a function, functions return their last statement, and the return value of the entry function is sent to stdout unless invoked in special ways? That print() around the "hello world!" does not appear any less superfluous than all the public static void you can throw at a javac 1.0
- driggs 2y agoYou mean a language like... Python? >>> 'hello world' 'hello world'
- usrusr 2y agoExactly like that (well, almost exactly: if python includes the quotes then it's not really equivalent to print()). The point was that by including that print(), people already do say yes to including "like you'd do in a real program" ceremony in their supposedly minimal examples.
- dajtxx 2y agoPython seems to have started with 'why do those other languages have all this trash' and then spent the time since then learning why and coming up with worse versions. I use python a lot these days, and like it, but it's pretty funny seeing stuff like the above and type hints. I hate not knowing what types a function takes and returns.
- nayuki 2y ago> Python seems to have started with 'why do those other languages have all this trash' and then spent the time since then learning why and coming up with worse versions. This seems true to me too. Examples: * if __name__ == "__main__": main() * Private members being marked by convention with leading underscore (e.g. def _foo()) instead of being a language feature * @staticmethod as a decorator instead of being a language feature * Duck typing vs. abstract base classes * Static type hints got retrofitted to the language gradually, one feature at a time * Reference-counted garbage collection seems to be more deterministic than tracing garbage collection and ensures that unreachable resources have their finalizers run as soon as possible... except it's not true * Having a GIL instead of being truly multi-threaded from day one * Various OOP concepts that are much better explained in Java than Python: __eq__(), __hash__(), monitor wait() and notify(), object finalizers, thread safety, weak references * Distinction between str and bytes. This is the biggest change from Python 2 to 3 and caused a lot of incompatibilities. Java separated String and byte[] from the start (though the use of UTF-16 is unfortunate).
- Quekid5 2y agoThe whole switch/pattern matching thing is a true abomination borne from: Well, things in statement position can't be expressions (or however Pythonistas might phrase it), so clearly switch/pattern matching must be a statement... It's such an own goal and undermines the main point of pattern matching. (I do realize that there was opposition on this, but that the Clearly Wrong side won out is baffling.)
- nayuki 2y agoYeah, it's a shame for Python. I am extremely impressed that Java 14's switch expression ( https://openjdk.org/jeps/361 https://openjdk.org/jeps/361 ) is a generalization of the switch statement (since Java 1.0); it's like they took a page from Rust's language design. I have found the switch expression to be quite useful in my work.