r/learnpython • u/apple68shsj929927e7 • Sep 07 '26
How do you get better at actually THINKING in code, not just learning syntax?
I have been learning python for a month now but I don't see any improvements. I tend to forget the concepts of python and can't solve problems logically. I don't think it's just me who is dealing with these problems, I need tips please.
50
Upvotes
82
u/desrtfx but other languages pro Sep 07 '26 •
We don't think in code. We think in algorithms - in steps to solve a problem.
Code comes way later.
First, we focus on breaking down a problem. Then, we solve each of the smaller sub-problems. Then, we test the hypothetic solution. Then, we start working on the implementation.
11
u/Lionh34rt Sep 07 '26
Learn algorithmic thinking and architecture + adaptibility (modular)
11
u/kallax82 Sep 07 '26
Well as others pointed out, it's related to breaking down a big problem or task into smaller actions. Each of these actions is one step to solve the task. In the end these action become your code. Try thinking about a task you know, i.e. your morning routine. What happens between your alarm clock ringing and you leaving the house?
You know exactly what you have to do. But now try explaining it to someone else without any ambiguity. What means "get dressed"? Usually the clothes are in the bathroom, but what if not? Step 2 says "go to the bathroom". It doesn't say anything about brushing your teeth or taking a shower.
Code is the translation of a bigger problem into tiny steps a computer understands. Does it know how to walk? Did someone else publish a 'walking' library you can import?
Once you get down this way of thinking you move to solving new problems, where you don't now how to do it in the first place. Hope that helps!
5
u/WillAdams Sep 07 '26
A book which I found helpful for structuring thinking on code is John Ousterhout's:
https://www.goodreads.com/book/show/39996759-a-philosophy-of-software-design
a programming technique which I've found to help is Literate Programming:
http://literateprogramming.com/
5
u/KnowledgeWhole9623 Sep 07 '26
1 month is nothing. You don't even know how to code yet, how could you possibly think in code? You need time & hard work.
4
u/Nilfiry Sep 07 '26
Try changing your approach.
Dont think about the code at all. First, think about what you want to do. Then, think about what steps you need to do to achieve your goal. Once you have an idea, then you can start thinking about how to code those steps.
2
u/ivovis Sep 07 '26
I don't think in code.
I also don't think in Gears and motors.
I do use both to make things - only by using it as mechanism to solve a particular problem will it become second nature, it would seem you just need to stop thinking about 'learning to program' and spend more time building stuff to fix things.
2
u/Fragrant-Cheek-4273 Sep 07 '26
A month is really not that long, so don't worry if you still feel lost. You're probably trying to learn Python syntax and problem-solving at the same time, and they're two different skills.
0
u/cylonlover Sep 07 '26 •
From a beginner, it's a very keen observation, and you should hold on to that. The power of programming comes exactly from thinking in programming, like thinking within the toolbox, programming is.
It is indeed not as much a question of programming as it is about problem solving.
But this comes with practice and getting intimite with the problem area aswell as the programming language.
You would often hear experienced programmers talk about how everything can be done in every language, or how if you already know one language, a second one is easier. This used to be more true than it is nowadays, especially the latter, because there is so much more to know about a language than just the generics that it shares with other languages. But the point of still stands. The real skill is showing in the problem solving coming when getting intimite with a language eco system and it's paradigms.
Now, traditionally you would outline all sorts of programming languages and all sorts of areas in which to use them, and they would differ vastly.
In some you would handle large datasets and you'd sort through them, correlate, apply rules and filters in order to extract information. Here you would need to be familiar with flat data structures and all sorts of operations on them, some built in, some appended by a library or module.
In game programming you would serve yourself well to be very comfortable with math, especially geometry, because you are going to think up solutions based on visualizing it in your mind. I am not even talking about graphics here, I am talking about decision trees and arches in storytelling. But also graphics, ofcourse. Even if you have an engine to do the heavy lifting, there is plenty of geometric and spacial thinking in the problem solving.
I can't even grasp what is required for machine learning, I have only watched a few videos about it, so I only know some of the theory. I have been programming since the late eighties, so I might be able to implement a winning tic tac toe strategy, but I would not be utilizing the right modules and methods for it to scale, I would start by reinventing the wheel.
My point is, practice on problems makes you familiar with the mechanics of programming, even with a language, but realize that the subject is not one but many different ones, and you can't expect to go forth in one unless you stick to it. I mean, stick to he problem domain. This is why so many answers to beginners always counter ask "what do you wanna do with your programing?"
What are the most satisfying areas of programming techniques you have come across till now? Maybe that could be a hint as to which direction you would benefit from going deeper into.
You like for-loops? List comprehension? Object design? You like finding a great library and dig into it? You like coding stuff that interacts with the user? You like call API's? To you that may sound like a shallow perspective, but to me it speaks volumes. To me, yes to any of them points correspondingly in the direction of algorithms, datamining, information modelling, systems design, interface design, transactional web, and that's just off the top of my head. I am thinking in terms that if you said you enjoyed this or that, I would recommend you to learn more about this or that area, because you might find it stimulating and that makes it easier to become intimite with a problem domain.
I hope this helps, feel free to follow up with your thoughts on it. It seems you have both the right intuition and motivation. That's not nothing.
1
u/ForeignAdvantage5198 Sep 07 '26
i never learned to speak python
1
u/Artistic_Map2243 Sep 07 '26
Spend less time trying to remember every Python concept and more time solving tiny problems.
Write the steps in plain English first, then turn each step into code.
1
u/Revolutionary-Oil408 Sep 07 '26
Do you write sudo code before actual code?
1
u/NiemandSpezielles Sep 07 '26
This might sound a bit esoteric but I think it works due to how the brain processes rewards: Try to work on problems you find interesting. Research how to best solve it (do not copy code! You need to understand how it works and implement it yourself). Then try to appreciate the beauty of the solution.
It helps when you write something you care about. Imo fun hobby project are by far the best way to learn.
1
u/localizeatp Sep 07 '26
by coding.
1
u/TheRNGuy Sep 07 '26
Look at it and analyze.Â
1
u/SirGeremiah Sep 07 '26
Focus less on the programming language and more on the logic. Write pseudocode before you dig into the syntax. As you improve, the pseudocode gets closer and closer to the structure of your final product.
1
u/Traveling-Techie Sep 07 '26
I know I’m getting there when I start dreaming in a language.
I think there’s no shortcut to solving problems over and over. It gets easier.
1
u/JGhostThing Sep 07 '26
You've studied Python for a month. Have you ever studied a foreign language, such as Spanish or German? After a month, could you speak fluently? No. Because the human mind take time to learn such things. The same with programming.
1
u/ShadowShedinja Sep 07 '26
Break down your task as small as possible. If there are any steps that repeat, consider a loop or function to make it easier.
1
u/Langdon_St_Ives Sep 07 '26
Practice. That's it. You're welcome
1
u/SprinklesFresh5693 Sep 07 '26
By practising
1
u/jlsilicon9 Sep 09 '26
Practice, practice, practice ...
1
u/-moron Sep 09 '26
If the problems you solve are too small/specific, you'll miss a lot of context as to why/when you would ever use them. I suggest starting a moderate-sized project, like an add-on for a program you use (e.g. Blender or GIMP). Processing large amounts of image or mesh data also gives you a chance to test the speed of different algorithms at scale.
1
u/Otakulypse Sep 18 '26
Take a simple concept like for or while loops and keep working on those skills. Read up on how to write them, write examples a few times over, the start making your own versions of those loops repeatedly. Do something simple like make a list of names and write a for loop that over and over using different lists. Take this for example: Names = ["mike" , "chris" , "adam"] For name in names: Print(name) Simplest things like this lead to more complicated retention.
1
u/recursion_is_love Sep 07 '26
It is the same process as using human language, think before speak. If you try to speak without thinking first, what come out of your mouth are random sound.
Focus on the semantic of the code, not syntax.
0
u/nog642 Sep 07 '26
Practice writing projects.
0
u/samsly135 Sep 07 '26
0
u/AuthurAndersson Sep 07 '26
Just create stuff using AI and you will pick up how it works over time. And youll have fun creating stuff whilst you learn.