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

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

145791012

Comments

  • User NameUser Name Posts: 1,451
    edited 2015-04-02 07:32
    Heater. wrote: »

    "Simplicity is prerequisite for reliability."

    Yup.
  • Heater.Heater. Posts: 21,230
    edited 2015-04-02 07:35
    Username,
    "Simplicity is prerequisite for reliability."
    Yep.

    Which side are you arguing for there?
  • MicksterMickster Posts: 2,693
    edited 2015-04-02 08:06
    User Name wrote: »
    "Simplicity is prerequisite for reliability."

    Yup.

    IOW...keep it very BASIC
  • User NameUser Name Posts: 1,451
    edited 2015-04-02 08:13
    Heater. wrote: »
    Which side are you arguing for there?

    Neither side. Just a general statement. My apologies for being completely off-topic. (Although I would note that one of the virtues of the Propeller is the simplicity of its hardware design and its native languages.)

    On the C vs Basic discussion, I've already cast my vote (#38). But my orientation is entirely microcontroller-centric, living close to bare metal and accounting for every cycle, mostly because the things I code need the speed, dependability, and temporal resolution.

    I'd agree with Mickster that there are many cases where Basic is the perfect tool (it certainly did the trick on thermodynamics assignments at university). It all depends on what you are doing and where. But others have already made these points. The discussion has already exceeded its utility in many respects.
  • MicksterMickster Posts: 2,693
    edited 2015-04-02 08:57
    This is a PowerBASIC Hello World, 8KB standalone.

    https://www.dropbox.com/s/gftkftixbu9w9pk/Hello.exe?dl=0
  • 4x5n4x5n Posts: 745
    edited 2015-04-02 11:53
    Heater. wrote: »
    idbruce,

    What's all this Visual Basic vs Visual C++ nonsense? How off topic can we get?

    Visual C++ is not even a programming language it's an IDE and libraries. The language it uses is C++ and that is not the language under discussion, C. Same for Visual BASIC except that the name also refers to yet another non-standard dialect of a BASIC like language.

    Neither of these are useful outside of their legacy operating system. And so are not interesting to the world at large.

    In the same way that every Christian should have a bible, every C programmer should have a K&R. Similarly it's not necessary to actually read it :)

    However doing so does at least teach people the difference between a programming language and an IDE :)

    Speaking non-standard dialects. I created a new version of basic call CBasic!! It's exactly like C and in fact uses the same header files, libraries and compilers as C, but it has basic in the name so it's now a variation of basic and superior to C!!!!
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-04-02 12:27
    Now, nobody has any excuse to just sit in their tepid pool of linguistic comfort and throw slime at their neighbor!

    CodingGround by TutorialsPoint offers a BUNCH of terminal interface and IDEs to test drive!! 80 different IDEs and 18 different terminal interfaces. No reason to be bored, no reason not to learn something new. No reason to fear the unknown or to attack a friend who just sees a different means to an end!!

    Go play, report back in 24 hours with something you learned about a language you never tried!
  • tonyp12tonyp12 Posts: 1,951
    edited 2015-04-02 14:21
    >Since I can't read C code

    That have stopped me also for 20 years to even look at it as it looked stupid, why does so many lines start with void should this part not be used? I thought.
    It turns out that every snipped of code can return an int, but if the routine in never suppose to have anything to say back you use void.
    So even start up code: void main() {... } uses it,
    As reset-vector my jump a initializer routine first and though main() routine hardly ever exits, there is a routine to handle that if it does but it don't expect a variable back.

    But this year I started to look in to it and now I get it, it's very structure and function friendly language.
  • localrogerlocalroger Posts: 3,451
    edited 2015-04-02 16:19
    I think there is a lot of confusion about the elements that make both "BASIC" and "better."

    A lot of BASIC is syntax, and it's possible to build a BASIC that is completely equivalent to C but uses = instead of == for equivalence, that parses line breaks and uses keywords like END IF or LOOP instead of braces to delimit code blocks, and so on, but which has the same variable structures and calling conventions. In fact one could make a version of BASIC that essentially IS C, with the ability to call all the same libraries.

    http://bcx-basic.sourceforge.net/

    But what makes most BASICs really different are a few things that aren't isomorphic.

    * Not having to dimension variables, and declaring types with suffixes like integer%, long&, and string$
    * Garbage collected overrun-immune string variables
    * String functions that look and act like numeric functions, not library calls, and can be embedded in shared expression evaluations
    * Overrun-protected arrays

    Not requiring DIM is considered bad in some circles but is a great convenience when you're whacking out something quick. The other things are great conveniences in absolute terms, but cost in terms of performance. The single most common class of code security vulnerability, the buffer overrun, simply is not possible in most BASICs, at all. But standard BASIC string handling creates difficult performance bottlenecks in high performance code.

    Of course, we have IBM to thank for one of these problems with C. The 80286 was intended to have hardware array bound checking so that it could be implemented without a performance cost. But IBM used the interrupt Intel reserved for that purpose to print the screen on the IBM PC, and the feature was never implemented in a widely used product the way Intel had intended.

    On the Propeller, the difference between BASIC and C is less than in other usual venues. One could easily make a version of BCX to make a BASIC out of any of the Propeller C compilers. Propeller BASIC's don't tend to have even the minimal string functions of Microsoft 8-bit TRS-80 BASIC because of memory limitations, so they are more C-like in that way. So a lot of it comes down to whether you want to be forced to declare variables and whether you want array bound checking.

    The other thing is the large number of libraries available for C; as BCX shows you can make a "basic" that can use them. The larger issue is whether a tool like gcc produces object code that is really well suited for a limited and very unusual environment like the Propeller. My experience with the Radio Shack LCD shield showed that even gcc byte code is both very large and very slow, the latter probably because of stack frame overhead on function calls. This is a feature that costs little on an 8088 but kills you on the Propeller, where the software stack is a costly extravagance.

    Both C and BASIC were originally designed around tight constraints to be the most useful possible language for very limited primitive computers. Both languages have evolved into more modernly useful forms for more modern machines, and in importantly different directions. In a very real sense which one is better depends more on the platform than anything else.

    Though I have to say C ignoring line breaks and using all those braces and brackets makes my eyes bleed. But there's always BCX for that :-)
  • Heater.Heater. Posts: 21,230
    edited 2015-04-02 21:26
    localroger,
    ...we have IBM to thank for one of these problems with C...
    I like to blame IBM for many things in the personal computer world but I don't think we can pin this one on them.

    C was around long before the 286, dating back to the early 1970's and is based on language designs from the late 60's. They did not cater for array bounds checking.

    I'm not sure that it is even possible to have array bounds checking in C, without changing the language, the syntax and semantics don't support it. Given that an array and a pointer are interchangeable I don't see how one could add array bound checking.

    At the time of the 286 it was mostly running MSDOS which had no idea about any protected modes of the chip. Basically running as if on a 8088 (As far as I can tell).
    ...all those braces and brackets makes my eyes bleed...
    I hear that sentiment a lot. What I don't understand is how the bracketing in C is any worse than that in modern structured BASIC dialects. I would much rather have {...} than WHILE...WEND. It's the same kind of bracketing, except less verbose and ugly.

    On the other hand all those round braces in a language like lisp or scheme drive one crazy. There are so many and they are all the same, you can't see where you are without counting them all.
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-03 04:13
    Heater. wrote: »
    On the other hand all those round braces in a language like lisp or scheme drive one crazy. There are so many and they are all the same, you can see where you are without counting them all.
    Well, you could try indenting your code to reflect the block structure. I guess you pretty much have to do that in any language to make any sense of a function that is longer than a one-liner. A paren matching editor helps too. Anyway, I don't think I'm going to make any LISP converts here especially since there is no viable LISP for the Propeller. :-)
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2015-04-03 04:22
    "C was originally developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs,[5] and used to (re-)implement the Unix operating system.[6] It has since become one of the most widely used programming languages of all time,[7][8] with C compilers from various vendors available for the majority of existing computer architectures and operating systems. C has been standardized by the American National Standards Institute (ANSI) since 1989 (see ANSI C) and subsequently by the International Organization for Standardization (ISO)."

    http://en.wikipedia.org/wiki/C_%28programming_language%29
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2015-04-03 04:34
    @idBruce

    re: Come On Bob

    WSH isn't even in the same ballpark as C or full blown Basic.
    =========================================================================================================================
    I did not say it was, I did not imply it was . I did not even think it was. I didn't mention C at all. I only replied to your statement.


    re:"Visual C++ Windows Shell Programming". Some pretty in depth stuff.

    I have a copy of the book. There is lots of info on WSH in it. For shell access it does it through the shell API or COM objects. Nothing really special. I've used Delphi to do that kind of stuff since Win 95.

    If you want to do it in VB use this:

    Visual Basic for Applications Reference
    Visual Studio 6.0
    Shell Function
    https://msdn.microsoft.com/en-us/library/aa242087%28v=vs.60%29.aspx
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2015-04-03 05:21
    re:Why C is better than BASIC, can anyone provide live example?

    Use the right tool for the job . If it get the job done and your happy & productive so be it and it's the right tool for you. C is not my favorite language but neither is Basic . I've use it(mikroC) on PIC microcontrollers for a few projects. . Recently I tried a few mini C programs on the Prop. I just did a few C G++ tests on the Raspberry Pi 2. I've tried Visual C++. However, I much prefer Pascal, Object Pascal(Delphi) when I can use it. Sometimes it's not what's better it's what you like, as long as it allows you to be productive. The first basic I played with was on a Radio Shack TRS 80. Then I tried it on the Vic 20, C-64 etc. When Visual Basic was available I tried it. I got hooked on Pascal when I was in the military and stationed in Germany(1988) I purchased a Commodore PC 10 no color screen, no Hard Drive, no internet, but it was IBM compatible . :) It was during that period that I was introduced to Pascal by a Ham Radio friend. I remember buying Pascal books by Tom Swan. I have always used Pascal when it's possible since then. I loved the syntax. A well written Pascal program looks Poetic to me LOL I just got the free Pascal compiler working on the Raspberry Pi 2 last night. Now I'm all set :)

    The advantages I see in C are the ability to do low level stuff, over all Industry acceptance and availability on so many different platforms. To me It's just plain ugly to look at :

    Picture - Commodore PC 10( great memories)
    (https://www.google.ca/search?q=commodore+pc+10&biw=1680&bih=927&tbm=isch&tbo=u&source=univ&sa=X&ei=x38eVZCIIcuqgwTSwYDQAw&sqi=2&ved=0CCMQsAQ#imgdii=_&imgrc=Tgoy4nWAdH18FM%253A%3Bv38iRuYzYaMbqM%3Bhttp%253A%252F%252Fwww.retroisle.com%252Fcommodore%252Fpcs%252FPictures%252Fimages_pc1020%252Fpc10.jpg%3Bhttp%253A%252F%252Fwww.retroisle.com%252Fcommodore%252Fpcs%252Fgeneral.php%3B674%3B786)
  • idbruceidbruce Posts: 6,197
    edited 2015-04-03 05:35
    Bob
    I have a copy of the book. There is lots of info on WSH in it. For shell access it does it through the shell API or COM objects. Nothing really special. I've used Delphi to do that kind of stuff since Win 95.

    Nothing really special.... :) Unless you know the techniques, by learning through such a book, modifying the shell would be extremely difficult.
  • Heater.Heater. Posts: 21,230
    edited 2015-04-03 06:11
    Dave,
    Well, you could try indenting your code to reflect the block structure.
    Well, you could. But it would not help. There is no sensible way indent Lisp or Scheme etc.

    For example, a typical tutorial Scheme program:
    (define (fact n)
      (if (= n 1)
        1
        (* n (fact (- n 1)))))
    
    How would you indent that? Like this maybe:
    (define (fact n)
      (if (= n 1)
        1
        (* n (fact (- n 1)))
      )
    )
    
    Sort of helps but not much.

    Strangely most Lisp/Scheme code I have seen does not do that.
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-03 06:13
    Heater. wrote: »
    Dave,

    Well, you could. But it would not help. There is no sensible way indent Lisp or Scheme etc.

    For example, a typical tutorial Scheme program:
    (define (fact n)
      (if (= n 1)
        1
        (* n (fact (- n 1)))))
    
    How would you indent that? Like this maybe:
    (define (fact n)
      (if (= n 1)
        1
        (* n (fact (- n 1)))
      )
    )
    
    Sort of helps but not much.

    Strangely most Lisp/Scheme code I have seen does not do that.
    Right. Most Lisp programmers prefer the first. I think it has to do with being able to see more of the code on a screen at the same time. However, I don't see that your second example is any harder to read than C.
  • Heater.Heater. Posts: 21,230
    edited 2015-04-03 06:25
    Bob,
    To me It's [C] just plain ugly to look at.
    From time to time I have to do some work on a couple of big Pascal applications, I hate it, to me Pascal is plain ugly.

    What's with all the "begin".."end" nonsense? See my post #125.

    Especially since you need a semicolon after "end" as well. Why the redundancy?

    Not only that but it's inconsistent. Why do we have:
    for a := 10  to 20 do
    begin
        writeln('value of a: ', a);
    end;
    
    while number>0 do
    begin
       sum := sum + number;
       number := number - 2;
    end;
    
    repeat
       sum := sum + number;
       number := number - 2;
    until number = 0;
    
    How come the last loop there does not use "begin"..."end"?

    Anyway. Let's not debate Pascal.

    I'm just puzzled as to how it comes to be that different people have different gut reactions to a language, "It's ugly" or it's "poetic". What is it in their past education or experience that causes them to see it so differently? Usually with no hope of ever getting them to change their mind.
  • Heater.Heater. Posts: 21,230
    edited 2015-04-03 06:32
    Dave,
    I don't see that your second example is any harder to read than C.
    In that simple example perhaps not.

    Thing is in C we have blocks of code or data (structs) with "{...}" around them. We have parameter lists with "(..)". We have arrays with "[...]".

    Meanwhile in Lisp/Scheme it's the same "(...)" for everything. That's confusing.

    On top of that you need a lot more braces to do the same thing in Scheme as more C like languages. Contrast:

    2 * 3 + 4 * 5

    vs

    (+ (* 2 3) (* 4 5))

    Eew...
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-04-03 06:34
    Heater. wrote: »
    Dave,

    Well, you could. But it would not help. There is no sensible way indent Lisp or Scheme etc.

    For example, a typical tutorial Scheme program:
    (define (fact n)
      (if (= n 1)
        1
        (* n (fact (- n 1)))))
    
    How would you indent that? Like this maybe:
    (define (fact n)
      (if (= n 1)
        1
        (* n (fact (- n 1)))
      )
    )
    
    Sort of helps but not much.

    Strangely most Lisp/Scheme code I have seen does not do that.

    OW!!!!

    There must be some very old Lisp brain cells still alive in my brain! I looked at your example and some dusty old synapse fired in vain trying to find friends that remember...when the heck did I program in Lisp????

    I don't think the first form is all that hideous - no more so than any of those bracketed languages.

    Maybe all this object/non-object,strong/weak typing, etc. is all just a waste of classification time. Maybe it should just be brackets and no-brackets! :D
  • idbruceidbruce Posts: 6,197
    edited 2015-04-03 06:35
    Heater
    From time to time I have to do some work on a couple of big Pascal applications, I hate it, to me Pascal is plain ugly.

    I ported a portion of Pascal yesterday to C, and there were portions of it that looked similar to SPIN, e.g. :=
  • David BetzDavid Betz Posts: 14,516
    edited 2015-04-03 06:35
    Heater. wrote: »
    Dave,

    In that simple example perhaps not.

    Thing is in C we have blocks of code or data (structs) with "{...}" around them. We have parameter lists with "(..)". We have arrays with "[...]".

    Meanwhile in Lisp/Scheme it's the same "(...)" for everything. That's confusing.

    On top of that you need a lot more braces to do the same thing in Scheme as more C like languages. Contrast:

    2 * 3 + 4 * 5

    vs

    (+ (* 2 3) (* 4 5))

    Eew...
    Yeah, it does take a different mindset. I suppose it's like adopting Forth. You have to leave behind your expectations about how arithmetic expressions are written.
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-04-03 06:53
    Heater. wrote: »
    I'm just puzzled as to how it comes to be that different people have different gut reactions to a language, "It's ugly" or it's "poetic". What is it in their past education or experience that causes them to see it so differently? Usually with no hope of ever getting them to change their mind.

    Just like everything else, people are irrational, illogical, emotional creatures that are all different in the way their brains process things. In the same way people learn differently, grasp different subjects at different rates, have different talents and skills, people see programming languages and concepts differently. That's one reason there are so many programming languages.

    Some people are better at abstraction, some can't deal with abstraction and need concrete mappings to things.

    It would be an interesting study to to group people by what languages they grok easily and then look at psychological profiles to see what traits they might share. Then go to the general population and find people with matching traits and see what their reactions are to the languages they should see in their positive group and their negative group. (Sorry to introduce "soft sciences" into this realm of engineering!!)

    You are right, there is little hope in changing minds. Some day, something may click inside someones head (finally) and then they see what everyone else does that makes that language "the best".
  • Heater.Heater. Posts: 21,230
    edited 2015-04-03 07:32
    David,

    I quite appreciate the concept of Lisp/Scheme. Every thing is a list.

    As I said, C has lists of statements, lists of parameters, lists of array elements. There are all just lists right? So obviously they should be bracketed similarly. Then we can manipulate lists of statements, parameters and elements all in the same way. And do magic stuff.

    Can't do that in C of course because all those lists are fixed at compile time (Except the varargs thing)

    It's just annoying that Scheme needs twice as many characters, a lot of brace noise, to write simple things.

    But then you can seriously meta, meta with it :)
  • Heater.Heater. Posts: 21,230
    edited 2015-04-03 07:34
    mindrobots,
    Just like everything else, people are ... all different in the way their brains process things.
    Yeah. I bet there are even people out there that don't like bacon :)
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-04-03 07:36
    Heater. wrote: »
    mindrobots,

    Yeah. I bet there are even people out there that don't like bacon :)

    Not when I'm finally in charge!!! Tolerance only goes so far!
  • Mark_TMark_T Posts: 1,981
    edited 2015-04-03 07:40
    No-one seems to have noticed the obvious, that there is no international standard for BASIC (well I've not
    noticed any). Also I wonder on the need to compare C and BASIC, since there are many other languages
    out there which might be "better" given a set of requirements/desirable properties. False dichotomy.
  • Heater.Heater. Posts: 21,230
    edited 2015-04-03 07:46
    Mark_T,

    The lack of a standard for BASIC has been noted many times here. At least back to post #73.

    There is actually an ANSI standard. It's pretty old now and I bet most BASICs do not adhere to it, if they ever did.

    Seems BASIC users don't care about such things so it's not even an argument in their minds.
  • MicksterMickster Posts: 2,693
    edited 2015-04-03 08:16
    @CuriousOne

    "can anyone provide live example?".....11 pages in and apparently not!

    VB and VC are "off topic" but apparently Scheme/Lisp/Pascal are on topic (I must be misinterpreting the title again)

    We have one who makes claims that C will "blow the pants off Basic" but can't tell us how/why. I guess he just read it somewhere.

    The statement was made: "Also, what your program does not use does not get linked in, that's great when you want tiny code." So I provided a compiled Windows BASIC "Hello World" that is ~8KB (no dependencies) and it fell on deaf ears.

    A data structure example written in C was used as an example of something that couldn't be done in BASIC. It took like 15mins (I'm slow on the keyboard) to replicate it using a 28 year old DOS BASIC and the bonus was improved readability.
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-04-03 08:34
    Mickster, your link goes to a hello.exe file on dropbox. I'm not sure how useful that is for proving your point. A C version of "Hello World" is "void main() { printf("Hello World\n"); }". It compiles to a 4,296 byte CMM binary.

    I have a threaded chess program written in C at http://forums.parallax.com/showthread.php/148414-Threaded-Chess . I'm looking forward to seeing your BASIC version of it. :)
Sign In or Register to comment.