Why C is better than BASIC, can anyone provide live example?
CuriousOne
Posts: 931
Hello.
I've often hear that C is way better than basic, because it is faster and more robust language. Indeed, C WAS FASTER once ago, when there was compilers for C and interpreters for BASIC. But currently, both being very effectively compiled. So I'm interested, can someone provide some simple task, and code in C and BASIC, so it will be possible to see, why C is better than BASIC ?
I've often hear that C is way better than basic, because it is faster and more robust language. Indeed, C WAS FASTER once ago, when there was compilers for C and interpreters for BASIC. But currently, both being very effectively compiled. So I'm interested, can someone provide some simple task, and code in C and BASIC, so it will be possible to see, why C is better than BASIC ?
Comments
You must always consider the advent of the PC, the main contributors of promoting the PC, and the languages that were mostly used. The one that was used the most, would of course be the most powerful, because it would be the most developed. Now if you are looking for specific examples, it would probably take hours to find such examples.
I would imagine, that if you were truly interested, you could probably find a huge difference between C and BASIC in image control and manipulation. To really see the difference, you would have to take a look at PC programming, but everything is always changing.
C is not what I'd call robust, and not even that well suited to Embedded control, lacking a native boolean type for a very long time, until it was dragged screaming, to join other languages.
The thing that determines C's success, is not syntax, or any of it's warts, it is something quite separate called 'critical mass'.
Basic, by comparison, is too divergent with no two the same.
EDIT: I believe it was the COM interfaces.
In what way is C not robust? What do you call robust? In what way not suited? That bool type seems such a minor convenience detail. I don't recall anyone having major difficulty without it.
Certainly there are more features of C inherited by languages that came after it than features like bool that have been "back ported" C. I think C should scream if anyone tries to "modernize" it. It is what it is and grafting modern features on to it will only make it worse
Oh, whilst I'm here. The only good thing about BASIC is that you get to C at the end of it
As IDBruce mentioned, much dependends on the context. Small architectures suffer an overburden from C. Big projects with adequate resources in terms of libraries do well with C.
Historically, C is a very important milestone in programing. It allowed programers to not have to learn a new lanaguge everytime they moved to a new platform, though Intel soon became the dominant platform for C.
Basic quickly turns to 'which Basic?' Some adhere to the principles of the original Dartmouth Basic and try not to do too much; while others have become huge and not really basic in spirit -- like VisualBasic.
C can easily be frustrating for new learners, just because the tool chain and error reporting is sophisticated. Spin and PASM are provided by Parallax to relieve the learning curve to some extent. Propeller Basic? Maybe even easier -- not sure.
Back in the day, there was no such thing as Visual Basic.NET, Visual C#.NET, or Visual C++.NET.....
But here is Microsofts rundown on the state of these languages: Reference 2003
https://msdn.microsoft.com/en-us/library/aa292164(v=vs.71).aspx
EDIT: Look at the list of services under C++
Which one?, is the chestnut (as above)?
FreeBasic ? Somewhat piecemeal, with separate IDE / Compiler / Debug efforts, but maybe good enough ?
Some talk of a RaspPi version.
VB ? Comes with a free, nicely polished IDE, but cannot create exe files ?
No talk of a RaspPi version ? or is there ?
http://blogs.msdn.com/b/laurelle/archive/2013/06/21/net-microframework-on-raspberrypi-part-1.aspx
At a later time I was eyeballing BBC BASIC which had extensions like subroutines, loop control, etc. And no line numbers
Now there are several "Basic" variants which aren't BASIC in the Dartmouth sense.
I was anyway thoroughly disgusted by BASIC and left it behind, even Fortran 66 was infinitely more structured than BASIC. Fortran 77 much more so. Well, even assembly language is more structured. So I moved on to Fortran and Pascal and other structured languages, and eventually to C. They are all infinitely more pleasurable to work with than BASIC. Now, "Basic" (in lots of modern more or less incompatible non-BASIC variants) are better, but I see no point in using that when there are alternatives which don't give me that low down feeling I get with BASIC. So for me, it's the experience with BASIC in the past. Programming should be fun, whenever I touch (even new) Basic I get that bad feeeling from old and nothing good can come out of it.
There is no "better". There is no answer to your question until you can say what it is you need be better. Easy to learn for beginners? Faster? Smaller? More portable? Easier for complex/large code? Wide user base? Better documentation? Better libraries? More widely available? Etc etc etc.
Program enough machines in enough languages for enough different applications and you will come to to find that all programming languages are flawed and annoying. That's why people keep inventing new ones!
If you are in this for the long haul you want your code to be useful on many different machines (large and small), with many different CPU architectures, with many different operating systems for years into the future. To that end the simplest DNA that runs all around the computing world today is C.
At the end of the day choice of language to use for any particular project is not all about technical evaluations, it's quite a lot about human social interaction. Despite what Loopy says programming languages are a means of communication between humans as much as English or Chinese. The one you use may depend on the one everyone else uses.
But as you have put your question as a challenge about performance I present my Fast Fourier Transform in C. It's a rude and crude FFT but works pretty well. Runs on any machine for which there is a C compiler. On the Propeller it can automatically make use of 1, 2, 4 or even 8 COGs to boost performance. It is impossible that any BASIC FFT is as quick or can easily use multiple COGs.
https://github.com/ZiCog/fftbench/blob/master/fftbench.c
Edit: I use the word "impossible" above in the usual sense of the word on this forum.
C was developed on machines with very small memory spaces, the PDP-8, PDP-11 era.
C (actually C++) is used on the tiny 8 bit AVR based Arduino. It is used to program even smaller devices. True. But when projects get big enough you start yearn for a language that can organize large code bases better. Enter C++.
To a large extent you are correct. One might say that "a language is a language and the differences in performance depend on if it is compiled or interpreted, or how efficient those compilers and interpreters are"
After all we have compiled BASICs which must be faster than interpreted, and we also have interpreters for C/C++ that must be slower than compilers. https://root.cern.ch/drupal/content/cint
However, the actual syntax and semantics of a language design can also determine it's performance. Or even whether it can be compiled at all.
Languages like FORTRAN, ALGOL, C and the many children in that linage are designed to be easily compiled to small, efficient, fast code.
Language like Lisp, Scheme, JavaScript are designed with different criteria that actually make them very hard or impossible to compile to an efficient binary executable.
For example, in JavaScript I can write: Well, what code should that be compiled to? If x is a number we want that "+" to be a floating point addition and then return an number. If that "x" is a string we want to do a conversion of the number 2 to a string and then do a string concatenation and return a string. If there were a JS compiler it would have no idea what to do. An interpreter is the only way to deal with this.
How BASIC fits in the scheme of things I'm not sure. Is it possible to make an efficient BASIC compiler?
Most BASIC dialects I've worked with weren't sufficiently dynamic to inhibit compilation. So I would guess that BASIC has more in common with C than JavaScript.
If BASIC has descended into pointer madness then I see no reason for it. Just use C.
However, none of that matters. What matters is that you can write things like this in C:
No, C is not better than BASIC, nor is BASIC better than C. Each is a tool for a specific job. BASIC is more basic, and therefore less flexible. C is more flexible in that you can do lots of intricate stuff, but allow you to shoot yourself in the foot more often. Sometimes you can miss, and shoot yourself in the head.
Here's your example use cases:
If you are starting out and just want to make a program work, BASIC is fine. But know how to slap together a program in BASIC does NOT qualify one as a programming expert.
If you know a LOT about programming and good programming practices, and know C; then use C. Otherwise, avoid it until you can learn good programming practices.
Right tool for the right job, as allways.
Those BASICs are slower than C because they are better than C, in that they have native string handling immune to buffer overruns. The later VB's even manage to handle arbitrarily long strings effectively without noticeable garbage collection pauses which would glitch the 16-bit string libraries. C is of course faster but that's because it isn't doing as much copying and isn't doing all that bound checking. That's an issue for things like operating systems or web servers that have to handle thousands of concurrent requests, but for applications the performance is adequate and the convenience wins the day.
BASIC also separates itself from languages like Javascript because that string handling is native, not part of a library, and yet the language is strongly typed, which is an advantage when one wants to manage resources closely or catch certain kinds of error. It's very sad that development essentially stopped when Microsoft stabbed the VB community in the back and that nothing new has happened since VB6, but then 6 was a very mature language that still works almost flawlessly and works in emulation better than .NET.
The other main advantage C has is threading, which shouldn't be an issue ("Threading is for people who don't understand state machines") but is because some OS functions require it for optimization. VB5 could be coaxed to spawn threads and there were some interesting demos but 6 was deliberately crippled to make that impossible. On the other hand 6 introduced some very powerful string array functions which go a long way toward making up for that.
The main difference between the languages is the focus of their designers. C was designed to give maximum power and performance in very minimal hardware and it shows. BASIC was designed to be easy to use. Now that the hardware has gotten thousands of times more powerful than the original designers ever dreamed, one of those goals is not as important as it once was.
I was following along with you there and mostly agreeing until I came to this: Well, C, the language, has no concept of threads. Unlike Erlang or Occam or xc or Ada for example. So I'm not sure what you mean.
Also I'm curious as to what OS functions require threads for optimization? It's generally accepted that the context switching involved in threaded code is a major performance drag. That's why languages that can handle many concurrent tasks efficiently, Erlang, JavaScript, are not threaded.
Then I was agreeing some more until I came to: That is all true but efficiency matters. When you scale up your energy and hardware bills become significant and small savings can save millions of dollars. That is why Facebook messaging uses Erlang for example.
On the other end of the spectrum we are scaling down. To battery powered mobile devices and those "Internet of Things" things where efficiency is very desirable.
you can programm ARDUINO hardware also with the very easy to use BASCOM.
www.mcselec.com
And one of the great things is the inline ASM should you want to do something really time critical.
And to add to LocalRoger -
I also still use VB6 to create small standalone applications.
Or even VBA inside EXCEL which is almost identical to VB6 and VERY similar to BASCOM (if you don't use the objects and extensions).
So I have VBA - Visual Basic for Applications code that I did easily port to BASCOM.
When I came to the Prop I was thinking about PropBASIC,
but then Tachyon started and it's gravity pulled me in ;-)
In general: have a look into your toolbox. Is there only one hammer or also maybe a screwdriver, a saw ...
It is good to have the choice :-)
@heater, your sentence seems to have ended prematurely! "...and so Forth" what? I'm sure you were bringing up an important point!
As discussed ad nauseum, it ends up being horses for courses. Whatever you think fits you and the task best works best until you find it doesn't.
I'll ask back to the original poster......Why is chocolate ice cream better than vanilla??
C/C++ is like owning an entire hardware store
And Basic has a Dim future.
BASCOM, do what? Nearly one hundred Euros. Allows me to spend hours of my life creating code in a language that is never going to be useful anywhere else but on the AVR. And I can only do it if I use a certain operating system to run the IDE. I think not. This is not 1990 any more.
Or have I missed a point about BASCOM some how? Yep. Totally with you there.
If anyone wants to know what programming language is "best", there is only one way, try them, see what they offer, see where they work, see what you can do.
But yes, horses for courses.
At least if somebody flogs a dead horse long enough we might get some good salami