I'm a java programmer, but now entering the "realm of python" for some stuff for which Python works better. I'm quite sure a good portion of my code would look weird for a Python programmer (e.g. using parenthesis on every if).
I know each language has its own conventions and set of "habits". So, from a readability standpoint what are conventions and practices which is "the way to go" in Java, but are not really the "pythonic way" to do stuff?
It's got incredibly concise syntax and is super easy to learn. Python code often looks like a pseudo-code; you tend to focus more on writing your logic and less on the intricacies of the language. That's one of the main reasons for its popularity, especially in the world of data science.
Python has an extremely simple syntax compared to most of the other programming languages. With Python, you do not even need brackets to define a code block. A simple indentation will do the job. Owing to its simplicity, Python is one of the easiest languages to learn.
Predicates not only improves readability but also enhances reusability. If you find yourself repeating the same "condition" in multiple places in your code, consider extracting it out as a Predicate and giving it sensible name. By doing so, you also documented your condition. if( user.
It is easier to make the transition from Java to Python or any other language, but the reverse is a bit difficult because of Python syntax is a bit different than most other popular programming languages.
There's no simple answer to that question. It takes time for your code to be "Pythonic". Don't try and recreate Java idioms in Python. It will just take time to learn Python idioms.
Take a look at Code Like a Pythonista: Idiomatic Python, Style Guide for Python Code and Python for Java Programmers (archived).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With