Why can I never find the most simple solution to a problem?
Posted by 10fighter55@reddit | learnprogramming | View on Reddit | 20 comments
It seems like no matter what, I can never figure out how to solve a problem in a simple way. I am a sophomore computer science student, and in all my projects and labs, I almost always come up with some inneficient, convoluted solution to a problem that could be solved a million different simpler ways. I know this is kind of a vague question, but has anyone overcome something similar?
canadian_viking@reddit
Do you just stop when you come up with your convoluted solution? If so, there's your problem.
There's nothing necessarily wrong with coming up with a convoluted solution, but your next question should really be "Now how do I simplify it?".
BranchLatter4294@reddit
The first solution doesn't have to be the best. It just has to work. You can always improve it later.
PratikVR@reddit
Start from first principles. Don't get carried away by your gut feeling. Trust me this works
The-Oldest-Dream1@reddit
Don't beat yourself over it too much. Everyone starts somewhere. If you've created an inefficient solution, you'll just have to look into how you can simplify it
DustyWalrus854@reddit
i feel this as a fellow student have you found any good strategies?
notislant@reddit
People think differently and are exposed to different things.
I was learning some basic web dev for personal projects and fun.
There was some assignment where you use local storage and have to let the user delete items on the screen. Like a shopping cart or whatever else.
Mine basically just used basic JS to remove the parent element and update local storage.
Meanwhile many others were generating unique IDs for each item, searching through both lists to find a match and delete it.
Then struggling to find out why it was deleting the wrong one when deleting by index. I think most issues were solved by going last to first or refreshing the index each time. But some people would find interesting alternatives there as well.
Ambitious_Emotion921@reddit
it
is a classic "sophomore slump" in programming: you finally have enough tools in your belt to be dangerous, so you treat every problem like a nail that needs a massive, custom-built power hammer.
Actually, your background in design, animation, and human behavior might be contributing to this. You are likely naturally inclined to think about the "experience" and the "structure" of the whole system rather than just the raw logic of the snippet. While that makes you a great designer, it can lead to "over-engineering" when you just need a simple loop.
Why It’s Happening
ifstatement would suffice.How to Simplify
switchstatements and basic loops.Efficiency comes from knowing what to leave out, not what to put in. As you move from research-based design to professional execution, you'll find that "simple" is actually the hardest thing to build.
BlueGnoblin@reddit
That's okay, every solution needs time. You think about a solution, test it out, refine it, something refactor it. This is all valuable experience you can use later on.
When I code something new, I have a good vision of what works, how it works and how to code it, but I'm coding for 35+ years and all the attempts and failure in the last decades helped me to produce faster better code nowadays.
OffbeatContents@reddit
Your brain just needs more patterns to recognize - after few years of coding you start seeing same problems everywhere and solutions become more obvious.
DemicideMMMCCCI@reddit
This is normal. I used to wonder the same bit then it's all about practice. Exposure to many types of problems and at some point it'll look like another one you've already come across with some slight difference.
All that it takes is practice and with, hopefully exposure to many problems.
hugazow@reddit
Because no one gets there at first try, just check the evolution on sorting algorithms.
theGaffe@reddit
I went through this as well. Simple solutions are obvious when you see them, but are not obvious to come up with. It only takes one single person to come up with the simple solution for others to replicate it, and it doesn't always happen instantly. As your experience grows, you will learn about quicker solutions to things you have came across before, and know how to better enact them in the future. Don't stress about it too much, just be happy when you do find those cleaner solutions.
434f4445@reddit
There are no simple solutions to complex problems.
augustcero@reddit
but it can be a collection of simple solutions independent of one another
augustcero@reddit
avoid going down the rabbit hole. sometimes you cant help but address a problem and then you discover it stems from another one, which stems.... you get the picture. my point is, try solving one problem at a time and consider refactoring later.
for example: your client needs a POS app, just to handle payments from customers. its easy to go down the rabbit hole and write code to include "loyalty benefits", which now in turn includes a separate module for customers etc.
Striking_Rate_7390@reddit
you're not used to syntax basics, this happens when you watch lots of tuts but don't practice it, happens with me alot
ryan_nitric@reddit
This is a normal phase. Beginners write complex code because they're solving the problem in their head as they type, so the structure of the code mirrors the messy thought process. Senior devs write simple code because they've already solved it in their head before they start typing.
Two things that helped me: first, write the messy version, get it working, then refactor. Don't try to write clean code on the first pass. Second, after you finish something, look back and ask "what's the smallest version of this that still works?" Delete code aggressively. You'll start to see patterns you can shortcut next time.
Reading code helps too. Find a small open source project in a language you know and just read how experienced devs structure things. Pattern matching builds taste faster than tutorials do.
DrShocker@reddit
The trick is once you have the convoluted way out of your head, you have more mental space to clean it up. Eventually the cleanup process will train you to recognize patterns you're using that only serve to make things convoluted.
SilentOverrule@reddit
Bro, u're trying to invent solutions instead of recognizing patterns. Most simple solutions aren't discovered- they're remembered from experience. The shift happens when you start asking 'What's the most boring way this can work?' instead of smartest --Read that once again !
Damodara_trilok_9@reddit
Because beginners think:
Can I solve this?
Experts think:
What unnecessary parts can I remove?
Most simple solutions usually come after struggling with the complicated ones first. Simplicity is normally the result of experience, not the starting point.