Shop OBEX P1 Docs P2 Docs Learn Events
It's time to really learn C. Need some advice.. - Page 2 — Parallax Forums

It's time to really learn C. Need some advice..

2

Comments

  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-08-03 15:12
    I suppose one could add on a library in plain C rather than C++. But regardless, there is a lot that is just 'the Arduino way' of doing things. For students wanting to learn mainstream C, they will have to backtrack some.

    Hundreds of thousands of Arduino users who have never programmed before would disagree with you. They developed perfectly fine, and a majority have not read any programming book beyond the Arduino language reference, and maybe a third-party Arduino activities book. This isn't to say they can't if they want to, as this material is also available.

    There's no need to call attention to C++, because they don't have to. Since it's not CS101 they're trying to teach, there's no need to stop and explain how a phaser works (old Star Trek axiom; Joe Friday never stopped to explain how his revolved worked, and the audience simply accepted it.) More importantly, classes, objects, members, methods, and properties are all a product of most every *mainstream* language a student is likely to use in real work. This includes Java, JavaScript, C#, even VB.net. Oh, and Spin, too.

    There are plenty of playground tutorials for the Arduino on creating non-object libraries, which you'd do anyway if you're trying to leverage some piece of hardware that cannot be classed (or would make no sense to class).

    I would suggest you look on Craigslist or some other online job board to see what employers are actually looking for these days. Then ask yourself why a microcontroller designed by teachers for students uses the language mix it does.
  • whiteoxewhiteoxe Posts: 794
    edited 2014-08-03 16:05
    Hundreds of thousands of Arduino users who have never programmed before would disagree with you.

    There are plenty of playground tutorials for the Arduino on creating non-object libraries,

    Hi Gordon, still trying to wrap my head around so many concepts.... can you explain exactly but non too technically what a Library is ? All I know is that they offer more or easier functionality when you use an INCLUDE statement. But then you have to be sure the umm,,err,.. library is there because INCLUDE is not the same as saying abracadabra ;)
  • whiteoxewhiteoxe Posts: 794
    edited 2014-08-03 16:10
    I think I've created battle plan..

    I'm going to take Gordon's advice and work the first part of the K&R book for the basics, then after I read over some source code that is of interest to me to see what I can understand of it., I'll launch into PropellerC.

    Expect questions.
    One thing not so great about Amazon is most technical books are aound the same price no matter if you buy the hard copy or the kindle version. That K & R is aound $47

    you'll save 5 bucks by getting it on kindle, bah !!!
  • whiteoxewhiteoxe Posts: 794
    edited 2014-08-03 16:23
    I had a friend that years ago he gave me his C books and floppy disks , think it was Borland C++ , not positive , but there were at least half a dozen books that were part of the whole package. I didn't touch it. I was having enough trouble with COBAL and one manual .
  • John A. ZoidbergJohn A. Zoidberg Posts: 514
    edited 2014-08-03 19:44
    I started a C and C++ programming when I was 14 - was a bored teenager trying to have some thrills on a computer that time. Plus, some of the games I played on computer inspired me to learn C/C++. There I went, got a "Sams How to learn C++ in 24 Days" and got stuck after "Inheritance".

    C/C++ isn't too difficult once you get past Pointers and Structures. The Pointers can get very frustrating if you are new to programming, but if you have done some assembly before, it may not be difficult. Get a "Dev C++" compiler, and get a normal C-tutorial book or read tutorials online. It's very straightforward.

    I've written an amount of C code for PIC32. The MPLAB-X is wonderful - liked it very much. However, the GCC inside has optimisations up to level 1 only, and you need to buy the license for better optimisations. The PIC32's peripheral registers are straightforward and easy to handle.

    The ARM ones, especially the STM32s, are feature rich, but I have experiences integrating Eclipse, GCC and the STM32Cube libraries. The outcome is "not fun". Browsing the datasheets for STM32s is a tedious job, and the examples provided are really sparse. Unfortunately, I have to use ARM for my job and I couldn't use commercial compilers due to the cost factor (the institute doesn't have one also) so I have to cobble up the Eclipse one as a closest alternative.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-08-03 20:33
    The Pointers can get very frustrating if you are new to programming,
    I'm not new to progamming, and C pointers are still frustrating. Somehow Perl references make more sense, even though I know that they're the same thing as pointers.

    -Phil
  • whiteoxewhiteoxe Posts: 794
    edited 2014-08-03 21:24
    I wish I could sue my university for teaching VB instead of C ;) Making all those pretty GUI's felt powerful but really a waste of time ! I'm just being mean.... it was fun and just introduction to programming.
  • TymkrsTymkrs Posts: 539
    edited 2014-08-04 05:29
    Why not listen to First C? http://tymkrs.com/shows - I approach it from only having known Spin :p
    Heater. wrote: »
    But that's my point Ray. From the point of view of someone who has perhaps never seen a micro-controller before or is totally new to programming, never mind C, the K&R thing may be just a bit to much. Enter people like the Arduino creators who take it from the beginning in very simple steps. I have always imagined that was the point behind SimpleIDE and the Parallax materials.

    Turned out that SimpleIDE became ComplexIDE (As compared the Arduino IDE) but my point still stands.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-08-04 11:57
    whiteoxe wrote: »
    I wish I could sue my university for teaching VB instead of C ;) Making all those pretty GUI's felt powerful but really a waste of time ! I'm just being mean.... it was fun and just introduction to programming.


    I'm sure your university would disagree with you as a lot of commercial software is written in VB.
  • whiteoxewhiteoxe Posts: 794
    edited 2014-08-04 12:43
    I'm sure you are right JMac, asking my opinion is talking to the wrong end of the horse, I simply didn't know enough to be able to comment. The lecturer who was my tutor was more than capable and a real pro, you can just tell. He actually wrote the program the uni used for keeping track of students and their courses and grades etc,etc,etc. He mentioned one day that as he was leaving the uni the next year there was going to be some issue with it being maintained. I couldn't understand that as I thought if the program is written then anyone can just keep using it forever, who needs to be maintaining anything ?? Knowing the calibre of the bloke im sure he figured out a solution !!!
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-08-04 14:53
    JonnyMac wrote: »
    I'm sure your university would disagree with you as a lot of commercial software is written in VB.

    In the mid 200s I did a big project for Technicolor using VB.net. It wasn't necessarily my first choice, but their IT department had settled on it for maintainability, and in the end I grew to like it. I still tend to crank up VB over C#. (And this project involved writing a low-level DirectShow media player that integrated with a database.)

    So yes, there are plenty of companies, large and small, that not only allow the use of VB, but require it because down the road they know they can always get someone familiar with the codebase.
  • jazzedjazzed Posts: 11,803
    edited 2014-08-04 14:56
    VB.net can be reverese engineered into C#.net. Best of both worlds unless you're trying to protect some code secret.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-08-04 15:00
    whiteoxe wrote: »
    Hi Gordon, still trying to wrap my head around so many concepts.... can you explain exactly but non too technically what a Library is ? All I know is that they offer more or easier functionality when you use an INCLUDE statement. But then you have to be sure the umm,,err,.. library is there because INCLUDE is not the same as saying abracadabra ;)

    The great thing about the Arduino is the (over) abundance of primers, tutorials, and references. Their main language page has links that explain these concepts, and more. The same concept applies to Propeller C, and the tutorials on learn.parallax.com provide additional insight from a Prop perspective.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-08-04 15:05
    jazzed wrote: »
    VB.net can be reverese engineered into C#.net. Best of both worlds unless you're trying to protect some code secret.

    I think the point is any MSIL code can be reversed back into human-readable statements. It's not just VB. Or maybe I misunderstood what you meant.

    There are "foggers" and other obfuscators that do a pretty good job at mangling. For most applications you might want to protect they're okay. I used one called Skater that was pretty decent, but in the end, for most commercial applications no one cares enough to reverse engineer it.
  • jazzedjazzed Posts: 11,803
    edited 2014-08-04 15:13
    I think the point is any MSIL code can be reversed back into human-readable statements. It's not just VB. Or maybe I misunderstood what you meant.


    Yup any MS CIL code.
    That's how I first saw the inside of Homespun (when Michael was making excuses ... just joking).
    I've used it to save other programs from the dust bin too.
  • whiteoxewhiteoxe Posts: 794
    edited 2014-08-04 15:44
    I actually got to love VB. iT was so readable and easy to read and write to the MS database and a lot of fun.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2014-08-04 17:15
    twm47099 said:
    I think I fall into that category. While I tried to learn C on my own back in the 1980's and did read K&R, I never got to the point where I knew when to use a '&' or a '*'. I haven't used C since then

    Yes, that's me too. I'm slowly starting to understand pointers, but it has taken me a long time. Maybe my experience might help someone?

    I think I went wrong when I misunderstood all the explanations. The all go along the lines of
    "A pointer is a variable whose value is the address of another variable"

    and then they go on to say that a * is used to designate a pointer. And then I started thinking in Propeller mode and figured that the @ symbol (ie the memory location of a variable) was the same as a * symbol. And then I got really confused because I thought that every time a * was used it was calculating the address, in some sort of recursive fashion. My misunderstood version does actually work if you only have one level of recursion. Boy was I wrong!!

    So ... pointers for BASIC programmmers:

    First, read this page http://www.tutorialspoint.com/cprogramming/c_pointers.htm

    Here's what I think is really going on (and I still could be wrong here...)

    A pointer is a kind of variable. In BASIC, you might have a string, an integer and a character. And in the same fashion, you have a pointer.

    Follow that tutorial as it splits it up into stages.
    Declare a variable as being a pointer
    Calculate the address of another variable, and put it in our pointer variable
    Print it
    And then do something totally confusing. Ok, code here
    #include <stdio.h>
    
    int main ()
    {
       int  var = 20;   /* actual variable declaration */
       int  *ip;        /* pointer variable declaration */
    
       ip = &var;  /* store address of var in pointer variable*/
    
       printf("Address of var variable: %x\n", &var  );
    
       /* address stored in pointer variable */
       printf("Address stored in ip variable: %x\n", ip );
    
       /* access the value using the pointer */
       printf("Value of *ip variable: %d\n", *ip );
    
       return 0;
    }
    

    The last bit is the confusing part. To quote the tutorial:
    "finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand."

    So this prints the value of the variable, and it is *ip, and this is the same syntax as is used to declare the pointer but it is doing something different.

    So in C, it seems that the * is multiplication, declaration of a kind of variable, and the calculation of the value at that variable.

    So like OBC, I think maybe I know enough C to be dangerous *grin*.

    Hehe, right now I've decided to torture C a bit by turning it into an object oriented language (not C++ mind, this is standard C). I want an IDE with autocompletion of object methods like in vb.net.

    Back to coding...
  • idbruceidbruce Posts: 6,197
    edited 2014-08-04 17:58
    And this project involved writing a low-level DirectShow media player
    It's time to really learn C. Need some advice..

    My advice is to put DirectShow projects on the back burner until you have a very good grasp of C/C++ :)

    EDIT: In all seriousness, pick up all the books you can on the subject and dive in.
  • potatoheadpotatohead Posts: 10,261
    edited 2014-08-04 19:54
    OBC: How did you learn Spin?
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2014-08-04 20:16
    @Potatohead,

    Thanks for asking..

    I tend to be the type that learns by having a project to work on. In the case of Spin it was working with and making modifications to Femtobasic that gave me the confidence to branch out into my own Spin creations. I credit Mike Green for alot of "code by example" learning.

    I'm a few pages into the K&R chapter 1. So far I've not hit any walls. It's a wordy text, but I like that it doesn't skip explaining things I'm typing in, by asking me to just type it in and take it for granted.

    Jeff
  • David BetzDavid Betz Posts: 14,516
    edited 2014-08-04 20:26
    I tend to be the type that learns by having a project to work on. In the case of Spin it was working with and making modifications to Femtobasic that gave me the confidence to branch out into my own Spin creations. I credit Mike Green for alot of "code by example" learning.
    This is a very good way to learn any language and I agree that Mike Green produces well written and what is more rare, well *documented* code that you could learn a lot from.
  • potatoheadpotatohead Posts: 10,261
    edited 2014-08-04 21:48
    Been a while since we last talked.

    In any case, I suggest that's how you learn C. David expressed my sentiments exactly. What you need are links to a few C projects you can modify and learn from.
  • TorTor Posts: 2,010
    edited 2014-08-05 03:01
    Programming courses in college or elsewhere shouldn't really be about learning some specific programming language, that is a different target. To learn programming is what it should be about. The language is just a tool, so if it's C or VB shouldn't matter. Actually C may not be the best one for learning programming because it's easy to get hung up in the quirks (like when learning how to write literature you get bogged down in MS Word's formatting menus. That doesn't teach you writing at all.) I don't know VB so I don't know how it fits. I know that in the past (not anymore I think) Norwegian universities would teach programming via the Simula language, learning about structured and object oriented methods at the same time. Pascal was designed to be such a teaching language, it did not (in its original specification) have any I/O features to talk about, because real use was not its target.

    The point is that when you have learned structured programming it will be easy (and more and more so) to just pick up another one (like C) when you need to. C was not my first language at all, and I can't for the life of me remember exactly what I did to learn it, all I know is that it must have happened quickly and I probably went via the "C projects you can modify and learn from" (quote: potatohead) method. Probably.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-08-05 10:07
    idbruce wrote: »
    My advice is to put DirectShow projects on the back burner until you have a very good grasp of C/C++

    Surprisingly not needed, unless you're writing traditional (non DMO) filters. A well-kept secret is an unofficial .NET wrapper to all the traditional C++ API calls to the DirectShow interfaces. It supports about 95% of the functionality. It's even possible to capture the callback frame at 30ps and process the bitmaps to add things like superimposed subtitles. This was on an XP machine with a P4.

    Not saying it was easy, and it consumes over a year of my life. But it's amazing what .NET-anything can do. If you have an interest in learning a modern C variant, getting the *free* .NET C# express download is an excellent way. You can write GUI or console apps with it, and it's fully functional. Makes for a neat backend for Propeller projects, too, like your own customized serial terminals. If you dislike Microsoft there's always Mono.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-08-05 10:13
    Tor wrote: »
    Programming courses in college or elsewhere shouldn't really be about learning some specific programming language, that is a different target. To learn programming is what it should be about.

    Most of the colleges around here do it this way. The first course is a generic introduction to programming. They cover all the basics, plus player in the year a little hands-on with whatever language the instructor likes.

    And this can be a problem. The inspecificity makes for a very boring experience, IMO. A lot of non-CS students drop out, it's so dull. Going back to the popularity of the Arduino, I think this is one of the areas that proved you can get the basics of programming, C, and embedded applications all at once, and do fun things along the way.

    I've seen a few forward-thinking schools teach programming using open source game engines, many of which use JavaScript, and are playable on desktops and mobile devices. I've heard the dropout rate is nearly nonexistent.
  • Heater.Heater. Posts: 21,230
    edited 2014-08-05 10:33
    Yep, and now you explore embedded MCU fun using JavaScript: http://www.espruino.com/
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2014-08-05 10:34
    Head First C

    By David Griffiths, Dawn Griffiths
    Publisher: O'Reilly Media
    Final Release Date: April 2012
    Pages: 632




    3.6
    Read 14 Reviews
    Write a Review











    Ever wished you could learn C from a book? Head First C provides a complete learning experience for C and structured imperative programming. With a unique method that goes beyond syntax and how-to manuals, this guide not only teaches you the language, it helps you understand how to be a great programmer. You'll learn key areas such as language basics, pointers and pointer arithmetic, and dynamic memory management. Advanced topics include multi-threading and network programming—topics typically covered on a college-level course.
    This book also features labs: in-depth projects intended to stretch your abilities, test your new skills, and build confidence. Head First C mimics the style of college-level C courses, making it ideal as an accessible textbook for students.
    We think your time is too valuable to waste struggling with new concepts. Using the latest research in cognitive science and learning theory to craft a multi-sensory learning experience, Head First C uses a visually rich format designed for the way your brain works, not a text-heavy approach that puts you to sleep.













    http://shop.oreilly.com/product/0636920015482.do
  • jazzedjazzed Posts: 11,803
    edited 2014-08-05 10:48
    Head First C


    Wonderful table of contents. Makes me want to read it too.
  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-05 11:50
    I have a friend, she's 38 and mother of 3 kids. Her previous programming experience was C at high school and VBScript/MS SQL at work for last 10 years. Now she had to change a job, and go to microcontroller programming. Today is day 20th she switched to and she already doing interrupts, adc interaction, pwm, touch buttons and so on, using MPLAB X and datasheets. So if she can do, why not you too? In fact, I've got so excited, I'm thinking about learning C by myself, abandoning my 30 year BASIC experience :D
  • ChaosUKChaosUK Posts: 5
    edited 2014-08-11 06:23
    There is a free Computer Science course from Hardvard that covers C if you are interested -

    https://www.edx.org/course/harvardx/harvardx-cs50x-introduction-computer-1022#.U-jDkWN0qpI
Sign In or Register to comment.