learning basics or sample code[SOLVED]

Thread Starter

Pushkar1

Joined Apr 5, 2021
414
How should beginners get started by learning the basics and code to design with planning or by looking at c sample code?

Some people are in favor that everything is already available on the internet, they should study the code and learn how it works. Then modify that it's needed, and make it work on your hardware.

Some people have a different opinion, they think that beginners need to learn some basic skills to be able to make proper decisions and use it properly in their own designs.
 
Last edited:

dl324

Joined Mar 30, 2015
13,532
I needed to fiddle with Python to use some Adafruit code for an SSD1306 LCD display. Not knowing any Python, I was able to hack on the code to get it to do what I wanted.

But, now I think I'm going to really learn how to use Python (even though performance sucks, it's popular). The first book I really looked at was Python Programming For The Absolute Beginner, Third Edition. It seemed like a good place to start, but it was a piece of crap. Luckily the book was given to me, so I'm not out $35.

Next I'm going to go with a book that describes the syntax and language features. I can skim through any sections that don't really help me...
 

nsaspook

Joined Aug 27, 2009
8,905
Should people just jump in a car and start driving on the road while looking at other bad drivers to learn how to drive?

The internet is filled with crap and good code. Without basic skills you will learn to mimic things that might be crap because you won't have the background to understand the difference. If you have the talent it won't take long to learn the basics of programming devices and computers. Then you can learn the basics of programming the language you wish to use.
 

xox

Joined Sep 8, 2017
609
How should beginners get started by learning the basics and code to design with planning or by looking at c sample code?

Some people are in favor that everything is already available on the internet, they should study the code and learn how it works. Then modify that it's needed, and make it work on your hardware.

Some people have a different opinion, they think that beginners need to learn some basic skills to be able to make proper decisions and use it properly in their own designs.
The first thing to do is start with a decent set of programming books. Petzold, Knuth, and K&R are some good examples of authors you might want to look into.

Next, just practice writing programs. You will likely need to write many, so the more the better. Some will be "serious" projects requiring long-term commitment. To break up the monotony, try cranking out something simple that just does something "fun" or "interesting". For example, one day I was thinking, "Well according to this and that theorem, you could theoretically calculate π by simply checking for common factors between a randomly selected set of integers". And so I sat down and wrote a program in about half an hour that did just that. Point is, using THAT momentum I was then able to refocus on the important stuff.

The main thing though is to continuously learn new things. And do realize that it tends to take some time to become halfway proficient at it. It also happens to take a lot of patience, but you'll learn that soon enough for yourself!
 

Papabravo

Joined Feb 24, 2006
17,295
How should beginners get started by learning the basics and code to design with planning or by looking at c sample code?

Some people are in favor that everything is already available on the internet, they should study the code and learn how it works. Then modify that it's needed, and make it work on your hardware.

Some people have a different opinion, they think that beginners need to learn some basic skills to be able to make proper decisions and use it properly in their own designs.
The assumption in your question is that there is a "one size fits all" answer. Sadly this is not the case. Each person learns the required skills via a different path. Some people are in a hurry and some people have the patience of a saint. In short you must try every possible method, keep at it, and "do forever".
 

dl324

Joined Mar 30, 2015
13,532
Another thing... Most programming books teach you how to use the language, not how to program. They assume you've already learned how to program in some other language.
 

MaxHeadRoom

Joined Jul 18, 2013
23,926
For me 'looking at code' does not cut it, all my life I must take a structured example and 'do it myself' and see what happens, if its wrong, why?
It's the figuring out that impresses the memory.
Simplistic? yes!
 

click_here

Joined Sep 22, 2020
446
If it's a new environment like a new microcontroller, start with working code, like a blinking light, and then modify - That way you are starting from something that you know works.

That being said, learn C independently of a microcontroller and master the language.

My advice is to start building programs and fixing other peoples programs on forums.

I love solving projecteuler.net problems.

... Or choose something that you like - I love cricket and I know that it is massive in India, so making a score card is a great little project. See if you can use it while watching a twenty20.

When you fix other peoples problems you start to see people making the exact same mistakes over and over.

A classic example of this is...
Code:
scanf("%d", apple);
// should be
scanf("%d", &apple);
or...
Code:
if(banana = 1);
// should be
if(banana == 1)
When I look through other peoples code I scan for the "low hanging fruit" first.

Getting familiar with common problems makes you a much better coder.

When you have the C language down, you'll want to look at some advanced stuff.

I once asked for advice on what book I should look at now that I had the language down pat and one of the best programmers that I have ever seen recommended "C Unleashed" by Lawrence Kirby and Richard Heathfield. (Now I do the same) - This book will mature your coding very quickly, but be warned that it is not a beginner's book.

If you want an advanced C book that is actually entertaining and enjoyable to read "Expert C Programming: Deep C Secrets", by Peter van der Linden.
 

dendad

Joined Feb 20, 2016
3,939
For a very basic start to Arduino, look for "ASKmanual.pdf" as an old but quite good book.
And the "learn to program the hard way" series has been recomended to me, butI have not tried it.
 

strantor

Joined Oct 3, 2010
5,695
Should people just jump in a car and start driving on the road while looking at other bad drivers to learn how to drive?

The internet is filled with crap and good code. Without basic skills you will learn to mimic things that might be crap because you won't have the background to understand the difference. If you have the talent it won't take long to learn the basics of programming devices and computers. Then you can learn the basics of programming the language you wish to use.
The assumption in your question is that there is a "one size fits all" answer. Sadly this is not the case. Each person learns the required skills via a different path. Some people are in a hurry and some people have the patience of a saint. In short you must try every possible method, keep at it, and "do forever".
I agree with these two posts equally and I don't care if that makes me in inconsistent. I have the attention span of a goldfish, so I have never opened a book to learn programming. I started programming out of necessity, by finding examples online and beating them into submission. These days I rarely have to Google my goals; I can write them from scratch. But I don't think I'm writing them well. Heaven only knows whose bad habits are part of my arsenal. Now that I'm at a level of confidence that I "know what I'm doing" I can (and think I soon will) transition from a mode of programming as a means to an end, to programming as an end goal. If my goal is programming properly, then I can accept book learning as a means to that end.
 

Papabravo

Joined Feb 24, 2006
17,295
I agree with these two posts equally and I don't care if that makes me in inconsistent. I have the attention span of a goldfish, so I have never opened a book to learn programming. I started programming out of necessity, by finding examples online and beating them into submission. These days I rarely have to Google my goals; I can write them from scratch. But I don't think I'm writing them well. Heaven only knows whose bad habits are part of my arsenal. Now that I'm at a level of confidence that I "know what I'm doing" I can (and think I soon will) transition from a mode of programming as a means to an end, to programming as an end goal. If my goal is programming properly, then I can accept book learning as a means to that end.
The creed I learned as a rookie programmer during the "startup" 1970's was:
  1. First, make it work.
  2. Second, make it optimal.
  3. Last , make it elegant.
There was no such thing as an optimizing compiler in those days, it was bare metal programming, using the smallest useful machines larger than a Turing machine.

why we need memory in microcontroller? | All About Circuits
David L. Mills - Wikipedia
 
Last edited:

dcbingaman

Joined Jun 30, 2021
498
The creed I learned as a rookie programmer during the "startup" 1970's was:
  1. First, make it work.
  2. Second, make it optimal.
  3. Last , make it elegant.
There was no such thing as an optimizing compiler in those days, it was bare metal programming, using the smallest useful machines larger than a Turing machine.

why we need memory in microcontroller? | All About Circuits
David L. Mills - Wikipedia
I tend to disagree. If you make it elegant and optimal from the beginning then making it work is much easier.
 

dcbingaman

Joined Jun 30, 2021
498
How should beginners get started by learning the basics and code to design with planning or by looking at c sample code?

Some people are in favor that everything is already available on the internet, they should study the code and learn how it works. Then modify that it's needed, and make it work on your hardware.

Some people have a different opinion, they think that beginners need to learn some basic skills to be able to make proper decisions and use it properly in their own designs.
I learned to make spaghetti code without any effort. I had to work at it to write elegant, organized easily reusable code. This is one of the best books that helped me out. It is not about any specific language but just how to write good code from the start.

https://www.amazon.com/Pragmatic-Pr...atic+programmer&qid=1631064611&s=books&sr=1-1
 

nsaspook

Joined Aug 27, 2009
8,905
For my line of work there is a 1.5: Make it reliable and resilient. This is where understanding the basics of computer theory matters because this skill happens during the make it work phase by designing checks, fallback by design. Optimal and elegant don't mean much if the gadget crashes in the field randomly. Learn to build programs like we build physical structures. "Premature optimization is the Root of All Evil".

https://www.ibm.com/garage/method/practices/manage/build-for-reliability
 
Last edited:

Papabravo

Joined Feb 24, 2006
17,295
For my line of work there is a 1.5: Make it reliable and resilient. This is where understand the basics of computer theory matters because this skill happens during the make it work phase by designing checks, fallback by design. Optimal and elegant don't mean much if the gadget crashes in the field randomly. Learn to build programs like we build physical structures. "Premature optimization is the Root of All Evil".

https://www.ibm.com/garage/method/practices/manage/build-for-reliability
As precursors, I might add controllability and observability. It is difficult to impossible to fix what you cannot see or imagine.
 

dcbingaman

Joined Jun 30, 2021
498
We did not have that luxury in those days since we were on the bleeding edge of technology with the very first microprocessors. It was "fix it" or "resign", and we preferred the former over the latter.
I know what you mean. I remember on certain project being under that same sort of pressure.
 

dcbingaman

Joined Jun 30, 2021
498
We did not have that luxury in those days since we were on the bleeding edge of technology with the very first microprocessors. It was "fix it" or "resign", and we preferred the former over the latter.
In my first job it was not as critical. If the software glitched it was no big deal. Later working for the MIC on Missile Guidance Software we could not afford any glitches, glitches mean we miss the target and put the soldiers life at risk. We had a lot of software reviews and lots of unit testing. So a unique situation the company was more willing to spend a great deal of time with proper software design before any coding started.
 
Top