BASIC is a lot easier for a non-programmer to read. (Excluding that MS stuff!)
C is a much more powerful language but for what the average person will do BASIC gets the job done.
C is also a lot more abstract and it lacks many of the convenience and safety features that BASIC has such as error checking and garbage collection.
Careful where you stick that C pointer or you might crash your system.
Loopy, I found Spin to very similar with PBASIC though there are some differences. I learned PASCAL after having learned BASIC and it made learning C a lot easier.
I disagree that basic is automatically easier to read than C. For someone that has learned even very basic (sorry for the pun) syntax of both languages is it really easier to read:
10 print "howdy world
Than:
int main(){
puts ("howdy world");
}
?
Once you get past trivial programs all the need gotos needed to make basic works makes it nearly unreadable.
Because in mathematics "=" means "Exactly the same amount or value". It's a statement of equality. It is not an assignment. For example "a + b = c" does not assign c to a + b. How could it?
Better to use some other symbol for assignment to avoid confusion. Which many languages do. Of course C does it backwards, where "=" is the assignment and "==" is the test for equality.
Anyone who has ever done the slightest maths in school will be happy with this idea.
2. Why some lines end with ;, while others - not
Good question. Every language has it's weirdness. ALGOL is "free form" you don't have to put every statement on a new line. So you need some kind of separator. No worse than comas, semicolons, colons, and full stops in English.
3. "for p := 1 step 1 until n do" - what this line does, it is not possible to understand from human knowing of english
language, while basic is much closer to "real" language in such constructions.
How can you say so? How compare and contrast:
BASIC:
FOR p = 3 TO 9 STEP 3
ALGOL:
for p := 3 step 3 until 9 do
Almost identical. Both equally readable or otherwise as some kind of "real" English. Where do you think BASIC got the idea from?
I might suggest that given a high school understanding of "=" the BASIC version is unintelligible. One has to be told what it does in both BASIC and ALGOL.
I am unware of any English usage which would have that "do" hanging off the end, "until" seems clunky and arbitrary compared to the more direct "to," and putting the step first kind of works except that it is an adjective showing up where we really expect a verb. It might make more sense if you speak German where always at the end the verb you put.
I am unware of any English usage which would have that "do" hanging off the end, "until" seems clunky and arbitrary compared to the more direct "to," and putting the step first kind of works except that it is an adjective showing up where we really expect a verb. It might make more sense if you speak German where always at the end the verb you put.
Well, there is no verb at all in the Basic version.
And for the readability, here's COBOL code example
MOVE WS-REL-ADDR TO WS-RELATIVE-KEY.
READ IN-MASTER.
EVALUATE WS-FILE-STATUS
WHEN '00'
PERFORM 300-SUCCESSFUL-READ
WHEN '23'
PERFORM 400-RECORD-SLOT-IS-EMPTY
WHEN '92'
DISPLAY 'FILE NOT OPEN'
WHEN OTHER
DISPLAY 'UNEXPECTED FILE ERROR: ' WS-FILE-STATUS
END-EVALUATE.
And for the readability, here's COBOL code example
MOVE WS-REL-ADDR TO WS-RELATIVE-KEY.
READ IN-MASTER.
EVALUATE WS-FILE-STATUS
WHEN '00'
PERFORM 300-SUCCESSFUL-READ
WHEN '23'
PERFORM 400-RECORD-SLOT-IS-EMPTY
WHEN '92'
DISPLAY 'FILE NOT OPEN'
WHEN OTHER
DISPLAY 'UNEXPECTED FILE ERROR: ' WS-FILE-STATUS
END-EVALUATE.
Clean, human readable code.
Excellent. I admit that COBOL is better than C as is BASIC. Why don't you immediately start work on a COBOL compiler for the Propeller? There is already PropBasic if you want to use BASIC.
I am unware of any English usage which would have that "do" hanging off the end,
How do you do?
That "do" is not "hanging off the end", it's part of a larger structure. The for loop:
for p := 3 step 3 until 9 do
can be though of as saying:
For integer values of p starting from 3, in increments of 3, up until and including 9 this is what I want you to do:
something with p,
something else with p.
Honestly it's such a stylized version of English like symbols it does not make much difference.
To say in different way, why algol needs :=, when basic uses only =
I thought I explained that above already.
In maths "=" is an expression of equivalence, it is not an assignment. Both BASIC can C are wrong to use "=" to mean assignment. As any high school maths student might agree. Many other languages do the correct thing and use a different symbols for assignment, Pascal, Ada, Spin, Algol...
":" is used in English to introduce a list. I believe that is what it is doing there in ALGOL. When it's not forming part of an assignment operator.
Looks like gibberish to me. What does it mean "WS-FILE-STATUS"? Is that like, WS minus FILE minus STATUS?
COBOL looks nice until you try to write some interesting algorithms with it, say a binary tree search. That is a very short, simple and clear thing in most languages. I would love to see your example of it in COBOL.
There is a reason they say there are billions of lines of code in existence, if they had used a more reasonably concise language it would probably only be a hundred thousand or so
Been there, seen that. There are no interesting little algorithms like binary tree search there.
Anyway let's forget all these primitive, archaic, simple minded languages like BASIC and C. Why doesn't the Propeller have a language designed around the concepts of parallel execution, isolated processes, process communication and so on.
Like, oh I don't know...like Occam, or maybe Erlang.
Erlang is brilliant. Erlang is:
General-purpose.
Concurrent / Parallel.
Garbage collected.
Mostly a functional style language, with immutable data.
Dynamically typed.
It supports distributed, fault-tolerant, soft-real-time, non-stop applications.
It supports hot swapping, so that code can be changed without stopping a system.
It supports threads without any libraries.
It supports message passing, no locks required.
An Erlang program for running a master process on on Prop, one local sub-process and one remote sub-process might look like this
(The % are comment markers):
[color=green]% Start a COG on this Propeller and run the function someObject:start(param1, param2)[/color]
ServerProcess = spawn(someObject, start, [param1, param2]),
[color=green]% Start a COG on a remotely connected Propeller and run the function someObject:start(param1, param2)[/color]
RemoteProcess = spawn(RemoteProp, someObject, start, [param1, param2]),
[color=green]% Send a message to that running COG process (asynchronously). The message consists of a tuple[/color]
[color=green]% with the atom "pause" and the number "10".[/color]
ServerProcess ! {pause, 10},
[color=green]% Receive messages sent to this process[/color]
receive
a_message -> do_something;
{data, DataContent} -> handle(DataContent);
{hello, Text} -> io:format("Got hello message: ~s", [Text]);
{goodbye, Text} -> io:format("Got goodbye message: ~s", [Text])
end.
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.
It common for folks that are looking from a single core general purpose processor to find the prop lacking. The prop is not designed as a general purpose CPU. The prop is designed for embedded applications, where very short time window is more inmportant than large memory size. The prop doesn't run linux nicely, while the Raspberyy Puidoes,; but the Raspberry Pi does not do real time stuff well at all, while the prop is really really good for this. This is why we use the prop for drivers, for our sensors and actuators, and use the linux box for large comms, long term storage, crunching, fancy graphical use interface etc.
If the article was written from the prespective of embedded microcontroller, then there might be more points of interest.
There are probably documents and examples for the various BASICS available for the Propeller. I have no idea. Other probably have links. A quick google site search would probably turn them up.
Firstly, kudos to everyone for ignoring unworthy and vituperative attacks. What a great way of dealing with them!
Secondly, to misquote prof_braino: If this thread dealt with C vs BASIC from the perspective of embedded microcontrollers, then there might be more points of interest.
Doubtlessly others disagree, but Windows and even Linux are so big and take so long to boot (from the POV of embedded control) that it almost seems irrelevant to discuss C and BASIC in the context of them. I mean how many of us want to wait even 20 seconds for our new widget to boot up every time we flip the switch?
Which led me to contemelious (which the iPhone spell checker just gives up on!)
Which is delicious in its definition as 'insolently abusive' - you can almost feel that!
If you are comfortable in BASIC the that's the right choice, if you find an example in Spin or PASM, that's the right choice, if c floats you boat (doubles your pleasure? Doesn't leave you void? Gills your brackets?) then it' the best choice.
That in C Pointers can be used to do what Assembler programmers do with indirect register addressing.
char *dpnt = buffer; char *spnt = mystr1;
while(*dpnt++ = *spnt++); // zero terminated string copy
compiles to (and I could not do it any better if I did the assembler programming by hand):
00C0A0 403F 0200 mov.w #0x200,R15 ;pointer to buffer
00C0A4 403E 0214 mov.w #0x214,R14 ;pointer to mystr1
00C0A8 4E7D mov.b @R14+,R13
00C0AA 4DCF 0000 mov.b R13,0x0(R15)
00C0AE 531F inc.w R15
00C0B0 934D tst.b R13
00C0B2 23FA jne 0xC0A8
I really cringe when people say that C is some kind of "high level assembler".
Well, it kind of, sort of is but:
Basically C is an abstraction over what all common computers are:
It assumes they all have memory addressed by some number.
It assumes they can somehow do the expected operations of +, -, *, / etc
It assumes they can all support decision making, "if this do that" etc. That can cause transfer of control.
That's it. It does that in a very succinct and efficient way. Brilliant! For this reason it has been ported to pretty much every machine that exists. And is what we build operating systems out of.
Other languages start from a different point of view. From the high level looking down. Perhaps messing with formulas is what you want to do, OK create FORTRAN. Perhaps messing with lists is what you want to do, OK create LISP. Perhaps making programming easy is what you want to do, OK create BASIC, or Python or Javascript etc. And so on.
Where am I going with this train of thought? I'm not sure, But higher level languages are higher level abstractions, and as Joe Armstrong says "It's better if you know what your abstractions are abstracting"
I really cringe when people say that C is some kind of "high level assembler".
Well, it kind of, sort of is but:
Basically C is an abstraction over what all common computers are:
It assumes they all have memory addressed by some number.
It assumes they can somehow do the expected operations of +, -, *, / etc
It assumes they can all support decision making, "if this do that" etc. That can cause transfer of control.
That's it. It does that in a very succinct and efficient way. Brilliant! For this reason it has been ported to pretty much every machine that exists. And is what we build operating systems out of.
Other languages start from a different point of view. From the high level looking down. Perhaps messing with formulas is what you want to do, OK create FORTRAN. Perhaps messing with lists is what you want to do, OK create LISP. Perhaps making programming easy is what you want to do, OK create BASIC, or Python or Javascript etc. And so on.
Where am I going with this train of thought? I'm not sure, But higher level languages are higher level abstractions, and as Joe Armstrong says "It's better if you know what your abstractions are abstracting"
The reason I refer to C as being a high level assembler is simple. The primary reason is to point out that C isn't truly a high level language but in fact a low level language. It is an abstraction to make it independent (for the most part) of the assembly/machine language of a given cpu or mpu and is capable of operations and functions not directly contained within the assembly/machine language of a given cpu or mpu. Which is why I refer to it as a high level assembly.
The reason I refer to C as being a high level assembler is simple. The primary reason is to point out that C isn't truly a high level language but in fact a low level language.
The two big things are garbage collection and buffer overruns. Any language which does not have GC and does not catch buffer overruns and array boundary violations is not a high level language, full stop. In fact, if you glaze over those two particular differences, BASIC and C become pretty isomorphic and something like BCX becomes truly representative.
Now there are good reasons why C doesn't do those things, all of which come down to performance both at compile and run time. You cannot write a high performance operating system or multi-threaded server in a garbage collected language, and there is a significant cost to checking all thouse array boundaries that aren't violated 99.9% of the time.
But when you don't need that performance, there are significant costs to having to manually reserve and release memory, and memory leaks become an insidious and hard to catch bug. Bugs from buffer overruns are even more insidious and potentially catastrophic. (Don't even get me started on the bugs that can creep into pointer arithmetic, which can be almost impossible for a non-expert to isolate.) These are problems you just don't have in BASIC. You also just don't have them in Javascript. Those are expensive but important conveniences for doing rapid development of non performance critical applications.
IMO no application that isn't performance critical should ever be done in a language like C which does not trap these assembly-language type catastrophic errors. Catching errors like that is the kind of grunt work computers are FOR.
Now the situation is a little different in microcontroller land where that expense is far more critical, you'll find syntactic BASICs which are far more like C under the hood. (Spin, which like BASIC is a language designed for teaching, is streamlined the same way for similar reasons.) But in general, when you talk about generic BASIC you're talking about a garbage collected bound-checking language unless it is operating on truly limited hardware. And in general, when you talk about C you're talking about a language that will let you blow your foot off with a howitzer even if you're writing a tic tac toe game on a 2 GHz 8-core PC.
Comments
I disagree that basic is automatically easier to read than C. For someone that has learned even very basic (sorry for the pun) syntax of both languages is it really easier to read:
10 print "howdy world
Than:
int main(){
puts ("howdy world");
}
?
Once you get past trivial programs all the need gotos needed to make basic works makes it nearly unreadable.
As you are curious: Because in mathematics "=" means "Exactly the same amount or value". It's a statement of equality. It is not an assignment. For example "a + b = c" does not assign c to a + b. How could it?
Better to use some other symbol for assignment to avoid confusion. Which many languages do. Of course C does it backwards, where "=" is the assignment and "==" is the test for equality.
Anyone who has ever done the slightest maths in school will be happy with this idea. Good question. Every language has it's weirdness. ALGOL is "free form" you don't have to put every statement on a new line. So you need some kind of separator. No worse than comas, semicolons, colons, and full stops in English. How can you say so? How compare and contrast:
BASIC:
FOR p = 3 TO 9 STEP 3
ALGOL:
for p := 3 step 3 until 9 do
Almost identical. Both equally readable or otherwise as some kind of "real" English. Where do you think BASIC got the idea from?
I might suggest that given a high school understanding of "=" the BASIC version is unintelligible. One has to be told what it does in both BASIC and ALGOL.
:
not
=
To say in different way, why algol needs :=, when basic uses only =
Clean, human readable code.
That "do" is not "hanging off the end", it's part of a larger structure. The for loop:
for p := 3 step 3 until 9 do
can be though of as saying:
For integer values of p starting from 3, in increments of 3, up until and including 9 this is what I want you to do:
something with p,
something else with p.
Honestly it's such a stylized version of English like symbols it does not make much difference.
In maths "=" is an expression of equivalence, it is not an assignment. Both BASIC can C are wrong to use "=" to mean assignment. As any high school maths student might agree. Many other languages do the correct thing and use a different symbols for assignment, Pascal, Ada, Spin, Algol...
":" is used in English to introduce a list. I believe that is what it is doing there in ALGOL. When it's not forming part of an assignment operator.
What the problem with the "not"?
Looks like gibberish to me. What does it mean "WS-FILE-STATUS"? Is that like, WS minus FILE minus STATUS?
COBOL looks nice until you try to write some interesting algorithms with it, say a binary tree search. That is a very short, simple and clear thing in most languages. I would love to see your example of it in COBOL.
There is a reason they say there are billions of lines of code in existence, if they had used a more reasonably concise language it would probably only be a hundred thousand or so
http://web.cse.ohio-state.edu/~sgomori/314/algs.html#tblseek
Anyway let's forget all these primitive, archaic, simple minded languages like BASIC and C. Why doesn't the Propeller have a language designed around the concepts of parallel execution, isolated processes, process communication and so on.
Like, oh I don't know...like Occam, or maybe Erlang.
Erlang is brilliant. Erlang is:
General-purpose.
Concurrent / Parallel.
Garbage collected.
Mostly a functional style language, with immutable data.
Dynamically typed.
It supports distributed, fault-tolerant, soft-real-time, non-stop applications.
It supports hot swapping, so that code can be changed without stopping a system.
It supports threads without any libraries.
It supports message passing, no locks required.
An Erlang program for running a master process on on Prop, one local sub-process and one remote sub-process might look like this
(The % are comment markers):
Which is better, yellow or blue?
Answer this question, and you will have you answer to C or Basic.
EXCELLENT news :-)
A fresh look often notices previously unseen things....
Clearly blue is better!!
If the article was written from the prespective of embedded microcontroller, then there might be more points of interest.
So there's no practical examples, right?
Like say, - "flash 16 leds with birghtness according to sin(X)" or whatsoever.
For C you can take a look at the Parallax learning materials here: http://learn.parallax.com/propeller-c-tutorials
There are probably documents and examples for the various BASICS available for the Propeller. I have no idea. Other probably have links. A quick google site search would probably turn them up.
http://forums.parallax.com/showthread.php/143397-PropBASIC-routine-for-quadrature-encoder-reading....FAST-and-worked-first-time!-%29?highlight=propbasic
Secondly, to misquote prof_braino: If this thread dealt with C vs BASIC from the perspective of embedded microcontrollers, then there might be more points of interest.
Doubtlessly others disagree, but Windows and even Linux are so big and take so long to boot (from the POV of embedded control) that it almost seems irrelevant to discuss C and BASIC in the context of them. I mean how many of us want to wait even 20 seconds for our new widget to boot up every time we flip the switch?
Thirdly,
Wow, I love this article!! <Instant bookmark.>
Which led me to contemelious (which the iPhone spell checker just gives up on!)
Which is delicious in its definition as 'insolently abusive' - you can almost feel that!
If you are comfortable in BASIC the that's the right choice, if you find an example in Spin or PASM, that's the right choice, if c floats you boat (doubles your pleasure? Doesn't leave you void? Gills your brackets?) then it' the best choice.
And finally, yellow and vanilla, of course!!
4x5n, I have never heard of the gets function. Which library is that in?
Well, it kind of, sort of is but:
Basically C is an abstraction over what all common computers are:
It assumes they all have memory addressed by some number.
It assumes they can somehow do the expected operations of +, -, *, / etc
It assumes they can all support decision making, "if this do that" etc. That can cause transfer of control.
That's it. It does that in a very succinct and efficient way. Brilliant! For this reason it has been ported to pretty much every machine that exists. And is what we build operating systems out of.
Other languages start from a different point of view. From the high level looking down. Perhaps messing with formulas is what you want to do, OK create FORTRAN. Perhaps messing with lists is what you want to do, OK create LISP. Perhaps making programming easy is what you want to do, OK create BASIC, or Python or Javascript etc. And so on.
Where am I going with this train of thought? I'm not sure, But higher level languages are higher level abstractions, and as Joe Armstrong says "It's better if you know what your abstractions are abstracting"
Great quote, sir!
The reason I refer to C as being a high level assembler is simple. The primary reason is to point out that C isn't truly a high level language but in fact a low level language. It is an abstraction to make it independent (for the most part) of the assembly/machine language of a given cpu or mpu and is capable of operations and functions not directly contained within the assembly/machine language of a given cpu or mpu. Which is why I refer to it as a high level assembly.
The two big things are garbage collection and buffer overruns. Any language which does not have GC and does not catch buffer overruns and array boundary violations is not a high level language, full stop. In fact, if you glaze over those two particular differences, BASIC and C become pretty isomorphic and something like BCX becomes truly representative.
Now there are good reasons why C doesn't do those things, all of which come down to performance both at compile and run time. You cannot write a high performance operating system or multi-threaded server in a garbage collected language, and there is a significant cost to checking all thouse array boundaries that aren't violated 99.9% of the time.
But when you don't need that performance, there are significant costs to having to manually reserve and release memory, and memory leaks become an insidious and hard to catch bug. Bugs from buffer overruns are even more insidious and potentially catastrophic. (Don't even get me started on the bugs that can creep into pointer arithmetic, which can be almost impossible for a non-expert to isolate.) These are problems you just don't have in BASIC. You also just don't have them in Javascript. Those are expensive but important conveniences for doing rapid development of non performance critical applications.
IMO no application that isn't performance critical should ever be done in a language like C which does not trap these assembly-language type catastrophic errors. Catching errors like that is the kind of grunt work computers are FOR.
Now the situation is a little different in microcontroller land where that expense is far more critical, you'll find syntactic BASICs which are far more like C under the hood. (Spin, which like BASIC is a language designed for teaching, is streamlined the same way for similar reasons.) But in general, when you talk about generic BASIC you're talking about a garbage collected bound-checking language unless it is operating on truly limited hardware. And in general, when you talk about C you're talking about a language that will let you blow your foot off with a howitzer even if you're writing a tic tac toe game on a 2 GHz 8-core PC.