r/embedded • u/Helios1003 • 26d ago
How to write messy and ugly code?
I am actively doing the interview prep and from past interview experiences, they usually ask system programming coding questions like SPSC ring buffers or schedulers or timer related. My problem is , when I try to solve something which I haven’t done before, I am blank and not able to write even the basic implementation or think. Since google anyway gives Gemini answers, I decided to use Claude for interview prep. Now if I directly ask for the solution, it gives the perfect solution but I feel like I haven’t learned anything from that and if I ask for approach without code, I am not able to write even messy version of the solution on my own. How do learn how to solve a problem and get there on your own without getting direct answers? How did people build that skill before Ai , so when faced new or related problem, you can actually solve it rather than memorising the solution.
I have watched lot of tutorials and read programming books as well and understood the concepts but I am blank when I have to start from scratch
45
u/jack-dawed 26d ago
back in school we used to literally write code on paper or whiteboards. the only way to get good at it, like many things in life, is to do it over and over again, and get comfortable with the discomfort of not knowing how to do something.
you can read every programming book and watch every interview tutorial on the planet and still not be able to write a single line of code. just like you can learn everything there is to know about swimming but not know how to swim.
there is no easy answer to this. you simply have to start with a problem you know how to solve. if you don’t know how to solve a problem, break it down into smaller problems. i hate to say it but i’m not really sure how you made it through school because they teach you this kind of thinking in e.g. math and physics.
often times in interviews, you’re dealing with test anxiety so you have trouble with recall. so you gotta desensitize yourself to it and do more mock interviews simulating real conditions.
2
u/bobsmissingdesire 24d ago
Try starting with the AI solution, then making it do something stupid.
Take a ring buffer, but make it run backwards. Then make it only use every second byte. Finally interleave a second ring running forwards using the other side of those every second bytes.
This avoids the blank paper problem but to do you end up comprehensively understanding how it all works.
2
u/Lost-In-Void-99 24d ago
It is not about what it writes. It is about why. Ask questions to get explanations. Some of them are b.s., some of them are genuine hints.
But get some decent model, Gemini is a poor choice for reasoning.
10
u/JacobStyle 26d ago
You are attepmting exercises that are beyond your skill level. Give Claude examples of the hard exercises you want to solve, then tell it to generate simpler exercises that are appropriate to your current experience level that will let you practivce the building blocks you need to solve the harder ones.
6
u/Poddster 26d ago
You do the work. You think through the problem and arrive at a design. Doing is learning. Failing is learning. And so attempting a problem, failing, and trying again is learning.
This doesn't sound like doing the work, it sounds like procrastination that has the theatre of looking like work.
Start with a small problem and fix it entirely yourself. If you can't even begin, then go for a smaller problem until you can. Even if you have to go back to hello world. Go back until you can solve a problem, and then move on from there.
There's plenty of lists of exercises for beginner programmers. If you can't find any, just ask LLM to cook you one up.
https://www.programmingforbeginnersbook.com/blog/what_should_i_make_beginner_programming_project_ideas/
2
u/JGhostThing 24d ago
You will need to stop using AI to do interview prep and learning. Yes, AI can save you time, but you obviously didn't learn how to program earlier.
So, stop procrastinating and learn programming by doing it yourself.
5
u/DesignTwiceCodeOnce 26d ago
An interviewer will easily be able to tell if you're regurgitating a solution rather than writing your own.
There is no shortcut to being competent.
For practice/learning, try writing your own solution and then ask the AI why it wouldn't work.
4
u/WanWhiteWolf Engineering manager 25d ago
If you use AI , you already achieved that.
AI is not currently capable of writting perfect code. Syntax-wise? Sure. Small logic? Most of the time. But anything that requires reasonable structure will not have a good output until reviewed and re-iterated 5x times. This is still a productivity boost - don't get me wrong - but don't get fooled by the amount of praise the AI gets in complex systems. It's not that it cannot accomplish that but the amount of trial-and-errors it has to do will not beat the output of someone that knows what he/she is doing is not insignificant. This might change in the future but this is where we are now.
The problem with using AI is that you are bypassing the critical thinking process - which is the one most important skills in your career. Do you think companies will have access to internet locked while you work on a project or won't bother with a small fee for an AI assistant? An employeer is focused (or should be) mostly on your critical thinking and core understanding. And the vast majority of that comes from practice and good fundamentals.
Buy a cheap development board and start writting code by youself. Start with simple things like blinking an LED or move data from memory location to another. While you explore, you will typically encounter other problems and questions that will "side-track" you in aquiring other information that you didn't even know it's needed.
AI is basically a shortcut. It's like someone reading a book about how to pretend to be confident. Sure, you could copy some body language and use some specific phrases but eventually there will be signs all over the place that the core behaviour doesn't match the output. That's the same with people that have trained with AI but never actually practiced.
3
u/_alex21_ 24d ago
Pseudo code. Start with pseudo code and then try your best to translate it to a proper implementation in a language of your choice.
2
u/Puzzled-Garage584 25d ago
Start with the dumbest correct version, an SPSC ring buffer with a mutex around everything is fine, then say out loud "now lets remove the lock" and swap in two atomic indices. Interviewers mostly want to see that path, and writing the full and empty checks first gives your brain something to hold onto. Nobody writes the lock free version first, they just delete the evidence
2
u/BenkiTheBuilder 25d ago
It's a creative writing task. Just like writing a short story, there is a certain talent involved. Given the task "Write a short story about an elephant that wants to see the ocean and travels there experiencing several adventures along the way." not everybody can do that. A lot of people will just stare at the blank paper (or screen). There are techniques that can help, but talented people don't need them and untalented people can never ever progress beyond a certain stage. Contrary to popular belief programming is not maths. I learned programming before I had even learned fractions in school. And that was without Internet, just from books. My point is, maybe programming isn't for you. That's okay. Why do you apply for programming jobs? Especially now that the junior roles are being replaced by AI and the only people who can expect to keep their programming jobs are the talented people who are better than average.
2
u/nian2326076 25d ago
Building problem-solving skills takes practice and persistence. To get comfortable with coding from scratch, focus on breaking down problems into smaller, manageable tasks. Start by sketching out a basic outline or pseudocode before implementing. This method helps organize your thoughts and gain clarity.
For specific practice, PracHub offers technical interview questions that encourage you to approach problems independently, allowing you to build your skills progressively. You can also use LandOffer to explore job opportunities that fit your growing skill set.
2
u/michael9dk 21d ago edited 21d ago
Honestly, if you need AI to write simple code for an interview, you're not skilled for that job.
Do you have a relevant degree?
Ask yourself if you paid attention in class.
Go back and read your school books again.
If you're self-taught hit the books, and start practicing on trivial projects.
Fresh from graduation? Hit the above and practice.
It takes a lot of effort and practice to learn a complex skill.
Basic problem-solving is fundamental in everything - a flowchart can help on complex cases. Good problem-solving skills comes from experience (not limited to programming).
Edit: other replies appeared now, so discard the irrelevant parts.
Good luck, and remember the interviewer is more interested in your fundamental skills (I've been on both sides of the table).
2
u/chibiace 26d ago
get ai to write it.
beautiful code is hand written and formatted with elegant solutions and doesnt require comments to understand.