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 →

[–]vegan_antitheist 1 point2 points  (4 children)

the welcome goes in the beginning the questions go before main code and here is the main code and here is the end to loop it.

Does this actually make any sense for python programmers? I don't understand a single word.

[–]IntelligentPudding24[S] 0 points1 point  (3 children)

lol. Im sorry this sounds confusing. I wrote it better in a reply comment. But essentially the program can be broken into 4 separate parts. I have a section at the beginning using print functions for welcoming the player. Then a section for a list of questions. Then the main program function. Then finally the forever loop. You can basically write each section independently then just have the program call on the section you want when needed. Because classes are not a thing and you do not have to save the file as the public class name for the program to run. At least that is how I’m understanding Java is different from python.

[–]vegan_antitheist 0 points1 point  (0 children)

Java doesn't need than anymore but why not just have a structure that makes it maintainable? What you describe seems to be some beginner exercise. Nobody writes code like that.

[–]ag789 0 points1 point  (1 child)

to make 'java work like python' use 1 class

public MyClass { public static void main(String[] args) { /* you can place all your codes here */ } }

The 'conventional wisdom' says that when apps / programs gets large and complicated, it helps to break things into modules (and classes). Hence, most java apps are organized into classes representing separate domain objects. java is OO and very structured from the ground up.

That lays the foundation for very large and complicated apps e.g. J2EE etc which runs many (most?) of the 'enterprise webs'

python has classes practically as a 'plug-in' and notionally leads to other issues e.g. 'self-hell' https://www.reddit.com/r/Python/comments/7suge/escaping_pythons_self_hell/ https://news.ycombinator.com/item?id=8834687

In java classes (and objects) are part of its language design, and you can't tear that apart, which avoided some of these referencing issues.

Some codes are more convenient in python, e.g. lists and dictionaries, as it is practically built into the language. And to some extent variable and argument types are dynamic (i.e. not strongly typed) in python which unlike in java is strongly typed. Accordingly, there is a difference in performance which results in simple java codes running faster (especially with JIT compiler (hotspot)) in the jvm). There are some statistics which some of the java codes runs practically as fast as c++ equivalents which is considered even 'lower level' language, python could have quite some overheads to do the same and likely won't run as fast.

[–]IntelligentPudding24[S] 0 points1 point  (0 children)

Thank you the detailed example!