5 ms·
You don't have to do this, though. You can have an entrypoint.py that simply calls `main()` without that if. You don't even need to have modules if you want to,
by abdusco 3y ago
You don't have to do this, though. You can have an entrypoint.py that simply calls `main()` without that if. You don't even need to have modules if you want to, so you can write your functions and call them right after.
- wredue 3y agoSo in python, you need to understand not 1, but at least 3 different versions of “an entry point”, and to you, this is “less cognitive load”? I had the same issue with Swift. There’s 30 ways to write the exact same line of code, all created by various levels of syntax sugar. Very annoying to read, and even more annoying because engaging different levels of sugar can engage different rulesets.
- elevatedastalt 3y agoYou don't "need" any of the entry points when you are beginning Python. print("Hello World") is a perfectly valid and runnable Python code. And when you are working on a small part of a large code base, you usually don't care about __main__ either. So yes, it's complexity but it's complexity that you don't need to encounter right away. Python is intuitive off the bat. public static void main(String[] args) is not.
- int_19h 3y agoInterestingly, C# (which began its life as a sort of Java/Delphi crossover syntactically) agrees. It used to be that you had to write: class Program { static void Main() { Console.WriteLine("..."); } } But these days, we can just do: Console.WriteLine("...");
- rotifer 3y agoFWIW, in an upcoming version of Java you'll likely be able to do this: $ cat Hello.java void main() { System.out.println("Hello, world!"); } $ java --enable-preview --source 21 Hello.java 2>/dev/null Hello, world! $ This is currently a preview feature in Java 21 and 22.
- xigoi 3y agoPython has no concept of an “entry point”. You just run the program from start to end. What’s hard to understand about that?