Looking for richly commented code.

This is a discussion on Looking for richly commented code. within the C Programming forums, part of the General Programming Boards category; Hi! I'm learning C programming (I chose C because I want to program MCUs as well). I already learned the ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Location
    Hu, Pécs
    Posts
    7

    Wink Looking for richly commented code.

    Hi!
    I'm learning C programming (I chose C because I want to program MCUs as well).
    I already learned the basics, but now i want to learn how to program GUI and audio,midi recording,processing.
    But I don't think buying a 400 or 1200 pages long book would be the best option because:
    I find that i can learn much faster from commented source codes than reading pages of definition with a short abstract example code. The result of such method is that i know what it does, maybe even why, but i don't know how to use it (or why would I use that instead of something else) in a real program, thus i forget it.


    I don't think I'm alone whit this, so i think making a good collection of richly commented source codes of various programs would help a lot of people.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Just think of your "400 or 1200 pages long book" as a collection of very "richly commented source codes". Lots and lots of comments accompanying a small amount of example code. It's exactly what you are looking for!
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Learning from code is nice and very productive if you know what you're doing. But if you don't understand the language, your "coding" can involve just searching through the examples to find some snippet that already does exactly what you need. If you want to learn from code, that's great, just be careful that in your own code you don't resort to copy-and-paste all of the time.

    I'd suggest looking at some tutorials online. They're usually faster-paced than textbooks and may be more suited for your taste. I don't know of any such tutorials, but this one looks good: C Tutorial - Chapter 1

    If you don't like it do a few searches of your own, see what you come up with.

    [edit] This may interest you. A development process [/edit]
    Last edited by dwks; 09-16-2010 at 06:47 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    Honestly I ignore half the 'green' lines in MSVS b/c 80% of the time they are incorrect, out of date, or in the wrong place due to merges and so forth.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nemuikuma View Post
    Hi!
    But I don't think buying a 400 or 1200 pages long book would be the best option because:
    I find that i can learn much faster from commented source codes than reading pages of definition with a short abstract example code. The result of such method is that i know what it does, maybe even why, but i don't know how to use it (or why would I use that instead of something else) in a real program, thus i forget it.
    Little known secret in technical trades...

    You don't need to remember ANYTHING so long as you know how to look stuff up.

    The goal of reading the book is to absorb concept, not function calls.

    Programming is only peripherally about function calls... You can't program any behavior you don't understand, no matter how many function calls you memorize.

    Afterwards the book becomes a reference text when you need to look something up...

    Consider windows API... something like 10,000 function calls. Nobody can reasonably expect to remember even a small portion of that. So we get the 1200 page book, scan it for concept and then look stuff up when we need it.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,262
    Emphasis mine:
    Quote Originally Posted by nemuikuma View Post
    Hi!
    The result of such method is that i know what it does, maybe even why, but i don't know how to use it (or why would I use that instead of something else) in a real program, thus i forget it.
    "why" is actually the most important part of commenting code in the real world. Any reasonable programmer can figure out what a function is doing, or how, even if it take some a bit longer than others, but the why part is the part that often code alone simply cannot answer.

    Very little code commenting goes into great detail in the how, you only really find that in code specifically written for a beginner to digest, e.g. a tutorial. I'm not really sure what you're after, besides some links to good tutorials. If that is the case though, you'd need to specify what aspects of programming you are wanting to learn via a tutorial, and what level you think you're at.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Sep 2010
    Location
    Hu, Pécs
    Posts
    7
    Thanks for the replays

    Quote Originally Posted by MWAAAHAAA View Post
    Just think of your "400 or 1200 pages long book" as a collection of very "richly commented source codes". Lots and lots of comments accompanying a small amount of example code. It's exactly what you are looking for!
    That is my problem with the books, small code, usually without example of"real life" example usage.
    I don't have anything against books( besides their price ) and I don't say that this way i can't learn it, but it takes much more time for me.
    I also read a few books, and I know how the c language works, it's syntax, keywords, basic functions, pointers,etc.
    I want to learn how to make a full screen , user customizable GUI, how can my program communicate with midi devices, and how can i write anything related to audio signals, as much OS independent as it can be.

  8. #8
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by nemuikuma View Post
    [...]as much OS independent as it can be.
    Here There Be Monsters!

    For a beginner, I think it would be best to start developing for the platform they use daily, and branch out once they are experienced enough to handle the can of worms that is cross-platform development.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nemuikuma View Post
    Thanks for the replays
    That is my problem with the books, small code, usually without example of"real life" example usage.
    I don't have anything against books( besides their price ) and I don't say that this way i can't learn it, but it takes much more time for me.
    I also read a few books, and I know how the c language works, it's syntax, keywords, basic functions, pointers,etc.
    I want to learn how to make a full screen , user customizable GUI, how can my program communicate with midi devices, and how can i write anything related to audio signals, as much OS independent as it can be.
    Think big... start small

    Those snippets in the book aren't trying to teach you how to make GUIs and handle Midi messages (an entire can of worms in itself)... they're showing you the basic steps used in all programs... variables, assignment, conditional, loop, selection, procedures, etc. Any program you write is going to be nothing but a sequence of those small steps strung together to achieve a desired behavior.

    Don't be impatient... do the small steps first. Write that cheque book balancer and the termperature converter. These are where you learn program structure, troubleshooting and debugging skills that will serve you very well later on. Over time your code will naturally become larger and more complex as you take on bigger challenges, but those basic skills will still be the backbone of everything you do.

    Programming is not a skill you master in a week... One of the tutorials I used while learning was titled "C in 21 days"... and indeed one lesson a day and 21 days later I was writing C language programs... It should have been titled "C in 21 months" because even years later I am still learning better ways to do things...

    The one thing you don't want to fall into --and this is happening more and more-- is the trap of relying upon other people's code to create your own programs. That is, don't let yourself become a "script kiddie" who only knows how to cut and paste blocks of code and is totally lost when something goes wrong... That's not programming, it's theft.

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > Teach Yourself Programming in Ten Years
    In 21 days, you will be able to recognise the difference between a C++ program and a hole in the ground with a reasonable degree of success.

    What you won't be by ANY stretch of the imagination be is a competent C++ programmer.

    If you're already a competent programmer in a similar language, then you could become a fair C++ programmer in 21 days, but for sure it won't be by reading noddy books with words like "21 days" in the title.

    Competent comes with the months and years of practice and mistakes, and is not something you just download "matrix style" in a short time and you can calmly announce "I know kung fu". If you try it, you will get your ass kicked!.

    @nemuikuma
    You're not likely to find what you want outside of academia.

    Assuming that the comments are even correct (see Bubba's comment), they're probably sufficient only for the people who are actively writing and maintaining the code. Which means they're not likely to be telling a newbie what they want to know.

    For sure, you're not going to see in any production code
    int i; // declare an int variable for indexing the foo array

    Comments in homework typically demonstrate the authors knowledge (or lack) of the language.

    Comments in real code generally only tell you what isn't obvious from reading the code. In particular, since it costs time/money to both write the comment and maintain it thereafter, you'd better have something worth saying!.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by Salem View Post
    Competent comes with the months and years of practice and mistakes, and is not something you just download "matrix style" in a short time and you can calmly announce "I know kung fu". If you try it, you will get your ass kicked!.
    That's certainly funny you're posting.

  12. #12
    Registered User
    Join Date
    Sep 2010
    Location
    Hu, Pécs
    Posts
    7
    The comments were very useful
    I never assumed that programming in any language can be learned in 21 days or in 24 hours ( yes, I seen a book with this tittle ).
    But I'm not new to programming, 5-6 years ago i programmed a lot in visual basic, but since than i didn't coded much.
    I really liked Teach the Yourself Programming in Ten Years article
    It reminded me that learning play the guitar took me about 6-7 years.
    I always loved practicing and a always want to be better in it
    So i know the basics of C, but i don't know what's next, I mean I practiced a lot with math, string, loops, etc... I can't imagine what else could i do with this.
    I want to practice (start learning) the things that I'm really interested in.

  13. #13
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    265
    Quote Originally Posted by nemuikuma View Post
    The comments were very useful
    I never assumed that programming in any language can be learned in 21 days or in 24 hours ( yes, I seen a book with this tittle ).
    But I'm not new to programming, 5-6 years ago i programmed a lot in visual basic, but since than i didn't coded much.
    I really liked Teach the Yourself Programming in Ten Years article
    It reminded me that learning play the guitar took me about 6-7 years.
    I always loved practicing and a always want to be better in it
    So i know the basics of C, but i don't know what's next, I mean I practiced a lot with math, string, loops, etc... I can't imagine what else could i do with this.
    I want to practice (start learning) the things that I'm really interested in.
    Start some projects then. I'm into network programming so thats what I've been doing. I'm getting into GUI programming(GTK+) and I want to learn to use SDL to make simple (crappy) games.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nemuikuma View Post
    I want to practice (start learning) the things that I'm really interested in.
    Then you should start writing code that helps you understand the tasks you are interested in.

    Need to look up a host name on a LAN?
    Experiment with Winsock calls such as "GetHostByName" and others...

    It's all leading you to the same place...

  15. #15
    Registered User
    Join Date
    Jan 2010
    Location
    Ca, US
    Posts
    29
    Quote Originally Posted by nemuikuma View Post
    The comments were very useful
    I want to practice (start learning) the things that I'm really interested in.
    Something I did was re-write a small program that I already used. If you can pick one that is open source you can go back and see how someone else did it (don't just copy it, look after you have a working version).
    One I can think of was the tail program, I was working on a DOS like OS that we run for some machines at work and it did not have a tail command.
    So I wrote mine, then went back to an open source version to see how they did it. I found many edge cases I did not even think about and places I could have tightened up the code.

    Dylan
    Last edited by dylan; 09-19-2010 at 11:54 AM. Reason: hit post before preview

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21