Shop OBEX P1 Docs P2 Docs Learn Events
Should I be learning C? — Parallax Forums

Should I be learning C?

DynamoBenDynamoBen Posts: 366
edited 2015-03-18 00:42 in Propeller 1
So I'm noticing an increased focus on C by Parallax which got me thinking, should I be learning C? While we can debate the merits of C over Spin what I'm wondering is if future products like the Prop II might be based on C over Spin. If so then learning C now with the Prop I would be wise. Thoughts?

Comments

  • LeonLeon Posts: 7,620
    edited 2015-03-12 08:52
  • Courtney JacobsCourtney Jacobs Posts: 903
    edited 2015-03-12 09:09
    C is a foundational programming language that is very important in the educational world, which is why Parallax has recently made the push towards accepting and promoting the use of C language with our Propeller-based products. Education is, and has always been, one of Parallax's most important focuses.

    This being said, Parallax has not, and will not, reduce its support and investment in Spin (the PropellerIDE project and new Jon Titus book are examples of recent Spin initiatives). Supporting multiple programming languages with our products naturally becomes a balancing act as we try to accommodate and account for the needs of every audience, from educators, to DIY hobbyists, to commercial customers.

    Which language(s) you choose to learn and program in should ultimately be your decision. From a personal standpoint as part of the education team here at Parallax, I would be thrilled if you gave our Propeller C Learning System a chance, but the goal of providing you with multiple options is to allow you to customize your own experience with our products.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2015-03-12 09:13
    Spin along with PASM keeps one pretty close to learning the ins and outs of managing the Propeller's parallel architecture.

    C was developed at a time when it was needed to serve mainframe computers that needed portable programs... mostly single CPU machines that were shared by many. Then it became the mainstay of computers with OSes. The Propeller 1 is a microcontroller that generally is used without an OS.

    While the C language itself is fairly straight-forward -- the libraries are architecture dependent and that pretty much breaks the ideal of portable programs. Also, the Propeller has 32Kbytes of hub ram, which is very tight for modern C applications.

    I tend to feel that C will perform better on the Propeller 2 (which is supposed to provide 512Kbytes hubram) and it is still worth focusing on SPIN and PASM to get the most out of the Propeller 1.

    OBEX is a mature and useful reference resource for SPIN and PASM.

    ============

    I had some high hopes of simple porting of Arduino programs to the Propeller, but the Arduino programs can come from all sorts of Arduinos - some with far more resources than the Propeller 1 AND the so-called Arduino code may have been yet another C program that is not original to Arduino. So things can get heavily bogged down in trying to transfer programs that seem quite simple from Arduino to the Propeller.

    Some C programs may transfer nicely, but many are far more than most can handle. You will find yourself dedicating a big chunk of time in learning the ins and outs of C compiler error and warning messages. Spin will seem heavenly.

    So at this juncture, I just don't see much advantage for myself. I end up in an endless maze of GCC and C++ documents from many different sources and projects often die in confusion.

    ***********************
    If you desire to learn C on the Propeller, use the Propeller tutorials and the Propeller Simple libraries. You will get a lot further in a shorter amount of time.

    And don't expect to get much done with floating point. Beginning C users seem to never realize that integer maths (signed and unsigned) are much faster and waste less resources.... they don't have to on a big desktop. But floating point libraries on the Propeller tend to demand a lot. The Propeller is a microcontroller, not a microcomputer. It doesn't have 4Gbytes of Ram and a math co-processor.

    +++++++++++++++

    In other words, if you learn C in the Propeller way, it can be delightful. But trying to learn how to master C for many different platforms as a means to borrow code for the Propeller can be quite daunting.
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-03-12 09:36
    If you need to learn <insert language> or want to learn <insert language> and have the time, then by all means do it.

    If you have an end goal that includes <insert language>, then you will be motivated, so go ahead and learn <insert language>.

    If you enjoy exploring and playing with different languages and have the time, then learn <inset language>.

    As Courtney said, C is considered a foundational programming language. So it is good to learn it to some degree.

    If your goal is a Propeller project, then Spin could be your better choice. Unless someone fires Chip, I doubt if Spin will become a non-player on any Propeller. :D

    Whatever language you choose, your underlying goal should be to learn to program. Languages change and you end up learning (and forgetting) many. The underlying programming concepts are relatively transferable.
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 10:19
    DynamoBen
    So I'm noticing an increased focus on C by Parallax which got me thinking, should I be learning C?

    I do not know why everyone is beating around the bush, instead of giving you sound advice. With C or C++, you will have a vast array of resources to pull from and it may even be an overwhelming amount resources. It is always better to have more than not enough. Additonally, by gaining C or C++ programming skills, you can apply this knowledge to many different aspects of programming, from personal computers to a wide variety of microcontrollers.

    Not that I have anything against SPIN, because I like the language a lot, but the resources and documentation are limited to basically parallax.com, and odds are that you will never use the SPIN language on anything besides a Propeller microcontroller.

    Of course, you will have to decide for yourself, what is important to you, but from my viewpoint, by learning C or C++ you will most certainly be upgrading your skillset, as well as having more resources at your disposal.

    Bruce
  • David BetzDavid Betz Posts: 14,516
    edited 2015-03-12 11:07
    Here is the dilemma, with C or C++ you have access to lots of code that has been written to run on other platforms. Some of it may run on the Propeller. It really depends on the resources it requires. The same would apply to attempting to run arbitrary C code on an Arduino. Both platforms have limited memory in particular so lots of C/C++ code on the net won't work because it's too big. However, much code will work on the Propeller. However, there is also the issue of drivers for specific hardware. The Arduino (actually the ATmega328p processor it is based on) has lots of built-in hardware interfaces like UART, I2C, SPI, etc. These don't exist on the Propeller. Instead, you have a very flexible architecture that allows you to use "soft peripherals" which are really software running either in the same COG or in its own COG. The OBEX is full of these drivers and mostly they are written in Spin or PASM. You can, with a little work, port the PASM ones to C fairly easily but very few have already been ported and there is no easily accessed collection of these ported drivers that you can use in your program. Parallax is working to fix this and there is lots of code in the Learn conference but not nearly as much as you'll find in OBEX. So I guess you should first look at what hardware you need to interface to and determine if

    1) There is already a C/C++ driver for it
    2) There is an OBEX object that is easy to port and you're willing to do the port yourself
    3) If both of the above fail, post your needs here and someone will probably help you
  • idbruceidbruce Posts: 6,197
    edited 2015-03-12 11:31
    Adding to David's list....

    4) There is a C/C++ driver that is incompatible with the Propeller, but can easily be ported, and you are willing to do the port yourself.
  • DynamoBenDynamoBen Posts: 366
    edited 2015-03-12 11:44
    For me I know enough C to be dangerous. ;) I prefer Spin with the Prop partly because its the "native" language and partly because its similar to Python which I've been using more frequently as of late.

    My programming "roots" were in BASIC many years ago, which led me to the BASIC Stamp, and then PICBasic. When the Prop was introduced I taught myself Spin which lead to Python. So as others have suggested, and I agree with, while the language may change the concepts remain the same.

    Given that Spin is here to stay I think I'll stick with it, but might dabble in C as time permits. Thanks for the input!
  • Mark MaraMark Mara Posts: 64
    edited 2015-03-12 11:55
    C does give you more options. I recently build a project using a propeller C3 and propGCC. When I decided to add a friendlier user interface I ran out of capacity on the propeller, even using xmm. Instead of using a a simpler user interface I decided to split the application between the prop board and a BeagleBone. I was able to move the user interface code to the bone with very little effort. The builds share a common directory for header files, typedefs and some functions. I don't think that I could keep the code bases synced if I was using Spin on the prop and C on the bone. I worked well for me.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-03-12 11:58
    DynamoBen wrote: »
    Should I be learning C

    The answer is always yes!
    ~A devoted fan of C++ on microcontrollers

    And on a more serious note...

    I'll give some relevant background about me:
    • I have a 4-year degree in computer engineering with a focus on embedded systems
    • I'm 1 year out of college
    • By day, I program in Java for the railroad

    I love C++ on the propeller because...
    • Easy to write a Hardware Abstraction Layer, like Arduino, PropWare, TI's TivaWare and many others. Keep in mind though, there's no need in Spin since there's only one piece of hardware using such a language
    • 99% of the concepts I've learned while making PropWare in C++ will help me in other aspects of my programming career. Though many lessons learned while programming Spin can be used elsewhere, no where near as much. It is a much simpler language, which makes learning easier, but also means you're not going to learn as much. Inheritance. Polymorphism. Dynamic memory allocation (this, more than most, should be avoided though). Make. CMake. There are lots of others too. Of course, none of what I just listed is required - certainly the Learn system never uses any of them - but they're available and can be used, which is more than could be said about Spin. (okay... you could use Make... but why?)
    • Inline assembly!!! No more starting up a new cog just to compute a simple floating point multiplication!
    • For the same reason that I can pull code from an Arduino and use it on the Propeller, an Arduino user can pull code from PropWare
    • I already know it and love the syntax
    • Many other reasons already listed by others above me

    So... choose for yourself. But be sure to choose C++ and PropWare.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-03-12 11:59
    Mark Mara wrote: »
    The builds share a common directory for header files, typedefs and some functions. I don't think that I could keep the code bases synced if I was using Spin

    I think this is the coolest thing I've heard someone do with C/C++ on the prop! Good job!
  • David BetzDavid Betz Posts: 14,516
    edited 2015-03-12 12:07
    Mark Mara wrote: »
    C does give you more options. I recently build a project using a propeller C3 and propGCC. When I decided to add a friendlier user interface I ran out of capacity on the propeller, even using xmm. Instead of using a a simpler user interface I decided to split the application between the prop board and a BeagleBone. I was able to move the user interface code to the bone with very little effort. The builds share a common directory for header files, typedefs and some functions. I don't think that I could keep the code bases synced if I was using Spin on the prop and C on the bone. I worked well for me.
    When you say that you ran out of memory in XMM mode do you mean you exceeded the 1MB of flash that is available on the C3 or that your data didn't fit in hub memory?
  • Heater.Heater. Posts: 21,230
    edited 2015-03-12 12:47
    DynamoBen,

    Yes of course you should learn C. But more on that later.

    Spin/PASM on the Propeller is a wonderful thing but in no way is Spin similar to Python. Spin does not have tuples or dictionaries or lists. Spin does not have first class functions, or lambdas. Spin cannot do this:
    $ python
    Python 2.7.8 (default, Oct 18 2014, 12:50:18) 
    [GCC 4.9.1] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 128361206406234062304163046012364061423 * 983249832094609812641209621364
    126211134646391195201739288712425980176791516597295352363563069040972L
    >>>
    
    I could continue. Apart from the white space indentation Spin and Python have almost nothing in common.

    You have BASIC, Spin and perhaps Python under your belt. That is good.

    Certainly you should learn C as a prime example of "imperative programming". It's very commonly used and very useful.

    You should look at one, and only one of: C++, Java, C# and others as a view of object oriented programming.

    Then then have a look at Haskell for an idea about the "functional programming" approach.

    Have a look at Scheme for an idea of how simple and powerful a language syntax can be.

    Look at Forth, stack based systems are a concept to behold.

    What I am saying here is that there are many different ways to look at programming and it's interesting to explore them.

    As a practical matter, if you are using a Propeller use Spin and PASM. If you are using an Arduino use C++. If you are using a Raspberry Pi or whatever you have a lot more choices. If you want to make use of the huge array of C/C++ code out there change to a chip that can run it nicely.

    Either way the more you learn the more you will know what to use when.
  • Mark MaraMark Mara Posts: 64
    edited 2015-03-12 13:14
    David Betz wrote: »
    When you say that you ran out of memory in XMM mode do you mean you exceeded the 1MB of flash that is available on the C3 or that your data didn't fit in hub memory?

    I said capacity not memory because I never completely understood the cause of my problems. My the user interface code uses several linked lists and a large state machine. I was experiencing a lot for strange problems as I increased the size of the state machine and heavily exercised the linked lists. Increasing the stack size was not the answer. I asked for help on the forum and it was suggested that I was banging up against some limits in garbage collection. All my problems could have easily been of my own makings, however, the code does run fine on the bone.

    I am not complaining, I really like the prop and propGCC. I was attempting to do something on it that it was not designed to do. Plus, I wanted to see if I could distribute the application across the two platforms.
  • David BetzDavid Betz Posts: 14,516
    edited 2015-03-12 13:24
    Mark Mara wrote: »
    I said capacity not memory because I never completely understood the cause of my problems. My the user interface code uses several linked lists and a large state machine. I was experiencing a lot for strange problems as I increased the size of the state machine and heavily exercised the linked lists. Increasing the stack size was not the answer. I asked for help on the forum and it was suggested that I was banging up against some limits in garbage collection. All my problems could have easily been of my own makings, however, the code does run fine on the bone.

    I am not complaining, I really like the prop and propGCC. I was attempting to do something on it that it was not designed to do. Plus, I wanted to see if I could distribute the application across the two platforms.
    Sorry, I guess I missed your call for help. I assume by "garbage collection" they really meant heap fragmentation. In the XMMC memory model all code is in external memory but all data including the stack and the heap along with the external memory cache have to fit in hub memory. The cache, by default, is 8k so that immediately reduces the amount of hub memory that you have for your data, heap, and stack to 24k. Maybe your application just didn't fit in that amount of memory.
  • DynamoBenDynamoBen Posts: 366
    edited 2015-03-12 13:47
    While we can debate the merits of C over Spin what I'm wondering is if future products like the Prop II might be based on C over Spin

    Let's not forget that I wasn't so much interested in a debate about the merits of C, I'm well aware of the merits was just wondering about the future direction of Prop when it came to languages.
  • Heater.Heater. Posts: 21,230
    edited 2015-03-12 14:11
    DynamoBen,

    Your opening question gives no hint that you are "well aware of the merits". After all, if you have to ask "Should I be learning C" that implies you do not know the merits or otherwise of C. So forgive any misguided replies.

    Let's get to the next part "...if future products like the Prop II might be based on C over Spin."

    I do not believe so.

    The Propeller and the Propeller 2 are the visions of one man, Chip. That is not just the chip architecture, it's the instruction set, it's the Spin language, the Spin compiler, the byte code interpreter, it's the Propeller Tool.

    Spin/PASM is not going away with the P2.

    If the Prop II was emphasising the running of C code efficiently it would have a very different architecture.
  • DynamoBenDynamoBen Posts: 366
    edited 2015-03-12 14:14
    Heater. wrote: »
    Your opening question gives no hint that you are "well aware of the merits". So forgive any misguided replies.

    Sorry, I guess I could have been clearer. I know what it's like to ask the "which language is better" question so I try to avoid that, I was just wondering if C was the future of the Prop which seems to not be the case. Thanks!
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-03-12 14:14
    1) There is already a C/C++ driver for it
    2) There is an OBEX object that is easy to port and you're willing to do the port yourself
    3) If both of the above fail, post your needs here and someone will probably help you

    May I suggest...

    0) Put on your big boy/girl pants and write the object/library yourself.

    Only if that fails -- after a serious attempt -- should the next steps be considered.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-03-12 14:20
    I was just wondering if C was the future of the Prop which seems to not be the case. Thanks!

    Wait... what? There is a team of internal and external resources that are making sure anyone who wants to use C with the Propeller has good tools to do that. The great news is that it's a choice, not a mandate. I don't like C, and unless forced to use it I don't. All of my professional development is in Spin and PASM. It works for me.

    Now take a bloke like Peter Jackaki. He loves Forth so much that he created a kick-@ss Forth environment for the Propeller (he's not the first or only, his project, Tachyon, seems to have the most coverage). Bean created PropBASIC.

    As David pointed out the Propeller architecture is very flexible; this allows -- maybe even encourages -- the development of a variety of tools for it.

    If you want C, you've got it and will aways have it.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-03-12 14:21
    JonnyMac wrote: »
    May I suggest...

    0) Put on your big boy/girl pants and write the object/library yourself.

    Only if that fails -- after a serious attempt -- should the next steps be considered.

    I take strong issue with that. Some people are here to learn programming, and thats AWESOME! Others just want to turn a lamp on automatically in their house. They couldn't care less how it's done, but a Propeller seems like a good idea. I think that's equally awesome, and I don't think they should have to even attempt to write their own drivers if someone else already did it.
  • Heater.Heater. Posts: 21,230
    edited 2015-03-12 14:28
    Well,

    a big thing about the Prop is that there is a huge pile of working objects in OBEX and elsewhere that make what you want to do easy.

    Not only that, but unlike single core devices, you can mix and match many such objects in your project without them tripping over each other timing wise and failing to do what you expect.

    I have to say I have no idea if such a variety of "plug-n-play" libraries exist for C on the Propeller yet.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2015-03-13 10:10
    DynamoBen wrote: »
    Sorry, I guess I could have been clearer. I know what it's like to ask the "which language is better" question so I try to avoid that, I was just wondering if C was the future of the Prop which seems to not be the case. Thanks!

    The real reply is that any microcontroller that provides C or C++, also has an Assembler available somewhere in its toolkit.

    In this case, Parallax provided SPIN as an enhanced IDE inclusive of an Assembler, and has made a genuine commitment to C in order to be a part of mainstream coding.

    So at this point, I suspect that Parallax will always have both The SPIN (with PASM) and C. These are generally accepted as a minimum set of programing tools for educational and industral uses.

    More debatable are other programs --- Basic, Forth, Python (Heater is passionate about Python), etc. These are the one's that might fade in and out from time to time-- much depends on an independent contributor's abilities and resources.
  • RaymanRayman Posts: 14,652
    edited 2015-03-13 13:33
    Spin can be used on about zero other devices.

    C or C++ can be used on just about anything out there.

    If you're dedicated to Propeller, like me, then you only would probably need C if you want to try to get someone else to use your project.
  • WossnameWossname Posts: 174
    edited 2015-03-16 08:12
    I've been a professional programmer for some time now and have had occasion to learn many languages on many platforms. I have to say that C is the most universally useful of the lot. I've written C code for ATTiny25s and for large enterprise-level Xeon clusters, games and databases.

    I'd say it's always a good idea to learn C, all technical reasons aside, it is in my opinion one of the most highly transferable skills an engineer can acquire. I cannot think of a single industry that does not make good use of the C language in one way or another and "time served" in C programming is a very significant benefit for prospective employers.

    Get a good knowledge of C and you'll find that other technical skills become a lot easier to accumulate. You'll be set for life if you get good enough at C :)
  • prof_brainoprof_braino Posts: 4,313
    edited 2015-03-17 07:24
    If you are a computer science major learning programming, C is often what they use. The univeristy will/should teach you good/best practices.

    If you are NOT a CS major and are learning C, their is no one to teach you good practices, and you may develop them yourself if you are very brilliant (as did many of this forums members and many programming professionals). On the other hand, you may develop -attrocious- habits like many self taught hacker and many programming "professions" did and still do.

    To a programming professional the selection of langauge and hardware are arbitrary, and are dictated by the current projects need. If one only has knowledge and expertise with a single tool, one is less flexible and at a disadvantage for large and/or complex projects.

    So the answer is "depends on what you are planning to do", which determines what you need to understand.
  • GenetixGenetix Posts: 1,754
    edited 2015-03-17 10:53
    DynamoBen,

    Since you've already learned several languages then why not give C a whirl. C is used all over the place so you will encounter it sooner or later.
    Also, many new devices and accessories are designed for the Arduino which uses C, and most chip companies will have sample C code for using their products.

    Propeller C has only been around for 1-1/2 years while Spin and PASM started when the Propeller first came out.
    Andy Lindsay wrote the Propeller C Tutorial on the Learn website and he is very good at breaking down things into manageable bites.

    I learned C years ago but only used it once for a class. Andy even makes pointers look easy (pointers "point" to the memory location or value of a variable).
  • edited 2015-03-17 20:11
    I was attracted to the propeller because it could be programmed in a language other than C. I liked Spin right from the beginning so that got me hooked on the prop. The integration of Spin and PASM is so well done / documented that even I can understand it.

    Now we have the best of all worlds; C for those who like C, Spin for those who like Spin, etc, etc.

    Imagine going to Italy and telling everyone you met that they really should speak english because it's better. They'd look at you like you had two heads!

    Sandy
  • koehlerkoehler Posts: 598
    edited 2015-03-18 00:42
    DynamoBen,

    I'd also say give plain old C a shot.
    At its core, its really not that difficult aside from some ; and { rules.
    I think you can even forget Pointers* and such initially and a quick google turned up this:
    http://www.embedded.com/design/prototyping-and-development/4006703/Saving-space-with-Pointer-less-C

    FWIW, you can get the K&R C bible from ebay or Amazon used books for $12 or so, many students just get rid of them after their first/only C class.
    Or, if you want something a little less dry, with a more superficial entry, try one of Dan Gookin's C for Dummies. Can also be found cheaply.
    I found CfD pretty nerdishly funny, quite a bit longer than it needed to be (but maybe thats better for beginners), and definately far less depth by an order of magnitude than K&R.
    But don't take my word for it, take a look for yourself: http://www.control.aau.dk/~jdn/edu/doc/arduino/litt/CForDummies2.pdf
Sign In or Register to comment.