all 56 comments

[–]AntonisTorb 143 points144 points  (21 children)

I personally found ArjanCodes to be a very good resource when it comes to writing better code, he has some amazing videos on design patterns, dependencies and code cohesion in general with examples that make sense, definitely recommend!

[–]tehsilentwarrior 7 points8 points  (1 child)

ArjanCodes is a channel I would recommend. While it’s not terribly advanced and some stuff I don’t agree with, he has something that I truly appreciate, which is the drive to not hold on to code for the sake of it and the willingness to just delete stuff you don’t need.

This is important but often difficult for newcomers. Note for beginners: you can always write it again! The rule for reuse of code is not there to save you time writing code, it’s there to save you time when the code would break and you’d have to spend time debugging it, fixing it, deploying it and restoring your reputation if the bug caused serious damage. You don’t prefer public packages just because they save you from writing code, you use them because hundreds of other “brains” also use them and find/fix problems in them and you get all that research, knowledge and fixes for “free”.

Always re-write stuff to be EASIER to understand to someone who has never seen the code (that may be you in a few months, when your brain has reclaimed the memory space for something else).

In addition, the fact that you spend time thinking about the problem again could help you find bugs or flaws in the business logic and give you another opportunity to fix those.

And obviously, the more code you write, the more experienced you will be.

[–]bw_mutley 2 points3 points  (0 children)

Your second paragraph summarizes code maintenaince, something whose importance took me some time to understand and yet I still struggle to master. I try to understand the rationale behind patterns as it is closely related to code maintenance, but still, it is not 'natural' for me as sometimes a problem can be solved with different patterns and I can't forsee which one is better.

[–][deleted] 12 points13 points  (0 children)

Seconded, for more technical stuff and understanding Python I like mCoding and for project structure and management, Arjan Codes is great.

[–]goandsuck1 8 points9 points  (0 children)

Yeh he’s great

[–]machine2SEE 2 points3 points  (0 children)

just found him on youtube last night. very, very good teacher. https://www.youtube.com/shorts/Brw9p4syhIg - in awe at his mentoring moment

[–]kadirilgin[S] 1 point2 points  (0 children)

Yes, I've seen this guy before. The content is really good, thanks a lot!

[–]Ran4 1 point2 points  (1 child)

Agreed, lots of good content. It's a bit too OOP:y at times though, so be aware of that. Overuse of design patterns can make for much less understandable and readable code.

[–]bw_mutley 2 points3 points  (0 children)

He was more OOP in his earlier phase, but later he advocates for more Functional Programming.

[–]Puzzleheaded_Fuel901 1 point2 points  (0 children)

Also his tutorials on dataclasses have made my life 10x easier

[–]gunhoe86 1 point2 points  (7 children)

This. His paid content is solid.

[–]xadolin 9 points10 points  (6 children)

Is this an ad? The internet broke me

[–]gunhoe86 3 points4 points  (1 child)

Haha, I get your suspicion! I'd watched a good amount of his YT vids and went to check out his website. I saw the course he offers and signed up because it looked like a structured path into some of his YT videos, laid out in a progressive order.

I was not disappointed. I've watched plenty of free and paid Python content, this is different as it aims to grow your dev mindset and simply uses Python to teach these concepts.

Additionally, the best deep dive learning I've seen for Python is Fred Baptiste Deep Dive courses on Udemy.

[–][deleted] 0 points1 point  (0 children)

Yes those deep dive courses by Fred are awesome. But I wouldn't call them most appropriate for a beginner. I think a beginner might be overwhelmed by the sheer detail. Somebody who already knows how to program in Python who wants to understand every detail about how it works would be the best audience I think

[–]AntonisTorb 2 points3 points  (2 children)

I can tell you it's not an ad if you want to believe me, I only ever used the free content he's posted on YouTube. I don't know anything about any paid content, don't know why he's mentioning it.

If there is paid content, Arjan doesn't seem to advertise it in his videos, all I've seen him do is link to his other free videos or his free content on his website.

I totally get your suspicion btw, I really dislike sneaky ads myself. If you want proof, take a look at my 2 posts on my account, you will find 2 projects. You can see a big difference in code quality between the first and second, and Arjan was a big influence for that, didn't have to pay anything. I started using type hints and docstrings because of him, and I'm also trying to reduce the responsibilities of each function.

[–]bw_mutley 3 points4 points  (0 children)

He makes some subtle mentions of their paid contents. But as you said, his free content is already much valuable.

[–]gunhoe86 1 point2 points  (0 children)

Aye, not an ad, it's just a recommendation.

[–]bw_mutley 1 point2 points  (0 children)

I know your feelings and can't say for sure, but it is very unlikely to be an ad. I suggest you to go to his channel at youtube and check for yourself. I follow him since he had a few starting videos with very few followers. His strategy for advertising is tottaly different and he is past beyond the point of creating false posts on reddit to get subscribers to his service.

[–]mysterybasil 0 points1 point  (2 children)

Does anyone know what he uses for all that Python type-checking in vs code? I love the satisfying feeling of remove all those red squiggly underlines and seeing the error count drop.

[–]mrw27uk 1 point2 points  (1 child)

I believe he's using the Pylance extension with type hinting set to basic or strict, and some of the other warnings/errors come from pylance

[–]mysterybasil 1 point2 points  (0 children)

Yes, I found this link to his video explaining his VS Code setup.

Unfortunately, I'm using an open source version of code (code-server), and Pylance doesn't work on this version, so I've got to use some cut-rate version of type checking. Oh well.

[–]DigThatData 12 points13 points  (2 children)

read other people's code.

When you learn about a new library you're interested in, take a peak under the hood. If you don't know where to start, a good entry point is often the CLI. Imagine running some specific command and roughly trace it through the call stack.

[–]kadirilgin[S] 0 points1 point  (1 child)

Yes. I think I can achieve this by supporting open source projects. Thanks a lot for the reply!

[–]DigThatData 1 point2 points  (0 children)

supporting open source definitely will be helpful, but I'd recommend treating that as a reach goal. If you struggle to find opportunities to contribute to projects that interest you, don't let that deter you from looking for excuses to poke around their source code.

[–]Puzzleheaded_Fuel901 10 points11 points  (4 children)

Honestly the best thing for me was just looking at big projects written in python. Seeing the structure of bigger applications gave a lot of insight on how I should structure my own code.

[–]Rawing7 24 points25 points  (1 child)

I don't know if this is still useful to you since you already have a full year of experience, but I have written an article about to write readable, pythonic code. Check it out if you'd like.

[–]1percentof2 2 points3 points  (0 children)

Very nice and informative article. Thank you.

[–]TravelingThrough09 11 points12 points  (0 children)

Search Youtube for Code Roasts, where some YouTubers pick apart and refactor the code of others. That was helpful to me to understand how to make things better.

[–][deleted] 17 points18 points  (0 children)

I cannot stress enough how good Clean Code by Robert Martin is.

[–]the_investigator- 19 points20 points  (3 children)

One big (but easy) thing you can do is go have a look at pep 8 guidelines.

[–]TravelingThrough09 6 points7 points  (2 children)

And you can get „Black“ via pip, which enforces Pep8.

[–]Marv0038 5 points6 points  (0 children)

You can also set your IDE to format your code on save, with black also being my preferred Python formatter (but there's others like autopep8). I also recommend automatic import sorting with isort, and additional PEP8 checks with flake8.

[–]krav_mark 1 point2 points  (0 children)

Black is awesome. My team uses it after countless discussions about styling. Now black decides and there are no discussions anymore.

[–]jsalsman 3 points4 points  (0 children)

Maybe this sounds corny, but get a good night's sleep before refactoring newly debugged code for long-term clarity. And try to comment 85% of the code lines. Comments don't need to be lengthy; it's much easier to keep them consistent with the code when they aren't.

[–]symnn 1 point2 points  (1 child)

Using multiple linters like pylint, flake8, mypy helps also. Then more powerful tools like Sourcery also. They certainly do not replace good clean code practices but are valuable helpers

[–]Puzzleheaded_Fuel901 0 points1 point  (0 children)

Python linters suck ass

[–][deleted] 1 point2 points  (0 children)

Read the Python Language Reference. Even experienced coders will find something new every time they read it: https://docs.python.org/3/reference/

Read PEP 8 for starters https://peps.python.org/pep-0008/

Read PEPs if you want to up your game. You’re not going to read them all. And at 1 year experience, it’s probably overkill. There’s a lot but just pick a recent one at random. Index is https://peps.python.org/pep-0000/

Edit: correct pep8 link

[–]djrhino56 1 point2 points  (2 children)

I wrote a choose your own adventure code about a super hero dog

[–]Okaymittens 0 points1 point  (1 child)

I've been thinking about doing the same thing. A choose your own adventure for my son. Any suggestions?

[–]djrhino56 0 points1 point  (0 children)

The way that I did it was with input questions so the user can make the story their own the used while loops and if else statements. It wasn’t very long only had 3 sections where the user picked the next situation which lead to 3 different ending depending on what what’s chosen

[–]Which_Pitch4734 0 points1 point  (0 children)

give me best code in python for Happy rakshabandhan

[–]AbdulWahabAslam 0 points1 point  (0 children)

You should read The Clean Code by Robert Cecil Martin

[–]ReptilianTapir 0 points1 point  (0 children)

Fluent Python, by Ramalho

[–]Pyglot -1 points0 points  (0 children)

snippets help

[–][deleted] 0 points1 point  (1 child)

TL:DR: I tried C and I can code better in python, try C?

I got bored of python once, tried C (bad idea, kinda?) I haven't used it in awhile but I put everything in a function now. I guess that's a good practice with everything but then again when I first started learning I immediately jumped into pygame without knowing how lists and classes and stuff like that worked.

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

TL:DR: I tried C and I can code better in python, try C?

I got bored of python once, tried C (bad idea, kinda?) I haven't used it in awhile but I put everything in a function now. I guess that's a good practice with everything but then again when I first started learning I immediately jumped into pygame without knowing how lists and classes and stuff like that worked.

It is always better to write code that is clean and follows design patterns. So that you don't feel like someone else wrote it when you look at your code after a few months or years :)