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.
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?
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
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.
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.
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?
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.
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.
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 "="?
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.
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.
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).
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?
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.
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 ?
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?
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.
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.
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.
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.
Comments
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
Consider this simple C program which doesn't even use pointers: 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:
Just tested it on my DOS Box.
I might be a bit biased but I think mine is the prettiest ;-D
Windows is largely written in C also, if that fans anyone's flames.
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
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.
Well it sure had *me* fooled!
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"?
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.
I think Mickster is talking about MS QuickBasic:
http://en.wikipedia.org/wiki/QuickBASIC
Excellent question David!
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 "="?
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
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.
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).
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?
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
Because a test for equality is not an assignment. Pascal and others us "=" for equality and ":=" for assignment.
Also it means you can write: 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.
#include <stdio.h>
void main() { while (1) { printf("This is dumb.\n"); } }
--OR--
10 print "This is dumb"
20 goto 10
Which is better????
Happy days!!!!
DO
Print "This is dumb"
LOOP
WHILE
Print "This is dumb"
WEND
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
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.
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.
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
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.
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.
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.