PDA

View Full Version : Advice for a beginner and not so good programmer?



Blueberry
11-05-2011, 03:49 PM
I'm sure you've seen these posts before.

So, as of last night I started looking into PIC microcontrollers because I had to purchase one my first year of college and I haven't used it since.
At the time I wasn't required to buy a formal kit as I see on the site, I have a propstick usb microcontroller, a non backlit 2x16 lcd screen, breadboard, a wire kit, 1k, 330, 47, 100, 270 ohm resistors, assorted leds, a push-button switch, a capacitor, temperature sensor, and 9v battery. I know I can get other items from school.

I've been taking computer science classes at school and I still feel like I haven't grasped a thing, sometimes I can't even finish my school assignments because I get stuck and I always need to see a teacher's assistant or teacher, while my peers tend to be on the opposite side of that where they can, for the most part figure out their errors without assistance, think like a computer therefore understand the program on a conceptual level, and even have the ability to start and finish their programs a few hours before the deadline. I know I shouldn't look at them, but it's frustrating to me as I feel like I haven't had a clear answer on what I might be lacking and because I'm in a classroom environment I have to keep up to speed with the rhythm of the class. I'm assuming it's because I haven't been able to learn just one main language or find an efficient way to step into it, every class is taught in something different and I'm currently learning assembly language, but previously took classes in python and java (data structures).

Honestly, I don't know where to start with programming. I think I'm the type who needs a walk-throughs/a little bit of hand holding for a while with a lot of descriptions until I can think in the manner that I need to in order to create a program. I found this site: http://www.mstracey.btinternet.co.uk/index.htm which seems to guide a user who has no knowledge at all.

I would like some online resource recommendations for the time being until I can obtain the books, obviously book recommendations that can cater to my learning style and even a well-done project walkthrough, preferably one for beginners, and even general advice won't hurt. Seeing that I am learning assembly, is it better to continue programming in it or better to start learning spin?

ElectricAye
11-05-2011, 04:44 PM
Welcome to the forum,

If you really want to stick with starting with a Propeller, then check out this page, especially the PE Labs link:

http://forums.parallax.com/showthread.php?89958-Propeller-Education-Kit-Labs-Tools-and-Applications

But if you really feel you need to back up some more and start afresh with something simpler, then I personally would suggest looking into learning with the What's a Microcontroller? literature and learn to program the Basic Stamp BS2.

http://www.parallax.com/Portals/0/Downloads/docs/prod/edu/28123-WAM-v3.0.pdf

There are lots of free downloads on Parallax.com :

http://www.parallax.com/go/WAM

Some of these kits might even be available at your local Radio Shack by now:
http://www.parallax.com/Store/Microcontrollers/BASICStampProgrammingKits/tabid/136/ProductID/327/List/0/Default.aspx?SortField=ProductName,ProductName

Also, this forum might be able to provide lots of help when you find yourself stuck.

enjoy!

Mike Green
11-05-2011, 06:00 PM
I think ElectricAye has the right idea. There are some really basic concepts that appear in most programming languages and most computer instruction sets. You can learn them with the Propeller, but there are also some very sophisticated concepts in the Propeller and in Spin that need to be left until you've mastered the basics. Eventually there will be Propeller tutorials that will cover the same really "start from scratch" topics as What's A Microcontroller? and the Propeller Education Kit Labs tutorials are a step towards that.

Start with the What's a Microcontroller? (http://www.radioshack.com/product/index.jsp?productId=2117994) kit. Work through the exercises. When you've finished the book and the exercises, start on the PE Labs with the Propeller and duplicate some of the exercises with the Propeller. You could also try duplicating some of the exercises with the PIC that you have. Pay attention to the similarities and differences between the Stamp and the PIC or between the Stamp and the Propeller. Note that you can use the BS2_Functions library to duplicate many of the specialized statements in the Stamp when using Spin on the Propeller. There is a variety of programming languages and libraries for the PIC that also duplicate many of the built-in functionality of the Stamps. Many of them though are for sale, not free.

SRLM
11-05-2011, 08:28 PM
I speak from my perspective as a former beginning programming tutor, and a current freshman engineering mentor perspective. This is what I've noticed working in a university environment, and all my opinion. Take it with a grain of salt.

Many students come to me with trouble in their classes, usually math and computer science. For the most part they have the same problem that you do: they simply start trying things with their program, run it and see if it works. It's not very effective, and it take's too much time.

This scatter shot approach almost always stems from a lack of understanding of the language and the problem. As simple as it sounds, this is important to recognize. I always recommend that students start with an "Introduction to XX Language" book, and work through it from cover to cover. I would probably start with Java* as the particular language, but any works. It's important to work through the whole book, typing out the programs that it lists and running them, then making small modifications and seeing how that effects the outcome. These steps are particularly effective on some of the larger (multi page) listings that the better books have.

You should read the entire book cover to cover even if you do not understand all of it, or even most of it past the first half or so. By reading the whole book you familiarize yourself with the language and general programming concepts that it represents. Later, when those topics come up again, you will have a framework to place the new information into.

After you've worked through the introductory book, I would suggest getting three books: a book on code style, a book on debugging, and a cookbook for the language that you are programming in. The first two books will allow you to write more maintainable code and (obviously) find your bugs faster. The last will help you know what is possible with a language.

I generally don't recommend learning from online resources. Online sites (like the wonderful cplusplus.com (http://www.cplusplus.com/)) are great for refreshing memory, but not for learning. Online material is harder to comprehend, retain, and relocate down the line. Use such information judiciously when learning to program.

So, what books would I recommend?

-The Pragmatic Programmer by Hunt and Thomas (http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X) (helps you learn good programming techniques)
-Debugging by Agans (http://www.amazon.com/Debugging-David-J-Agans/dp/0814474578) (teaches methods to effectively find bugs)
-Java After Hours by Holzner (http://www.amazon.com/Java-After-Hours-Projects-Youll/dp/0672327473) (a series of fun small but powerful projects explained in depth)
-Learning Java by Niemeyer and Knudsen (http://www.amazon.com/Learning-Java-Patrick-Niemeyer/dp/0596008732) (a "cookbook" of useful Java functionality)

I don't have a recommendation for an introductory book to learn from (before any of the above). You should be able to find one without too much trouble.

*I don't agree with the posts above. Learning programming by using a microcontroller teaches more about accommodating hardware than algorithm development. I think you should learn embedded programming (aka, microcontrollers) sometime, but most certainly not in the beginning of your programming career.

A comment about buying books($$$) vs learning online ($0): if you are not willing to invest in your education then you are in the wrong field. Those who refuse to buy learning materials almost always do worse than those who get good books on the subject (and the hardware, if appropriate...)

CameronM
11-05-2011, 11:51 PM
If you are still going to college I would see if your school offers safari books online its free if your schools signs up for the service. To find out just do a search with safari books online and your schools name. I found it through my college but it was kind of hard to find, and at least where I go nobody really knows about it. They offer a bunch of programming books and other tech related books too. All of the books are Ebooks but I think you can get a physical copy for a reduced price. I usually go to barns and nobles to find a name of a programming book and see if safari books has it, most of the time they do.

CameronM

Phil Pilgrim (PhiPi)
11-06-2011, 02:20 AM
Blueberry,

The main thing is not to be discouraged. It gets better. My introduction to programming came in my sophomore year of college via an informal introduction to Fortran from a college physics prof who volunteered his time in the evenings. It was the hardest thing I'd ever tried to learn! Seriously. I thought I would never "get it." But after that, it suddenly crystallized, and I eventually shifted from a career in physics to study computer science in grad school. It will "kick in" for you, too. Just keep at it!

-Phil

prof_braino
11-06-2011, 03:25 PM
Your skill level is directly proportional to the number of hours you spend programming. You won't be an "experienced pilot" until you logged enough hours of "flight time".
So practice is the key, like everything else in this life. Those proficient make it "look easy" because they have more experience to draw from. The key is patience, but this does not particularity help with getting an assignment done by tomorrow.

Remember that today's assignment is for a beginner of exactly your skill level, so you don't have to know anything fancier or more complex than today's lesson.

The whole trick is to "get your ducks in a row":
What are the inputs you will see?
What are puts are expected at the end?
What processing is needed to get from the inputs to the outputs?

Answer those, and you begin the "divide and conquer" process the gets us from a blank puzzle to a solid result. Equipped with answers to the previous three questions, one can be begin to divide the "processing" into to individual functions that turn the inputs into the required outputs. Answering the questions and dividing the processing into functions is the only actual hard part. Writing the code is simply mechanical, it just SEEMS hard because you haven't done it before, and you haven't followed the process but answering the three questions first.

Writing the code is impossible until the three questions are answered. (You can write code, but it won't solve your problem, since you didn't establish the problem you are trying to solve). Experienced do the analysis and "divide and conquer" by reflex, but can forget to point this out to new folks. That's why it looks easy for them and hard for you. Follow the process, it make life easy.

IF YOU ANSWER THE QUESTIONS and get your ducks in a row BEFORE you start writing the code, writing code becomes easy. Time spent should work out to something like 90% is time spent planning, and 10% is time spent coding. And then you're done. :)

If you do it the other way around, it isn't just 10% planning, 90% coding, there's an additional 90% debugging, another 90% fixing, and another 90% scratching your head wondering why your late and it took four times longer and still isn't finished. :(

Good process is not a new concept, but doesn't seem to be part of curriculum. No-one knows why.

SRLM
11-06-2011, 10:01 PM
Good process is not a new concept, but doesn't seem to be part of curriculum. No-one knows why.

Somehow, I have managed to get through almost 4 years of CS without a single week of class on good coding practices... It's rather disappointing. I'm glad there are good books out there that cover this sort of thing.

Blueberry
11-13-2011, 02:13 PM
Thank you all of your replies.

@SRLM: I guess I worded that a little weird. It's not my intention to substitute online resources for actual books, but to use them while I am in the process of getting those books.

We actually don't have Safari Books, I guess because we're a relatively small school.

@Prof Braino I understand what you mean, and when I think about it you are correct that computer science courses fail to center around planning but rather coding. I've been trying to write steps out since last year, but there are honestly some times where I just don't know what I should be thinking in terms of how to start and where to go after that. For example, on my midterm I was asked to create a program that takes in a name as a string and print out the hexadecimal values for each character (including proper formatting ie: spacing between each hex value). In reality it should be easy, but I didn't even know where to start or what I should be thinking in order to even get something down.

prof_braino
11-13-2011, 05:34 PM
on my midterm ....

The midterm is likely an example of the structure of the curriculum. It assumes you have used all the parts, and can recall them in the correct order for a new task. The alternative is to focus on all the steps before the coding, and if done properly, the code is simple and mechanical, like paint by numbers. And these steps for your mid term example would be:
High level Requirement - Echo hex values of text character input
System requirements: Input, processing, output.
Functional requirement:
input receive text characters: at this point ask for clarification, from keyboard? From File? From other? and code appropriate interface
Processing - identify the commands or set of commands that a) get the string, b) get a character from the string, c) get the byte value of the character
Output - ask for clarification,determine output to file, to terminal, other. determine command or set of commands to output a value as human readable text.

TESTS: Work out a set of inputs for which we know the output. For example, the digit 1 is hex 30, the character A is hex value something else, the this other set of values are not printable characters. If we put in a small set of these cases and they work, then we can be confident that most other cases might work.

In this method, we can now approach each functional requirement as a relatively simple thing to code. It no longer matters what the coding language or environment is, and I can turn any set of functions over to somebody else to do the actual code. Ducks in a row, divide and conquer, the actual work is the fun part and the coding is relatively trivial. In fact, the analysis is often accepted as the answer, and code snippets or pseudo code is sufficient. This applies to real life as well as school, since the analysis is the bulk of the work and any coder can take it and complete it.

Standard curriculum typically does not address the TESTS part. In fact, everything relies on the proper set of tests; which are critical and have to be determine first or as early as possible. The likelihood of success is directly related to passing the proper set of tests. Unfortunately, folks often do tests last, and discover too late that they have coded for conditions that are not needed, and not coded for conditions that are required.

Blueberry
11-14-2011, 12:51 AM
Even though the midterm passed, I might go back to it and break it into smaller steps and see where I can go from there. I think my problem was trying to figure out how the characters related to the hex values, meaning if by default if the program reads in characters using hex or decimal or binary.

Aside from planning out before coding, SRLM suggested to go back to take on a (I guess higher level) programming language instead of trying to learn the syntax of the propeller microcontroller. I'm really interested in learning how to program with one, but is it better for me to take a step back?

Kevin Wood
11-14-2011, 03:46 AM
Aside from planning out before coding, SRLM suggested to go back to take on a (I guess higher level) programming language instead of trying to learn the syntax of the propeller microcontroller. I'm really interested in learning how to program with one, but is it better for me to take a step back?

One thing that you need to keep in mind about computer programming is that programming language syntax does not equal programming. Programming languages are designed to make it easier for us to give instructions to a machine, but they don't give us the "understanding" of how to do what we instruct. We need to supply that understanding.

It works the same way with natural languages. Let's say that you speak language A, and you know how to make quiche. So you're given the task to explain how to make quiche to another person that speaks language B... but you can't, because you don't speak language B. Now let's say that you speak both A and B, but don't know how to make quiche. Given the same task, you get the same results, but this time for a different reason.

When it comes to computer programming, a lot of people are busy trying to learn a bunch of languages, when they really need to learn how to make quiche. Making quiche requires a recipe (an algorithm) that contains a set of variables (the ingredients) and functions (what you do with the ingredients). Programming requires an understanding of certain core principles the same way cooking does. Once a chef learns the core principles of cooking, all recipes become just a variation of applying those principles. The same with programming.

Here is an explanation that I gave to somebody with a similar problem on another forum. It may help you to understand what I've written here.



> The problem I have is that I don't know how to take my knowledge
of syntax and control flow and actually create something out of it.

Sure you do... you do it everyday in other areas of your life...
you start with the overall description of the task, then you break
it down into smaller & smaller steps until you complete the task.

For example... putting on your clothes...

Task: put on clothes
Steps: 1. put on pants
a. get pants from dresser
aa. walk to dresser
ab. open drawer
ac. reach inside
ad. grab pants
ae. lift pants from drawer
b. put left leg through hole
ba. position pants
bb. lift leg
bc. insert leg in hole
bd. put leg down
c. put right leg though hole
ca. etc.
d. pull up pants
da. etc.
2. put on shirt
3. put on socks
4. put on shoes

This is same way that you program...
break the problem down in to smaller and smaller steps,
until they get so small that the can be implemented with
syntax and control flow...

def insertInto(clothing, hole, appendage, side):
if (clothing == 'pants'):
if (appendage != 'leg'):
print "you can't wear your pants on your " + appendage
elif (hole != side):
print "try your other " + hole + " " + appendage
else:
print "good job!"
else:
print "forget about your " + clothing + ", you're not wearing any pants!"


insertInto('pants','right','leg','right')
insertInto('pants','left','leg','right')
insertInto('pants','right','arm','right')
insertInto('shirt','right','arm','right')



As for learning the Propeller, Parallax is planning to release a new Propeller Board of Education next month, and I think that there are plans for a version of "What's a Microcontroller" to go with it. If you can wait until then, this might be the most beginner-friendly way to go. But as far as taking a step back... no, you don't need to. Just focus on learning core concepts. However, that said, if the syntax of the language that you are being taught is getting in the way of you learning core concepts, then definitely switch languages outside of class.

Blueberry
11-14-2011, 04:23 AM
Haha, humorous way of putting it...

I guess sometimes I'm aware that syntax doesn't make the program as much as logic does... But I do forget it each time I have to deal with another one in another class and can barely grasp things.

I kind of do have a microcontroller, I had to buy one for a class... I think the most I would need are capacitors, maybe some servos... whatever else and the book.

4x5n
11-14-2011, 04:48 AM
Even though the midterm passed, I might go back to it and break it into smaller steps and see where I can go from there. I think my problem was trying to figure out how the characters related to the hex values, meaning if by default if the program reads in characters using hex or decimal or binary.

Aside from planning out before coding, SRLM suggested to go back to take on a (I guess higher level) programming language instead of trying to learn the syntax of the propeller microcontroller. I'm really interested in learning how to program with one, but is it better for me to take a step back?

To me I think the problem was a "trick question"! :-) The characters are in fact stored in hex and all you needed to do was output each byte in hex. Read the string into an array (or index the string depending on the language) and output the value in hex. The key is to not make things harder then they need to be. As Albert Einstein used to like to say. Everything as simple as possible and no simpler!

4x5n
11-14-2011, 04:59 AM
I speak from my perspective as a former beginning programming tutor, and a current freshman engineering mentor perspective. This is what I've noticed working in a university environment, and all my opinion. Take it with a grain of salt.

Many students come to me with trouble in their classes, usually math and computer science. For the most part they have the same problem that you do: they simply start trying things with their program, run it and see if it works. It's not very effective, and it take's too much time.

This scatter shot approach almost always stems from a lack of understanding of the language and the problem. As simple as it sounds, this is important to recognize. I always recommend that students start with an "Introduction to XX Language" book, and work through it from cover to cover. I would probably start with Java* as the particular language, but any works. It's important to work through the whole book, typing out the programs that it lists and running them, then making small modifications and seeing how that effects the outcome. These steps are particularly effective on some of the larger (multi page) listings that the better books have.

You should read the entire book cover to cover even if you do not understand all of it, or even most of it past the first half or so. By reading the whole book you familiarize yourself with the language and general programming concepts that it represents. Later, when those topics come up again, you will have a framework to place the new information into.

After you've worked through the introductory book, I would suggest getting three books: a book on code style, a book on debugging, and a cookbook for the language that you are programming in. The first two books will allow you to write more maintainable code and (obviously) find your bugs faster. The last will help you know what is possible with a language.

I generally don't recommend learning from online resources. Online sites (like the wonderful cplusplus.com (http://www.cplusplus.com/)) are great for refreshing memory, but not for learning. Online material is harder to comprehend, retain, and relocate down the line. Use such information judiciously when learning to program.

So, what books would I recommend?

-The Pragmatic Programmer by Hunt and Thomas (http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X) (helps you learn good programming techniques)
-Debugging by Agans (http://www.amazon.com/Debugging-David-J-Agans/dp/0814474578) (teaches methods to effectively find bugs)
-Java After Hours by Holzner (http://www.amazon.com/Java-After-Hours-Projects-Youll/dp/0672327473) (a series of fun small but powerful projects explained in depth)
-Learning Java by Niemeyer and Knudsen (http://www.amazon.com/Learning-Java-Patrick-Niemeyer/dp/0596008732) (a "cookbook" of useful Java functionality)

I don't have a recommendation for an introductory book to learn from (before any of the above). You should be able to find one without too much trouble.

*I don't agree with the posts above. Learning programming by using a microcontroller teaches more about accommodating hardware than algorithm development. I think you should learn embedded programming (aka, microcontrollers) sometime, but most certainly not in the beginning of your programming career.

A comment about buying books($$$) vs learning online ($0): if you are not willing to invest in your education then you are in the wrong field. Those who refuse to buy learning materials almost always do worse than those who get good books on the subject (and the hardware, if appropriate...)

I couldn't agree with you more!!!!

I remember when I was in college (a long long long time ago I admit) I had the same professor for college algebra and calculates. At the time I hated him as much as one human could hate another!! Later I realized how much the man taught me!! When I had him for algebra he used to love giving us "story problems" his claim was that in the real world you "boss" wasn't going to give you an equation and then asked to solve for x or y. It's going to be up to you to create the equation! Later in calculus he would give us course work that I would spend all weekend on 5-6 "problems"!! I learned then that I did better when I would go out and take a walk and think about the problem for an hour or two before sitting down and "solving" it. I wish I could run into that professor today so I could shake his hand and buy him a beer or three as thanks for all he taught me. He didn't just teach me algebra or calculus!! More importantly he taught me something far more valuable, he taught me how to solve problems!!!!!

SRLM
11-14-2011, 05:49 AM
The alternative is to focus on all the steps before the coding, and if done properly, the code is simple and mechanical, like paint by numbers.

I disagree. The syntax and the language isn't the focus in problem solving, but translating high level requirements to code requires a base of knowledge to be done properly ("functional requirements" in your steps). I don't think it is simple to gain a good understanding of the language. After all, a good understanding of C would mean that we never had buffer overflow problems...

In any case, I prefer to learn as much as I can about the low level syntax/structure of a language before I do any serious programming in it because I don't want to be distracted by an inability to convey intentions to the code. In the physical word it's called ready at hand. (http://en.wikipedia.org/wiki/Heideggerian_terminology#Ready-to-Hand)

bsnut
11-14-2011, 10:09 AM
Everyone has cover everything so, my post is going to be short to the point.

Remember when programming a microcontroller it's all about sequence of operation and how the application is going work. This also means you need to know how many I/O you will use in your application as well. Once you know this, the programming is the easy part.