How tf do I learn good coding

I’m putting this here cuz it’s about esp32 and arduino mostly. I use them a lot for hobby projects, and the minimal code I can spout out looks like chicken scratch. I try to figure out coding by myself, but I always end up going back to ChatGPT, which does nothing to teach me. Where do I start? Digital logic? Basic commands beyond pinMode and digitalWrite? I’m jumping into this hobby solo, and youtube is just full of tons of slop nowadays, so any resources or advice yall have would be great

1 Like

The best way to learn is to have a project in mind that you need to code for. This way you have to specialize it for your particular need. AI is fine for brainstorming the project but until you have a need it’s hard to learn.

1 Like

A lot of “coding” is learning how to partition your project. What functions to split your tasks up into along with what variables will you need inside the functions and outside(or passed into and returned from). Besides when to use ‘if’ statements, ‘while’ loops or ‘switch’ statements for some of the basics. $0.02

1 Like

If having a project in mind is a good idea, then that leads us to problem #2. I have no idea what to do. I don’t have access to much cuz I’m a broke teenager, and I really want to work with physical i/o like motors and servos. I tried brainstorming, but a lot of the stuff I was coming up with isn’t exactly worth anything.

You mentioned that you want to control a motor/servo. Great start!

Next, what can you do with a motor/servo? You can make a car, make a clock, or make a fan (add temp sensor to turn off/on. You can also add LEDs to mark rotation ect.

You get the idea, start small and the ideas will start to flow and so will the coding.

1 Like

I’m starting from your question about learning good coding…

Basics: There are two areas of fundamentals to learn, honestly. Computer science and engineering. It’s good to know what they are even before you learn them, so you know what’s out there.

Computer science is our model for how computers work, starting from the basics and building useful abstractions on top. This is where you learn things like controls structures (if, while, for, etc.), functions, recursion, data structures, algorithms, and so forth.

Engineering is the practices we use to effectively make computers do the work we want from them. This includes how to break a problem down into smaller pieces, how to design a program so that it has internal structures that other people can recognize and work together on, and so forth. This is where you learn things like design patterns; common types of solutions that have been used over and over and which you can recognize in code. “This is a model-view-controller architecture” or “this is a singleton” — after you learn these things, it’s easier to understand code that other people have written that use these patterns. But you don’t start there! First you make mistakes that help you learn why these patterns exist. :grin:

Does that sound intimidating? It doesn’t have to be. That’s more a map of where you can go as you learn over the years. Starting with embedded programming (as with arduino and esp32) is a great start. But if you want to understand how computers work, boolean algebra will be a really helpful math skill; it’s hard to do interesting things with computers without being comfortable with boolean algebra.

It’s hard to give good advice without knowing what it is that you do know. Are you already comfortable with boolean algebra? What’s the hardest project you have completed successfully, and what was hard about it? Are you good with learning from books and other written material?

2 Likes

As far as the hardest class I’ve completed, it’s up to precalculus so far. Hardest part for me is the trig function rules (quotient rule, odd/even rule, etc.) I have an okay understanding of boolean algebra, especially when working with physically drawn logic gates, so I can visualize data flow better. Overall, it’s just me trying to get out of tutorial hell and stop relying on A.I. to write my code as much as it does right now.

1 Like

Wait, project, not subject hah :sweat_smile:. So far, it’s been a lot of stuff like 7-segment displays and stepper motors. I’ve made a car with simple driving logic and an esp-now connection to control it.

One of the things that makes Arduino a bit more complex is that it’s actually writing C++ code. They try to present you with an easy to learn subset of C++ but when you look at other people’s code they might use a lot of C++ and it’s just complex.

ESP32 makes it easy to work in embedded Python, and there’s lots of good coding learning available for Python. That’s not a terrible place to start.

I have been programming for almost 6 decades. There is so much to learn, I can’t even figure out where to start.

Most languages are compiled to produce an executable file compared to an interpreted language.

A compiler reads your source and produces an assembly language file for your indicated cpu. Then an assembler produces an object (module) or machine instruction file (module) and the linker is invoked to link the various object modules together to produce an executable. This is loaded directly into the machines memory for it to execute.

An interpreter evaluates each line of code as it encounters it. The problem with interpreters have always been it’s a bit more difficult to handle run time errors.


Most good writers are veracious readers. I suggest you read over a lot of the code that’s out there related to what you want to do… just doing it will help you understand programming.

I’ll make some suggestions, even though I know you likely won’t follow through, just hoping you’ll save yourself..

  1. Understand the target machine. Here’s a link to the A good place to start is reading the manual for the Atmel 328p controller, same controller that’s in the Arduino. Even if it’s over your head initially, it will start to make sense as you want to do more. You can find the same type of document for the ESP32. Here is their site on getting started with an ESP32.
  2. Draw a flow chart. May sound simple but it makes you think first - program later. This is incredibly useful when you actually write the code as each step is clearly documented.
  3. Learn to use or drive the debugger. It takes time to learn how to use a debugger. It’s pretty alien at first, but hang in there. It allows you to step through the code and you can look at and change variables as the program is executing each line.
  4. Document the code and keep it up to date. Change the code, keep the documentation in the source up to date for the next victim, I mean next person who needs to fix or modify it.

C was designed for portability, so many of it’s operations are not specifically defined and usually related to different hardware architecture. Some compilers/machines may store memory variable from lowest address to higher address or vice versa, C lets you determine this things, but you should know them if you plan on using some of these functions.

Object oriented languages like Ada and C++ need to use data types for many of it’s over loaded functions. C may warn you about a type mismatch, but it’s easy to make a mistake. C is also know as the language that gives you plenty of rope to hang yourself.

I taught different programming languages in the local community college for about 12 or more years, so I’ve read lots of other peoples code. You might think it should work this way, but the person next you may have a completely different view of how to handle it. Don’t assume you know it all.

How you learn to write software becomes a habit and you can have good and bad habits. Not documenting your code and learning how to drive a debugger will vastly improve what kind of software person you are. Don’t get in a hurry, which I see you are by using AI… although it has it’s places.

Good luck.

:grinning_cat_with_smiling_eyes:

1 Like

Here’s another angle. I wanted to learn more about arduinos. I bought this and went through the CD that comes with it. I was interested in controlling motors. It has a wide variety of “labs” you can do. You might pick up some of the basics by doing them in order. I found enough information to do what I wanted to do.

Amazon.com: ELEGOO UNO Project Super Starter Kit with Tutorial and UNO R3 Board Compatible with Arduino IDE : Electronics

1 Like

I have been doing a lot of AI assisted coding lately. Its not that I don’t know how to code, it’s that I am a really slow and bad typist and I don’t want to commit to memory the myriad of rules about syntax etc. Above all, I don’t want to be a great “coder” I want to be a great programmer. For that, its only necessary to know whats possible, and then brief an AI to do the coding for you. The better the briefing the better the final code. I also stop briefly at various stages to examine the code and often ask questions about it - How does it work? why not do it another way? explain it to me… etc I find myself learning a little bit every time. Some AI’s like Gemini and Copilot proactively explain the code that they product.

If that is not really your style of learning I find that programming environments such as VSCode and Arduino Studio have excellent tutorial projects that teach you the basics of the language you want to program in as well as the programming environment. In general I too have found that I Iearn as I complete a project (build a robot/ build a remote/ build a tensile testing machine/ etc etc). I never ge it right the first time, and the mistakes are more informative than final code..

Enjoy the process.

As I suspected, you don’t want to learn it, you want to know just enough to get AI to do it for you.

Good luck, with that attitude, I wonder what kind of programmer you will be. Coding and programming is the same operation.

Have fun anyway.

:grinning_cat_with_smiling_eyes:

1 Like

Jack, it’s @GlassHammerMaster who started the thread. Not @NotTheMama . :slight_smile:

2 Likes

Putting on my moderator hat here…

Let’s not cut others down here. I know AI usage has been kind of polarizing. But I’d like to ask that we take it easy.

2 Likes

Taking my moderator hat off…

I have a few offspring studying computer science. My advice to them has been, roughly:

  • The field of AI is almost as old as CS and has changed tremendously over time, and the current crop of LLMs is changing faster. If you focus on how to make an LLM do your bidding today, it won’t help you a year from now.
  • The core computer science topics aren’t changing that much, just evolving a bit (like which languages would be good to learn).
  • If you don’t know computer science, it’s hard to know when an LLM is doing something stupid
  • If you do know computer science well, you will be well positioned to deal with whatever LLMs are like in a year or five, which will probably be different from today.

There’s definitely real evidence that leaning on LLMs has some negative impacts.

Even people building LLMs and using them daily can recognize these impacts thoughtfully:

Personal opinion here: In my own personal projects, I mostly use LLMs sparingly, typically as a context-sensitive memory augmentation device. I’ve written a lot of python code in the past, but I haven’t recently kept up with the whole ecosystem. An LLM is likely to find the particular python module that I didn’t know existed to solve a problem I asked faster than I would from a search. Because I still have a lot of general expertise here, I’m well positioned to determine if it’s doing something sane.

A real problem right now is that LLMs are making experienced, senior engineers noticeably more efficient if they use them in certain ways, but are making it a lot harder for junior engineers to learn what they will need to become those senior engineers in time. It’s facilitating a skills gap.

So @GlassHammerMaster you are doing well to recognize that going back to ChatGPT each time isn’t really teaching you.

I’m finding it hard to suggest one specific path to you (other than just diving in and trying things and failing and learning from failure and asking for specific help as you learn) because there are so many learning paths.

3 Likes

All the advice is super helpful. I realize AI has a time and place, but I don’t want to use AI to replace the critical thinking and such that comes with learning programming. I’ll take the advice so far and move forward. Maybe revisit Python a little bit. Thank you all!

2 Likes

Have you seen MicroPython? It’s supported on a lot of inexpensive hardware and it’s not at all a bad way to experience embedded development as you learn.

2 Likes

When I used to work on automated and robotic welding equipment, the welders were always complaining that the automation was going to take their jobs away. I tried to explain to them that it takes a good welder to know when the automation is either doing what it’s supposed to or putting in a very bad weld.

The same goes for coding, if you don’t know what you’re looking for you have no clue if the code is good or not.

2 Likes

I’ve been doing embedded programming for 50 years. About 20 years as a full time job. And… I teach programming with UCSD extension, and have mentored FIRST robotics teams. I’ve been thinking about this a lot:

  • If your goal is to have a job, don’t. AI is 100% replacing programming as a job. Yell at me. It is. I use it, it works, and every MONTH it gets better. Programming as a career is over.

  • If your goal is to LEARN, then again, don’t. At least not first. Instead, go beat NANDGame online, then play with CARDIAC Online. then mess around with ASM and learn how assemblers are written, and linkers and then maybe a little about how C compilers work, and THEN… learn to program.

Why all that before learning to program? Because without that, you don’t have a scaffolding on which to place what you learn! It’s just mumbo jumbo being memorized. But when you can look at a line of code, and your mind can see how that translates into asm, machine code, bits flipping around, electroncs racing… Then… you actually understand it.

There is another path, which is top down, instead of bottom up. In that one, you learn LISP via MIT’s 6.001 Structure and Interpretation of Computer Programs class (the lectures and course work are all online free). I don’t like that version, but I respect people who followed it.

In anycase, best wishes.

1 Like