Timeline for Why do variable names in BASIC need type suffixes?
Current License: CC BY-SA 4.0
45 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 30, 2021 at 20:47 | review | Suggested edits | |||
Sep 30, 2021 at 22:21 | |||||
Sep 30, 2021 at 18:15 | review | Low quality posts | |||
Sep 30, 2021 at 20:53 | |||||
S Sep 30, 2021 at 17:40 | history | edited | Raffzahn | CC BY-SA 4.0 |
fix botched markdown
|
S Sep 30, 2021 at 17:40 | history | suggested | JDługosz | CC BY-SA 4.0 |
fix botched markdown
|
Sep 30, 2021 at 15:50 | review | Suggested edits | |||
S Sep 30, 2021 at 17:40 | |||||
Sep 29, 2021 at 22:09 | history | edited | Raffzahn | CC BY-SA 4.0 |
added 435 characters in body
|
Sep 29, 2021 at 21:50 | comment | added | Raffzahn | @supercat And the point is? The same way one could drop the suffix notation in BASIC, which is what the OP had in mind (and Visual BASIC did). Just, it wouldn't anymore be BASIC, same way as dropping parenthesis around function argument would make it no longer C. | |
Sep 29, 2021 at 17:48 | comment | added | supercat |
@Raffzahn: The Standard allows Conforming C Implementations to extend the language in arbitrary fashion, with only three caveats: (1) Programs where an #error directive survives preprocessing must be rejected ; (2) An implementation would need to issue a diagnostic upon receipt of some programs, but may issue such a diagnostic at arbitrary other times as well or even unconditionally; (3) extensions must not affect the behavior of Strictly Conforming C Programs. For a C compiler to accept code like what you show would be weird, but nothing in the Standard would forbid such a thing.
|
|
Sep 29, 2021 at 17:37 | comment | added | Steve | "It is about introducing concepts that are completely alien to students in the 1960s." - it's worth noting that whilst general purpose computer hardware was new in the 1960s, the principles of mathematics and secretarial science were not, and it's very likely that the average university student in the 1960s had a much better conceptual grounding than the average modern student. | |
Sep 29, 2021 at 16:34 | history | edited | Raffzahn | CC BY-SA 4.0 |
added 352 characters in body
|
Sep 29, 2021 at 16:07 | comment | added | Raffzahn | @WillisBlackburn But it's exactly that point. The suffix is not just a qualifier, but part of the name. A and A$ are two different variables (IIRC even in Atari BASIC - it's stored in the variable table entry as part of the name and compared accordingly). It's because BASIC is defined that way. | |
S Sep 29, 2021 at 11:54 | history | suggested | CGCampbell | CC BY-SA 4.0 |
minor spelling and grammar
|
Sep 29, 2021 at 11:13 | review | Suggested edits | |||
S Sep 29, 2021 at 11:54 | |||||
Sep 28, 2021 at 22:40 | comment | added | Willis Blackburn | @Raffzahn The question was about why BASIC uses type suffixes instead of just implementing dynamic typing at runtime, which you pointed out that many BASICs actually do. I only used Atari BASIC as an example of a BASIC where the type of each variable is known at runtime. I think I understand the rationale, but your initial answer, "because it's BASIC," wasn't helpful. | |
Sep 28, 2021 at 20:16 | history | edited | Raffzahn | CC BY-SA 4.0 |
added 206 characters in body
|
Sep 28, 2021 at 19:40 | comment | added | Raffzahn |
@WillisBlackburn BASIC requires by definition that string variables are marked by a trailing '$' sign - despite the possibility of compiler/interpreter that could do without. The same way C requires that all functions need to have parenthesis and required them to be matching, no matter if a compiler could be written that would work without, like accept fu(bar); , fu (bar; or fu bar; all the same. A compiler not requiring parenthesis would simply be not a C compiler.
|
|
Sep 28, 2021 at 19:28 | comment | added | Raffzahn | @WillisBlackburn Erm, It seems you're random jumping between questions about specific implementations, like Atari BASIC, but insist to want general answer about BASIC as a language, don't you? It would help if you could stay with one topic. Atari BASIC is in many ways a special case with implementation specific details. So is your question not about BASIC and its syntax, but why Atari did stick to standard syntax despite being able to do different? If that's the case, then please tell so. I start to belive that the question is not well thought thru and may need to be more focused. | |
Sep 28, 2021 at 17:36 | comment | added | Jim Nelson | As mentioned in my link above, one of Atari BASIC's features is that it performs tokenization at the time the line is entered, and even points to the character in the line where it first detected a problem. That was unusual at the time, however. | |
Sep 28, 2021 at 15:29 | comment | added | Willis Blackburn |
It's easy to demonstrate that Atari BASIC at least does do type-checking at program entry. Entering 10 PRINT "X"+1 immediately produces an error.
|
|
Sep 28, 2021 at 15:25 | comment | added | Willis Blackburn | @Raffzahn Kind of confused by all the different answers. First you said there is "no room for complex runtime management to have dynamic typing" but then you said that no type-checking is performed at the point of program entry... it can't be both ways. If the code logic is "check if the operands to this plus operator are both integers, and if so then add them, otherwise generate an error," that's dynamic typing. A statically-typed program would just add the two numbers, knowing that they were integers. | |
Sep 28, 2021 at 14:56 | comment | added | Raffzahn | @WillisBlackburn (caveat, there are many variations out there even such you'd like) No, it's just the other way around - most basic do NOT type check anything when source lines get entered. They just crunch them into a more compact representation, which gets interpreted at runtime. Type checking is done during interpretation, but there is no polymorphism. A function called simply checks if the parameters supplied are of the required type and throws an error when otherwise. During runtime and from left to right. It also has nothing to do with compilers as back then compilers were as simple. | |
Sep 28, 2021 at 14:44 | comment | added | Willis Blackburn | The answer that I think is becoming apparent is that BASIC type-checks program lines when they are parsed or compiled but does not check expression types at runtime, and the reason for this is that although a BASIC interpreter with an integrated editor like Atari BASIC obviously has to carry around type-checking code and could apply it at runtime, earlier BASIC implementations were compilers, and type-checking during compilation enabled those compilers to produce a smaller executable. | |
Sep 28, 2021 at 6:19 | comment | added | Patrick Schlüter | @WillisBlackburn Microsoft level 2 Basic could declare variables and their types. DEFDBL A-Z or DEFINT I, etc. This said, the choice of a sigils to distinguish variable type is a language design choice. Perl is for example another example besides BASIC. As for Python's variable they are not typeless, they are so called sumtypes, i.e. a union of all types. The variable has one type that is chosen when initialising the variable. | |
Sep 28, 2021 at 5:07 | comment | added | Raffzahn | @WillisBlackburn You're arguing again with Atari BASIC and in hindsight. So if you want a more technical answer: BASIC was developed in 1964 on a GE-225 Computer with 8 Ki Word of drum based memory running in batch mode, which got user programs feed as virtual punch cards by a DN-30 front-end processor. There is no room for a complex runtime management to have dynamic typing or a compiler analysing program flow to guess types. Not to mention, that dynamic typing wasn't a thing in 1964. | |
Sep 28, 2021 at 4:30 | comment | added | UncleBod | @WillisBlackburn Yes, Python doesn't have type. But The Python runtime (Just the program named python2.7) on my system is bigger than 3 MB. I would have trouble to fit that into a 8-bit computer. Even with overlays and memory banking. | |
Sep 27, 2021 at 21:56 | comment | added | dan04 |
Also note that most dialects of BASIC treated arrays as a separate namespace, so A , A$ , and A() would all denote different variables.
|
|
Sep 27, 2021 at 21:32 | comment | added | dave | @WillisBlackburn - dynamic typing requires a runtime system that static typing does not. BASIC was a compiled language when language decisions were being made. | |
Sep 27, 2021 at 21:16 | comment | added | dave | @WillisBlackburn - for any implementation except the original Dartmouth BASIC, the answer to why is "because that is the language". For Dartmouth, the answer is probably (and here we have to guess, unless there's a rationale written by Thomas Kurtz or John Kemeny hiding somewhere) "because it made the language easier to use". See my answer. | |
Sep 27, 2021 at 19:39 | comment | added | Willis Blackburn | Maybe other BASICs had separate variable name tables for, say, integers and reals. That would allow the interpreter to reserve only 2 bytes for each integer instead of the 4 or 6 bytes (or in Atari BASIC's case, 8 byte) needed to store a value of any type. Can anyone identify a BASIC that worked that way? | |
Sep 27, 2021 at 19:37 | comment | added | Willis Blackburn | Kind of looking for a more technical answer. I think you're saying, variables have to have a declared type, and just suffixing string variables with '$' saves the novice programmer from having to declare the variables as strings before using them. Except that variables don't have to have a declared type. They don't in Python, or in JavaScript, or in a lot of other languages. It would have been easier to just let the programmer assign values to variables without worrying about type. Atari BASIC at least was clearly capable of changing the type of a variable based on its assigned value. | |
Sep 27, 2021 at 17:26 | comment | added | Jim Nelson | A good study of the differences between Atari BASIC and its brethren: web.archive.org/web/20070524044410/http://www3.sympatico.ca/… (written by @maury-markowitz, I think?) | |
Sep 27, 2021 at 15:10 | history | edited | Raffzahn | CC BY-SA 4.0 |
added 137 characters in body
|
Sep 27, 2021 at 15:07 | comment | added | Raffzahn | @StephenKitt yes, by now I think the 'features' of Atari BASIC are the real origin why the OP came to ask in the first place. Easy to stray afar when only looking at this (very special) implementation. | |
Sep 27, 2021 at 15:02 | history | edited | Raffzahn | CC BY-SA 4.0 |
added 168 characters in body
|
Sep 27, 2021 at 14:54 | history | edited | Raffzahn | CC BY-SA 4.0 |
added 742 characters in body
|
Sep 27, 2021 at 14:48 | comment | added | Stephen Kitt | So the key is “No, it doesn't, as it works simply left to right. No look ahead and no backtracking. BASIC is intended to be a simple language. For usage as well for implementation.” Note that Atari BASIC has a few deviations from “standard” BASIC, so using that as an argument doesn’t work all that well — in particular, string handling ;-). (Atari BASIC doesn’t support lists of strings.) | |
Sep 27, 2021 at 14:38 | history | edited | Raffzahn | CC BY-SA 4.0 |
added 798 characters in body
|
Sep 27, 2021 at 14:27 | history | edited | Raffzahn | CC BY-SA 4.0 |
added 1515 characters in body
|
Sep 27, 2021 at 14:26 | comment | added | Stephen Kitt |
@WillisBlackburn so would it be accurate to say that the real question is “Why did BASIC v4 add string variables with a $ suffix?” (The first versions of BASIC didn’t have string variables, they were added in v4.)
|
|
Sep 27, 2021 at 14:13 | comment | added | Raffzahn | @WillisBlackburn But that's the whole point. BASIC is made to allow two different variables of different type with the same name. Further BASIC was made to be simple, no prior data definition, no look ahead for assignments or alike. It's to be simply interpreted left to right . | |
Sep 27, 2021 at 13:53 | comment | added | Willis Blackburn | I asked, why does BASIC need these variable name suffixes, and you answered, because it's BASIC. This answer begs the question, which isn't about why Atari BASIC chose to implement BASIC this way but rather why the language is defined this way. | |
Sep 27, 2021 at 13:37 | comment | added | Raffzahn |
@UncleBod some BASICs even allowed to explicite mark floats as A!
|
|
Sep 27, 2021 at 13:37 | history | edited | Raffzahn | CC BY-SA 4.0 |
deleted 70 characters in body
|
Sep 27, 2021 at 13:36 | comment | added | UncleBod | First BASIC I used even had three A: string, integer and float. (Ok, only the float was actually written A, the others where A¤ and A%). | |
Sep 27, 2021 at 13:26 | history | answered | Raffzahn | CC BY-SA 4.0 |