Shop OBEX P1 Docs P2 Docs Learn Events
Do I want to C? — Parallax Forums

Do I want to C?

ErlendErlend Posts: 612
edited 2014-01-16 19:54 in Propeller 1
It was love at first glance when I met Spin a few years ago. By now I have learnt to know her fairly well, but for sure I do not know all her secrets yet. We go along well. There are many other - more or less strange - inhabitants in Propeller town, running back and Forth, doing things real quick, and that is fine, it makes life interesting, but I am not likely to leave Spin for any of them. Unless-... Lately the one they call C have gained both popularity and power, and I fear that one day C will chase Spin out of town.
Am I only being overly nervous? I remember how in earlier days how the C Clan gained almost world dominance. Will it happen in Propeller? Must I again read K&R?

Erlend
«13

Comments

  • Ken GraceyKen Gracey Posts: 7,392
    edited 2013-12-19 03:52
    Erlend wrote: »
    It was love at first glance when I met Spin a few years ago. By now I have learnt to know her fairly well, but for sure I do not know all her secrets yet. We go along well. There are many other - more or less strange - inhabitants in Propeller town, running back and Forth, doing things real quick, and that is fine, it makes life interesting, but I am not likely to leave Spin for any of them. Unless-... Lately the one they call C have gained both popularity and power, and I fear that one day C will chase Spin out of town.
    Am I only being overly nervous? I remember how in earlier days how the C Clan gained almost world dominance. Will it happen in Propeller? Must I again read K&R?

    Erlend

    Stay with Spin in your case. C follows Spin at Parallax in many ways. Almost all of our commercial customers are using Spin/ASM.

    You'll get more from the Propeller with Spin and ASM, first. C proved necessary for Parallax business in Education, which pays the way for so many other efforts in our company. I don't know why you'd need to fear that C would kick Spin out of town. Do what you like and do it well. Chip's heart lies with Spin and ASM, so that'll ensure that our first demos, programming tools and examples will use Spin 2. However, please count on the C compiler team working concurrently to deliver the same.

    Ken Gracey
  • RaymanRayman Posts: 14,662
    edited 2013-12-19 11:44
    Spin or C is made a tough choice now... It's great to have a choice.
    I agree with Ken though, that if you've already learned Spin, it's perfectly fine to stay with Spin.
    C is more standard and has more options, but it's also a hair more complicated.
    The Spin language was specifically designed for the Propeller.
    Also, the ROM contains the Spin interpreter. So, C programs will generally be larger than Spin programs.

    But, if you need to run super big programs, have direct code compatibility with other micro controllers, or need faster speed. It's worth trying out C.
    C will probably be the language of choice for Prop2 also.

    BTW: If you do want to try C or C++, the Spin2Cpp tool is a really amazing way to convert your existing Spin code to C or C++
  • jmgjmg Posts: 15,173
    edited 2013-12-19 13:41
    Rayman wrote: »
    BTW: If you do want to try C or C++, the Spin2Cpp tool is a really amazing way to convert your existing Spin code to C or C++

    That's a great idea, as you can learn much faster if you already KNOW what the code does.

    Another option for the toolbox to consider is Spin for main code, and if PASM is too big a jump, you can do Spin2Cpp -> then C into COG, for small blocks, that you need more PASM-like speed on.
    Erlend wrote: »
    Unless-... Lately the one they call C have gained both popularity and power, and I fear that one day C will chase Spin out of town.

    Spin is in ROM, so is rather literally cast in stone.
  • FlippoFlippo Posts: 1
    edited 2013-12-19 13:45
    New to this: Are there any resources for things such as quadrature encoders for C? I have looked at abdrive but it only handles single channel encoders. I have looking in it and can't really get a feel for it. I have gotten spin to do this (from other's modules) so I can always go back to that if I have to, I was just hoping to use C instead. My question is are there resources for objects and things like there are for spin?
    thanks
  • RaymanRayman Posts: 14,662
    edited 2013-12-20 00:27
    you can use Spin2Cpp to convert most any Spin driver to C or C++
  • ErlendErlend Posts: 612
    edited 2013-12-20 00:38
    I did some coding in C way back in time, enough that I am not really curious to learn Propeller C.
    Sounds like I can safely stay faithful to Spin, but I like the idea to put some C into a COG for when I need speed, but don't want to assembly. I could code the object in Spin, then Spin2Cpp it. It wouldn't be much of a craftmanship, but would save me a lot of time.

    Erlend
  • MicksterMickster Posts: 2,694
    edited 2013-12-20 02:20
    You can always count on me to bring up PropBasic at every opportunity. It hasn't had much of a mention lately but it's a high level language with PASM speed. I also use it for high speed quadrature encoder handling.
  • ErlendErlend Posts: 612
    edited 2013-12-20 03:53
    @Mickster
    My first language was BBC Basic (for the Acorn micro) where GOTOs were banished and Procedures encouraged. So, I am not a BASIC-hating fundamentalist at all. Do you mind sharing the quadenc code you mention with me? - I'm curious.

    Erlend
  • T ChapT Chap Posts: 4,223
    edited 2013-12-20 04:34
    Flippo. Have you tried the Rotary Encoder object in OBX? It allows multiple encoders. It is coded in PASM and is easy to control from your SPIN main program. The Rotary obj is a multi input quadrature encoder obj. Maybe you can convert it to C if that is a requirement.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-12-20 05:03
    Those that already use C want C.
    Those that use spin should use spin until it doesn't do whats required.
    Those that have no prior preference and want to work quickly and have fun should talk to me.
    I did some coding in C way back in time, enough that I am not really curious to learn Propeller C.

    There are significant number of people with this opinion, but be aware that any bad experiences may have been from the way the project was handled, rather than the tool itself.
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2013-12-20 09:52
    There are significant number of people with this opinion, but be aware that any bad experiences may have been from the way the project was handled, rather than the tool itself.

    Not reading too far into the statement, but I'm curious what you mean, Doug. The compiler and tools were developed very much in the open, in the community, fairly loosely managed by Parallax. If it's worth clarifying please do so since we're always trying to do the best we can given the allotted resources available to the project.

    Thanks,

    Ken Gracey
  • jmgjmg Posts: 15,173
    edited 2013-12-20 11:03
    Ken Gracey wrote: »
    Not reading too far into the statement, but I'm curious what you mean, Doug. The compiler and tools were developed very much in the open, in the community, fairly loosely managed by Parallax. If it's worth clarifying please do so since we're always trying to do the best we can given the allotted resources available to the project.

    ? I read #11 as talking about the 'back in time' experience, not any Prop C experience.

    Prop C seems to be percolating nicely.
    GCC also gives users access to a Macro Assembler, which matters to some.
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2013-12-20 12:04
    Yeah, I read #11 the same as jmg, Ken. I don't think anyone could complain about the PropGCC team/effort/work. It's pretty fantastic.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-12-20 12:24
    Ken Gracey wrote: »
    Not reading too far into the statement, but I'm curious what you mean, Doug. The compiler and tools were developed very much in the open, in the community, fairly loosely managed by Parallax. If it's worth clarifying please do so since we're always trying to do the best we can given the allotted resources available to the project.

    Sorry, I was not clear. I was not refering to the project developing Prop C.

    I was refering to various projects at various organizations, where C selected as the programming tool, due to the commodity nature of C programmers. More often than not, "fast paced, dynamic environoment" meant little chance of success due to poor requirements, insufficent resources for testing, unrealistic goals and deadlines, moving targets; poor management in general. Many bad experiences using C on development projects. Because of this, I know to avoid non-regulated industries.

    This is not an issue with any particular tool, its an issue of management. Software deveopment using C and non regulated industry are indicators of these risks.

    Parallax is an example of the "good way" to do it. But Parallax is still pretty rare.
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2013-12-20 12:26
    Gotcha, Doug, Roy and jmg. I figured as such.

    Seems everybody seems to have a horror story about large-scale C programming projects, accentuated by the various points Doug brought up (insufficient testing resources, unrealistic goals, poorly defined needs, etc.). Having worked in small environments for my whole existence I lack the experience of large-scale challenges. And I think I might be thankful for not having this kind of experience.
  • ratronicratronic Posts: 1,451
    edited 2013-12-20 12:49
    Ken Gracey wrote: »
    Chip's heart lies with Spin and ASM, so that'll ensure that our first demos, programming tools and examples will use Spin 2. However, please count on the C compiler team working concurrently to deliver the same.
    Ken Gracey
    Thank's Chip for making Spin/PASM so easy to use and keeping up development for Spin 2!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-20 13:24
    T Chap wrote: »
    Flippo. Have you tried the Rotary Encoder object in OBX? It allows multiple encoders. It is coded in PASM and is easy to control from your SPIN main program. The Rotary obj is a multi input quadrature encoder obj. Maybe you can convert it to C if that is a requirement.

    I don't want to sidetrack the discussion too much but I wasn't able to find a working quadrature encoder object in the OBEX.

    Wildatheart recently found a bug in Kye's QE object.

    The QE object in the Propeller Tool Library seems to work correctly. I didn't see a demo for the object so I posted a couple in post #7 of my quadrature encoder thread. While the my main effort is to write an object to both read encoders and provide PWM to motors, is did post some encoder only code to post #2 of the thread. Kye also posted some additional encoder/PWM code to the thread.

    I'm still on the fence about C. I like Spin but I have several large projects which require me to load only a portion of the program in the the Propeller at a time. Most of this segmented program is stored on a SD card. I think C would probably make these type of programs easier to manage.
  • T ChapT Chap Posts: 4,223
    edited 2013-12-20 13:38
    Maybe this was always included in the Propeller Tool examples? If not, then it has been removed from obex. Works great for me.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-20 13:42
    T Chap wrote: »
    Maybe this was always included in the Propeller Tool examples? If not, then it has been removed from obex. Works great for me.

    That's the one I tried to find in the OBEX. I knew I had used it before. It took me a while to realize it was in the Propeller Tool Library. I'm pretty sure it has been there a long time.
  • ErlendErlend Posts: 612
    edited 2013-12-21 01:40
    My experience with C isn't bad, it's just not exciting, although the ++ helped because I liked the object-based thinking, particularily for general information processing purposes. For embedded control the needs are different. For this, the Propellor cogs are invaluable, since they allow effortless handling of I/O, and no worry about interrupts. And hand-in-hand with the cogs goes Spin as a to-the-point language with minimal clutter. That combination is powerful. (If P2&Spin2 will have more cogs & better string handling, that would make it even more perfect).

    Erlend
  • MicksterMickster Posts: 2,694
    edited 2013-12-21 01:48
    Erlend wrote: »
    @Mickster
    My first language was BBC Basic (for the Acorn micro) where GOTOs were banished and Procedures encouraged. So, I am not a BASIC-hating fundamentalist at all. Do you mind sharing the quadenc code you mention with me? - I'm curious.

    Erlend


    Here's a link to an earlier thread. It's a different approach and only good for one encoder (as-is). It doesn't include writing the updated count to the hub but that would happen just prior to GOTOing (JMPing) to a different label after a change of state of either ChA or ChB.

    The generated PASM code uses very few instructions and I bet it could be further optimized.
  • ErlendErlend Posts: 612
    edited 2013-12-21 03:40
    Thanks. But I do not like to walk in GOTO-land, so this BASIC is obviously not for me, I can see. Unless I take the view that it is a kind of high level PASM-.

    Erlend
  • Heater.Heater. Posts: 21,230
    edited 2013-12-21 03:48
    Whatever happened in the BASIC world.


    BASIC looks like this:

    0 INPUT "What is your name: ", U$
    20 PRINT "Hello "; U$
    30 INPUT "How many stars do you want: ", N
    40 S$ = ""
    50 FOR I = 1 TO N
    60 S$ = S$ + "*"
    70 NEXT I
    80 PRINT S$
    90 INPUT "Do you want more stars? ", A$
    100 IF LEN(A$) = 0 THEN GOTO 90
    110 A$ = LEFT$(A$, 1)
    120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30
    130 PRINT "Goodbye "; U$
    140 END
    


    Other people peddle languages that look like this:

    Public Class StarsProgram
        Public Shared Sub Main()
            Dim UserName, Answer, stars As String, NumStars As Integer
            Console.Write("What is your name: ")
            UserName = Console.ReadLine()
            Console.WriteLine("Hello {0}", UserName)
            Do
                Console.Write("How many stars do you want: ")
                NumStars = CInt(Console.ReadLine())
                stars = New String("*", NumStars)
                Console.WriteLine(stars)
                Do
                    Console.Write("Do you want more stars? ")
                    Answer = Console.ReadLine()
                Loop Until Answer <> ""
                Answer = Answer.Substring(0, 1)
            Loop While Answer.ToUpper() = "Y"
            Console.WriteLine("Goodbye {0}", UserName)
        End Sub
    End Class
    


    How do they have the nerve to use the same name for these things?
  • Martin_HMartin_H Posts: 4,051
    edited 2013-12-21 04:14
    I agree Heater, Basic is supposed to be a stripped down introduction to programming. I think PBasic removing line numbers and adding if then else is still with the spirit of the language. But the snippet of code you posted is outside the realm of a beginner's language.
  • Heater.Heater. Posts: 21,230
    edited 2013-12-21 07:03
    Often you here debates about how awful and brain damaging BASIC is. Usually based on the arguments that BASIC has none of the nice structural features of "structured programming" that became popular with languages like ALGOL, C, Pascal and so on. Instead of proper syntax for the fundamental ideas of sequence, selection and iteration, instead of proper functions and procedures we just get line numbers and GO TO's.

    BASICS supporters will counter such arguments by pointing out that BASIC does not look like that any more. They point to VB or whatever and say "See it's just like a modern language".

    Sometimes I think it's just awful both ways round. The original BASIC was too rude and crude. The modern BASICs because, well because they have no reason to exist, we have many other standardized and cross-platform languages.

    On the other hand if you want a language that is small enough to work on your device and is a soft start for beginners then BASIC is fine.
  • MicksterMickster Posts: 2,694
    edited 2013-12-21 07:06
    Erlend wrote: »
    Thanks. But I do not like to walk in GOTO-land, so this BASIC is obviously not for me, I can see. Unless I take the view that it is a kind of high level PASM-.

    Erlend

    It's been a while since I checked the PropBasic documentation but I do believe that you can use an inline ASM directive which would allow one to substitute JMP for GOTO. Would that make things more palatable? After all, there's no getting away from JMP in ASM.

    JMPRET in PASM is even more "interesting" :-)
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-12-21 07:52
    GOTO and JMP are just instructions. JMP tends to be used by certain established rules in the automated compiler, and its fine. GOTO tends to be used manually by beginners in ways that cause problems.

    A screw driver can be used to turn screws or stir paint. If you don't have the habit of putting down the screw driver and picking up the paint stirrer, you may end up with a mess. GOTO ends up in a mess often enough to remove it from the tool box.
  • ErlendErlend Posts: 612
    edited 2013-12-21 08:33
    I don't mind if there are GOTO's in a language as long as I don't have to use them. Maybe there are brains out there that keep tally of all gotos in a code, but with me I loose track after a few of those jumps. Probably that is why I never did get a grip of assembly coding.

    Erlend
  • Martin_HMartin_H Posts: 4,051
    edited 2013-12-21 08:57
    Mickster wrote: »
    JMPRET in PASM is even more "interesting" :-)

    JMPRET reminds me a bit of the IBM System 360's BALR instruction. Except that BALR used a register to hold the return address and the Propeller uses storage in the instruction sequence. But other than that it's a way of doing a JSR when your processor doesn't have a stack.
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-12-21 09:27
    The Sperry 1100 series (a stackless architecture) had a SLJ (store location and jump) and LMJ (load modifer and jump) instruction which stored P+1 into either a memory location in the first case or a register in the second. These effectively allowed subroutine calls and avoided goto situations in assembler. I think most processors have some way to implement this. Coding conventions then make it easy to implement callable procedures.
Sign In or Register to comment.