by legobridge on 7/18/23, 6:56 PM with 53 comments
I've worked extensively as a software developer in Java before, so I am aware of the many things that go into writing "real" code (as opposed to what one writes for Leetcode or even an academic project), from little things like using the right annotations, to bigger ones like dependency injection frameworks.
I've used Python for Leetcode, scripting, isolated ML work, writing little games, etc., and I've read and practiced much of PEP8, so it's not that I write bad Python code. But I do feel that I could be doing so much better (since I've done better in Java) and I'd like to get to that level of proficiency as soon as I can.
In that vein, I'm looking for any resources that have worked for any of you and you think would be suited for me. Thanks!
by serjester on 7/18/23, 9:23 PM
Clone the package, run the tests, break the tests and try adding functionality. You’ll learn a lot - I know I did when I was starting out.
I’d also recommend checking out Fluent Python.
by Aperocky on 7/18/23, 9:53 PM
Don't stretch inheritance where where they are not needed - avoid factory classes unless you know for certain that it's called for.
Use pythonic stuff like @decorators and enjoy functions as first class objects.
Finally, try to avoid using an IDE. This keeps your files and folders structures simple and organized out of necessity. In Java it's almost impossible, but it's very possible in python as it removes so much verbosity.
by extasia on 7/19/23, 8:35 PM
Constantly circle back and refactor. Ruthlessly.
Same as in any lang, focus on data structures and algorithms (business logic is algorithmic) rather than the implementation, at least to start with. Get it working (usually easy in python, it's so dynamic!), make it good, make it fast. A good data model makes coding a joy. If your data structures suck every little thing will accrue friction. This is a red flag that you chose the wrong data model.
Source: 1000s of python hours in engineering and research roles
by nhgiang on 7/18/23, 7:46 PM
Learn all about pytest and how to use its fixtures well.
Mypy for use in conjunction with type annotations for static analysis.
Packaging: Python-poetry.org
Personally, I recommend Deal (design by contract) and/or Hypothesis (property-based testing) libraries, too.
Controversial opinion: Stay away from Flask and all of its derivations. That framework is badly designed. Learn from Django instead.
by speakspokespok on 7/19/23, 1:46 AM
by brauhaus on 7/18/23, 11:10 PM
I mean, so many people want to write production-level code and yet never took the time to actually read the production-level code right in their faces!
Even the standard library is worth seeing. Next time you import pathlib.Path, right click it, select "See Definition" and go find out how the sausage is made.
Obviously you are not expected to understand _everything_. But you will be surprised you will understand a bit. And then a bit more. And you will start getting comfortable dealing with production-level code. Soon you'll start writing it yourself.
This little habit skyrocketed my Python game
by anoy8888 on 7/19/23, 3:41 AM
by anyfoo on 7/18/23, 9:21 PM
mypy brings some of the sanity back.
by ezedv on 7/18/23, 9:48 PM
by mydriasis on 7/18/23, 7:14 PM
TDD is very easy with Python because the unit testing framework is built in -- I'd suggest writing tests for just about everything you do.
Additionally, the typing system is expanding all the time. Make sure you're adding type annotations where / when you can; even lightweight ones like TypedDict help.
by SushiHippie on 7/18/23, 9:07 PM
I enabled nearly all the rules it has available. And I've learned so much from it.
[0]: https://beta.ruff.rs
by Mawr on 7/19/23, 4:04 AM
by AussieWog93 on 7/18/23, 10:48 PM
If you don't have a colleague, GPT-4 is an acceptable substitute.
by more_corn on 7/19/23, 12:01 AM
by gte525u on 7/18/23, 10:01 PM
Where python falls down is the flexibility - if you aren't careful it's write only.
by mharig on 7/19/23, 1:10 AM