Shop OBEX P1 Docs P2 Docs Learn Events
Why C is better than BASIC, can anyone provide live example? - Page 4 — Parallax Forums

Why C is better than BASIC, can anyone provide live example?

1246712

Comments

  • RsadeikaRsadeika Posts: 3,837
    edited 2015-04-01 05:21
    Why C is better than BASIC, can anyone provide live example?
    With C you can develop an OS, like UNIX, while I doubt that using an original interpreted BASIC, you could even come close. The original intent of C was to create operating systems, now it seems that C is being used for everything, not sure if that is a good outcome for the original intent of C. C is a very powerful tool with a steep learning curve, if it is to be used properly.

    On the other hand, the original intent for BASIC, was a tool to get people interested in a fairly quick way of programming on a mainframe. I remember, in the mid 70s, the college I was attending offered a BASIC, that did just that, and that was way before their was a Computer Science offerings.

    So, the moral of the story, use the right tool for the problem that you want to deal with.

    Ray
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-01 05:56
    I've lost track of what we're talking about here. Are we talking about the original Dartmouth Basic with line numbers and gosub or are we talking about modern versions of Basic?
  • MicksterMickster Posts: 2,693
    edited 2015-04-01 06:40
    [QUOTE=Tor;1323884
    Consider this simple C program which doesn't even use pointers:
    #include <stdio.h>
    
    typedef struct {
        char *name;
        int age;
        int height;
        int weight;
    } person;
    
    static void print_name (person theperson)
    {
        printf ("Name: %s\n", theperson.name);
    }
    
    static void print_age (person theperson)
    {
        printf ("Age: %d\n", theperson.age);
    }
    
    static void print_height (person theperson)
    {
        printf ("Height: %d\n", theperson.height);
    }
    
    static void print_weight (person theperson)
    {
        printf ("Weight: Won't tell\n");
    }
    
    int main (void)
    {
        person salesman;
    
        salesman.name = "Mr Seller";
        salesman.age  = 35;
        salesman.height = 180; /* No imperial measurements */
        salesman.weight = 110; /* Likewise */
    
        print_name (salesman);
        print_age (salesman);
        print_height (salesman);
        print_weight (salesman);
    
        return (0);
    }
    
    The above isn't even something C is particularly good at.. but it has:
    • Real function calls. Not 'GOSUB 40' or whatever.
    • Functions can take parameters.
    • There is a type system: You can define new types.
    • You can define a record and pass that one around as any other variable (not even using a pointer (address)).
    • No line numbers.. if you want to insert a line of code you don't have to re-number all the lines in case there aren't any free numbers in between where you insert code.
    I'm not including a version written in BASIC, because it's not possible to write it that way in BASIC!
    -Tor[/QUOTE]


    Is that so? This is QuickBASIC 4.5, circa 1987:
    TYPE person
        thename AS STRING * 32
        age AS INTEGER
        height AS INTEGER
        weight AS INTEGER
    END TYPE
    
    'Prototypes
    DECLARE SUB printname (theperson AS person)
    DECLARE SUB printage (theperson AS person)
    DECLARE SUB printheight (theperson AS person)
    DECLARE SUB printweight (theperson AS person)
    
    
    DIM salesman AS person
    
        salesman.thename = "Mr. Seller"
        salesman.age = 35
        salesman.height = 180
        salesman.weight = 110
    
        printname salesman
        printage salesman
        printheight salesman
        printweight salesman
    
    SUB printage (theperson AS person)
        PRINT "Age: "; theperson.age
    END SUB
    
    SUB printheight (theperson AS person)
        PRINT "Height: "; theperson.height
    END SUB
    
    SUB printname (theperson AS person)
        PRINT "Name: "; theperson.thename
    END SUB
    
    SUB printweight (theperson AS person)
        PRINT "Weight: Won't tell"
    END SUB
    
    
    

    Just tested it on my DOS Box.

    I might be a bit biased but I think mine is the prettiest ;-D
  • ercoerco Posts: 20,256
    edited 2015-04-01 07:12
    Rsadeika wrote: »
    With C you can develop an OS, like UNIX, while I doubt that using an original interpreted BASIC, you could even come close.

    Windows is largely written in C also, if that fans anyone's flames. :)
  • TorTor Posts: 2,010
    edited 2015-04-01 07:16
    Mickster:
    That is QuickBasic. That's the point. QuickBasic is not BASIC. As BASIC was specified, we have to compare to BASIC. If you want to compare with some other language, then specify that other language and let's compare. And indeed, as soon as you start comparing structured languages with a type system against each other it's only about taste. But BASIC is not structured, and that is why C (or any other structured language with records and types and all that - including QuickBasic) is better than BASIC - as soon as you want to do something more trivial than a linear list of operations. Your QuickBasic example shows that QuickBasic is so different from BASIC as e.g. Pascal is. It's a different language. And that's why you can't just say "BASIC" and by that incorporate any and every language with the letters "basic" somewhere in there, into some kind of meta-language (which doesn't exist) and point out what it can do.

    -Tor
  • Heater.Heater. Posts: 21,230
    edited 2015-04-01 07:45
    Loopy,
    I really wonder if performing an FFT offers anything meaningful for a generalized language. How many of us really need to calculate FFT? And if we do, how many of use desire to use a microcontroller to do so with limitations of speed and memory?
    Calculating FFT on a micro-controller is a very common thing. Even on the Propeller a least two projects have been done using my FFT, a power factor meter and a musical note detector, both done as student projects. There is even another FFT in assembler for the Propeller, sadly I forget who did that or find a link 2 it.

    Just because you cannot see any use for a thing does not make it useless.

    Admittedly I wrote that FFT just as an exercise to prove to myself I understood how it worked and how to do it. The Propeller version in PASM was just an idle Christmas break activity.

    Really, as the documentation says FFT_bench it's not about being an FFT, it's just a benchmark of normal loops and operations that a machine commonly uses. As a bonus it tests the operation and scalability to many COGs of the OpenMP threading available in C.

    That zbasic is another unknown variant of BASIC that may or may not be compatible with any other BASIC I might happen to have. It's also expensive.
  • MicksterMickster Posts: 2,693
    edited 2015-04-01 07:45
    Tor wrote: »
    Mickster:
    That is QuickBasic. That's the point. QuickBasic is not BASIC.
    -Tor

    Well it sure had *me* fooled!
    10 CLS
    20 INPUT "You telling me that I am not BASIC"; A$
    30 IF A$ = "Y" THEN GOTO 10
    40 CLS : PRINT "Good!"
    50 END
    

    Because it runs the above code with no problems at all.

    Where in the thread title am I supposed to interpret "Why are modern C compilers better than a clunky old BASIC interpreter"?
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-01 07:53
    Tor wrote: »
    Mickster:
    That is QuickBasic. That's the point. QuickBasic is not BASIC. As BASIC was specified, we have to compare to BASIC. If you want to compare with some other language, then specify that other language and let's compare. And indeed, as soon as you start comparing structured languages with a type system against each other it's only about taste. But BASIC is not structured, and that is why C (or any other structured language with records and types and all that - including QuickBasic) is better than BASIC - as soon as you want to do something more trivial than a linear list of operations. Your QuickBasic example shows that QuickBasic is so different from BASIC as e.g. Pascal is. It's a different language. And that's why you can't just say "BASIC" and by that incorporate any and every language with the letters "basic" somewhere in there, into some kind of meta-language (which doesn't exist) and point out what it can do.

    -Tor
    Can you please post a link to the version of BASIC you're talking about?
  • Heater.Heater. Posts: 21,230
    edited 2015-04-01 08:00
    Mickster,

    The fact that some modern BASIC can run the exact same code as some original BASIC is nice. The problem remains though. The moment you write some non-standard statements in there you have created a potentially incompatible program. Or does QuickBASIC warn you when you stray from the ANSI BASIC standard?

    It's this non-standardization of the thing called "BASIC" that makes it unacceptable in industry where one wants some hope that ones investment in creating code is usable across many different machines, architectures, and operating systems for years into the future.

    The opening post was all about performance. So far we have one benchmark result in comparing the same functionality in BASIC and C. C was far quicker. The BASIC used is not even released for others to use.

    Score: C:1, BASIC:nil

    Play on.

    :)
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-01 08:06
    The name "BASIC" applied to a language seems to mean nothing these days. I want to implement a new version of BASIC. How will I know if I've succeeded? What characteristics make my language a version of BASIC as opposed to some completely new language? Maybe I need a FOR / NEXT statement? Well then I guess pbasic passes that test. Does my language need MID$? If so, then pbasic is not really BASIC. Do I need GOSUB and GOTO? What distinguishes a BASIC from any other language. I think that these days a language is an implementation of BASIC if it has the string "basic" somewhere in its name. That's it.
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-01 08:07
    Actually, since we're talking about the Propeller here, why not make the question "Which is better, C or PropBASIC?"
  • PublisonPublison Posts: 12,366
    edited 2015-04-01 08:10
    David,

    I think Mickster is talking about MS QuickBasic:

    http://en.wikipedia.org/wiki/QuickBASIC
  • PublisonPublison Posts: 12,366
    edited 2015-04-01 08:11
    David Betz wrote: »
    Actually, since we're talking about the Propeller here, why not make the question "Which is better, C or PropBASIC?"

    Excellent question David!
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-01 08:12
    Publison wrote: »
    David,

    I think Mickster is talking about MS QuickBasic:

    http://en.wikipedia.org/wiki/QuickBASIC
    Okay, if that is the case then this discussion is meaningless since there is no implementation of QuickBASIC for the Propeller.
  • MicksterMickster Posts: 2,693
    edited 2015-04-01 08:34
    David Betz wrote: »
    Actually, since we're talking about the Propeller here, why not make the question "Which is better, C or PropBASIC?"

    Which has enjoyed the most support and encouragement?

    What I can say is that PropBASIC is the most readable which is kinda important to those of us who don`t program on a constant basis and therefore can`t remember where and when to type silly squiggly, meaningless symbols.

    BASIC's variable assignment: A = 3
    BASIC's variable compare: IF A = 3 Then...

    Why does one have to remember when to use "==" as opposed to "="?
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2015-04-01 08:58
    Mickster wrote: »
    What I can say is that PropBASIC is the most readable which is kinda important to those of us who don`t program on a constant basis and therefore can`t remember where and when to type silly squiggly, meaningless symbols.

    You'll be happy to know that we are working towards PropBASIC support in PropellerIDE. I've been too busy to talk much about this, but it's coming together with a small team of people (Bean, Brett, Jeff) due to requests from our customers.

    Ken Gracey
  • Ray0665Ray0665 Posts: 231
    edited 2015-04-01 09:15
    To get back to the original question,

    Better is in the eyes of the one asking the question.

    Since you asked the question you now need to define better,
    For what? making flower pots? swimming the english channel,
    a beginners first programming language.
    A very senior highly experiences programmer processing HTML5 POST strings
    realtime embedded software with strict time constraints?

    and I suspect once you do that you will have your answer and then you get to decide yourself.
  • MicksterMickster Posts: 2,693
    edited 2015-04-01 09:33
    Heater. wrote: »
    Mickster,

    Or does QuickBASIC warn you when you stray from the ANSI BASIC standard?

    What was actually of far more productive use to me was a compiler that prevented me accidentally straying out of array bounds. IIRC, non of the C compilers at that time even cared (I could be wrong on this).
    Heater. wrote: »
    It's this non-standardization of the thing called "BASIC" that makes it unacceptable in industry where one wants some hope that ones investment in creating code is usable across many different machines, architectures, and operating systems for years into the future.

    The opening post was all about performance. So far we have one benchmark result in comparing the same functionality in BASIC and C. C was far quicker. The BASIC used is not even released for others to use.

    Score: C:1, BASIC:nil

    Play on.

    :)

    I really couldn't care less about standardization and code that can be used for years. I build machine tool controllers and if my HMI still looked like a Lotus 123 spreadsheet, I would've been out of business a long time ago. My current HMI is Android based and migrating QuickBASIC and PowerBASIC code to B4A (Basic4Android) was an absolute breeze.

    I must have missed the BASIC source code for this benchmark test....where can I find it?
  • Heater.Heater. Posts: 21,230
    edited 2015-04-01 09:53
    Mickster,

    Ariba's FFT code in BASIC is attached to his post here: http://forums.parallax.com/showthread.php/129972-fft_bench-An-MCU-benchmark-using-a-simple-FFT-algorithm-in-Spin-C-and-...?p=982930&viewfull=1#post982930
    Why does one have to remember when to use "==" as opposed to "="?
    Because a test for equality is not an assignment. Pascal and others us "=" for equality and ":=" for assignment.

    Also it means you can write:
    if (status = doSomething() == ERROR)
    {
         log("Something failed", status);
    }
    
    Mind you, to be honest, I personally don't like to see that style used.

    I could turn it around and ask why in BASIC does "if" in front of an expression change the meaning of "="? That's confusing.
  • Ray0665Ray0665 Posts: 231
    edited 2015-04-01 10:21
    Examples

    #include <stdio.h>
    void main() { while (1) { printf("This is dumb.\n"); } }

    --OR--

    10 print "This is dumb"
    20 goto 10

    Which is better????
  • MicksterMickster Posts: 2,693
    edited 2015-04-01 10:22
    Ken Gracey wrote: »
    You'll be happy to know that we are working towards PropBASIC support in PropellerIDE. I've been too busy to talk much about this, but it's coming together with a small team of people (Bean, Brett, Jeff) due to requests from our customers.

    Ken Gracey

    Happy days!!!!
  • MicksterMickster Posts: 2,693
    edited 2015-04-01 10:25
    Ray0665 wrote: »
    Examples

    #include <stdio.h>
    void main() { while (1) { printf("This is dumb.\n"); } }

    --OR--

    10 print "This is dumb"
    20 goto 10

    Which is better????

    DO
    Print "This is dumb"
    LOOP

    WHILE
    Print "This is dumb"
    WEND
  • jmgjmg Posts: 15,173
    edited 2015-04-01 11:52
    Ken Gracey wrote: »
    You'll be happy to know that we are working towards PropBASIC support in PropellerIDE. I've been too busy to talk much about this, but it's coming together with a small team of people (Bean, Brett, Jeff) due to requests from our customers.
    Is this also getting a clean-pass, to make PropBASIC co-operate better with mainstream PC Basic ?

    Being able to test subroutines on a host, before 'sending them out into the real world' has many benefits, more so on a Prop, which is poor in hardware debug.support.

    Which mainstream PC Basic ? - I would favour FreeBASIC, but I see Microsoft have moved Visual Studio essentially free, and seem to be doing a push, and it is hard to ignore that level of resource.
    I also note Atmel has used Visual Studio shell, as their IDE-shell for the AVR Studio.

    One test could be to check the RaspPi road maps of each ?

    A couple of references :
    FB : http://virtualink.wikidot.com/fbtut:fbsconsts
    VB : https://msdn.microsoft.com/en-us/library/swfss70d%28v=vs.90%29.aspx
    https://msdn.microsoft.com/en-us/library/s477hyxw.aspx
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-01 12:48
    Mickster wrote: »
    DO
    Print "This is dumb"
    LOOP

    WHILE
    Print "This is dumb"
    WEND

    This is something that has always bothered me about BASIC. It isn't consistent. You have WHILE and WEND but not DO and DEND. I believe you also have ENDIF instead of IEND. Why not make them ENDWHILE, and ENDDO to match ENDIF?
  • MicksterMickster Posts: 2,693
    edited 2015-04-01 13:11
    David Betz wrote: »
    This is something that has always bothered me about BASIC. It isn't consistent. You have WHILE and WEND but not DO and DEND. I believe you also have ENDIF instead of IEND. Why not make them ENDWHILE, and ENDDO to match ENDIF?

    Really has never been a problem for me. The DO or the LOOP can have WHILE or UNTIL and you can escape using EXIT DO.
    a = 0
    
    do until a = 100
      incr a
    loop
    
    (Alternatively)
    
    a = 0
    
    do
      incr a
    loop until a = 100
    
    

    I like the fact that BASIC has so many built-in functions and commands. Never did get the brevity-is-beautiful premise of the C language.
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-04-01 13:12
    Yes, partnering up with Microsoft sound good! That Microsoft Robotics Studio / Parallax partnership did so well!!
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-01 13:20
    Mickster wrote: »
    Really has never been a problem for me. The DO or the LOOP can have WHILE or UNTIL and you can escape using EXIT DO.
    a = 0
    
    do until a = 100
      incr a
    loop
    
    (Alternatively)
    
    a = 0
    
    do
      incr a
    loop until a = 100
    
    

    I like the fact that BASIC has so many built-in functions and commands. Never did get the brevity-is-beautiful premise of the C language.
    I'm not complaining about the statements. I'm complaining that there is no consistency in the syntax. Looks like a patchwork of various people's ideas. It isn't a well designed language.
  • jmgjmg Posts: 15,173
    edited 2015-04-01 13:28
    David Betz wrote: »
    This is something that has always bothered me about BASIC. It isn't consistent. You have WHILE and WEND but not DO and DEND. I believe you also have ENDIF instead of IEND. Why not make them ENDWHILE, and ENDDO to match ENDIF?

    True, but part of that is for legacy reasons, mostly they have End If , End Select etc

    ENDDO (would be End Do in modern basics) is usually also coded with an Until condition, and 'End Do Until' is not so natural as .. Loop Until
    Do
        keycode = Asc(Inkey)
        Sleep 1
    Loop Until keycode = 27 
    

    Contrast that with C, where a whole string of } are the End closures for almost everything..
    You really DO need a smart Syntax highlighting Editor + style rules, to help you out of that morass.
  • rod1963rod1963 Posts: 752
    edited 2015-04-01 13:30
    You're copping out Tor.

    Mickster used a valid form of Basic and it can handle what you did in C and is much more readable than C.

    The fact is Basic evolved over time just like C which became C97, Objective C and C++.

    That's part and parcel of the entire computer industry, things evolve and change over time to suit the needs of coders and end users.
  • jmgjmg Posts: 15,173
    edited 2015-04-01 13:39
    Mickster wrote: »
    Never did get the brevity-is-beautiful premise of the C language.
    That made sense when Core memory was around, and punched cards for entry, as saving source-code-space made a difference way-back-when.
    Source-code-Size has not been an issue for some decades, but the legacy remains.
    These days, with GB size IDEs, there are enough additional helpers wrapped around C to assist programmers of all skill levels.
Sign In or Register to comment.