The original BASIC programs were written on machines that did not have the kind of modern editors we are used to where you can go to an arbitrary line and insert new code there and automatically shift the rest of the program downward in the memory to make space for it.
Instead you would just have a ">" prompt and you would just write your program line by line, starting with the line number of each instruction. So maybe you begin by typing 1 PRINT "WELCOME TO ZETHMRDADJOKES COOL PROGRAM". (If you didn't put a line number first, it meant "execute this command now, it isn't part of the program I'm writing").
If you made a mistake on one line, you could rewrite the line easily by typing its line number, which would then replace the line. But there was no way to insert a new line, you couldn't have a non-integer line like 1.5 PRINT "COPYRIGHT ZETHMRDADJOKES 1972". So if you wanted something between lines 1 and 2, you just had to start writing your program again!
So a typical technique was to space your lines 10 apart. If you needed to add a new line of code between lines 10 and 20, you could just type 15 at the ">" and insert your new code there. (But oddly it was kind of frowned upon as a sign that you had screwed up. Next time think more carefully about your program before you start writing it on a computer.)
Later editors did get support for renumbering lines so you could add new code, and then even more advanced editors put the line numbers in for you. That was kind of cool.
Side note, (sorry to revive such an old thread) but network engineers still do this on routers and switches for Access Control Lists, VLANs, and other things. It's always good skip by 10 or so juuuuust in case you need to go back and add something down the line.
Also there's still a stigma where you should complete delete and recreate an ACL if you need to add something. Instead of just inserting a line 5, don't ask me why.
If you’re not doing math with numbers, it’s better to store them as a String, especially when doing something a numeric data type doesn’t support, like leading zeroes or number formatting.
I mean sprintf or the equivalents that are included in every modern programming language can do the same thing much easier, but I'm guessing whatever version of BASIC is shown there doesn't have a similar formatting function?
It's valid ANSI 1985 BASIC code (QuickBasic or QBasic, although the interface looks like GW-BASIC), but the show takes place in 1985, before any ANSI 1985 compliant interpreters existed.
Haha I don't know enough about BASIC to be able to tell, all I know is that like a hundred different variants of it exist. Though I wouldn't be surprised if they just made up some mashed up language just to make it more readable in the show.
It's probably slower than writing the exact characters you need directly, but I'd still prefer using the (hopefully) most correct and performant version of a string formatting function that's included in the standard library over rolling my own.
99% of the time when you need formatted strings, performance isn't an issue anyway. 10k passwords is no big deal even on ancient hardware, but yeah if you were dealing with much larger numbers it's definitely worth writing more optimized code.
Yeah, inside an array. And he is calling back the array, in Visual Basic (I know, not basic) it tells you the UBound. So this would print out 3 or just print {9,9,9,9} if he prints the array values.
I don't know if recursion would be faster. One of my professors said that some older programming languages couldn't handle recursion very well because of how they handle memory.
Likely due to tail-call optimization that exists in many functional languages. Without it you build a stack frame for every recursive call which is memory inefficient. BASIC does not have tail-call optimization. More here.
In computer science, a tail call is a subroutine call performed as the final action of a procedure. If a tail call might lead to the same subroutine being called again later in the call chain, the subroutine is said to be tail-recursive, which is a special case of recursion. Tail recursion (or tail-end recursion) is particularly useful, and often easy to handle in implementations.
Tail calls can be implemented without adding a new stack frame to the call stack.
This looks like it would work... if, of course, getFourDigits() and checkPasswordMatch would do what they say. I would assume getFourDigits() would do what u/irbinator said, and I assume checkPasswordMatch() would hash the calculated password and compare with the known correct hashed password.
Ah, good point. Well, it looks like the dude is carefully studying the code, so hopefully he’ll remember to add those in :) (or an include function (BASIC has an include statement, right?))
That and most interpreters tokenized the commands as they were entered. Any extra spaces were typically removed (or added in the case of Applesoft BASIC). Those tabs would not survive most 8-bit BASIC interpretations.
Not back then, anyway. I don't even remember seeing that in Turbo Pascal, in the late 80s. I think the first place I saw indents like that was C code in the early 90s.
Somebody else in the thread said lack of indents was to save bits in file and executable size, because the home machines I and others were using had so little capacity.
That wouldn't have worked in most 8-bit microcomputer implementations as the entered lines would be tokenized and stripped of extra spaces to save memory.
It depends on the dialect. There were BASICs with user-defined functions in '84. No idea if it's plausible that they would have been using one, though.
E: It looks like that's an IBM 3180 terminal. The would mean it's probably a System/38 minicomputer. IBM had a BASIC for the S/38 but I've had no luck finding any information about it. But I wouldn't be surprised if its BASIC had proper functions considering that the S/38 was about a hundred years ahead of its time.
There were earlier 'extended BASICs' with functions. The extended BASIC for Heathkit's PCs supported functions as early as '80 IIRC.
I found an old brochure that made it clear that S/38 BASIC was an extended dialect but didn't describe the extensions in detail. It's amazing how hard it is to find information about S/38.
OK, they are mixing ANSI 1978 BASIC with line numbers and ANSI 1985 BASIC which allowed for procedures and function calls. The latter version eliminated (well, at least deprecated) line numbers, so they would have been redundant and bad form. Adding to the confusion is the fact that this looks like IBM PC GW-BASIC or BASICA, which would not have supported the ANSI 1985 extensions. That function call would have thrown a big syntax error.
Those came later. QuickBasic, QBasic all had functions. The 1985 ANSI revision allowed for functions (and no more line numbers). By the time that was implemented, though, BASIC was mostly on the way out in terms of popularity.
My least favourite I saw in a friend’s program was “if True = True” followed by the code he wanted to run then “else: exit()” or something like that. Like wtf did he think that True would magically become false??
Did systems besides home micros even use BASIC? That bit's in a government lab. I'd be surprised of they weren't using UNIX. And if that's the case surely C would be more appropriate?
The line numbers aren’t exactly line numbers: they’re labels that happen to be integers that have to be in ascending order. You’re free to use whatever integers you want (within the limits of the system) as long as they’re ordered.
It was common practice to start numbering with multiples of, say, ten so you could go back and add lines without needing to fix the labels. That’s what they did in the screenshot.
652
u/Thranx Jul 04 '19
this might be the most ... plausible? ... thing I've seen on one of these. I mean... someone actually wrote that.
865
u/dark_mode_everything Jul 04 '19
Way cooler than doing for 0 to 9999
215
u/[deleted] Jul 04 '19
This looks like it would work... if, of course, getFourDigits() and checkPasswordMatch would do what they say. I would assume getFourDigits() would do what u/irbinator said, and I assume checkPasswordMatch() would hash the calculated password and compare with the known correct hashed password.
84
u/Redbird9346 Jul 04 '19
I have never seen a block of BASIC code that has indentations like that.
41
u/[deleted] Jul 04 '19
This could actually work, assuming getFourDigits() and checkPasswordMatch() are actual functions
60
u/cyberist Jul 04 '19
Should I teach you French while I'm at it, Jim?
18
u/lostwriter Jul 04 '19
Dammit. I didn’t know you could create user functions in BASIC. I wrote everything using GOSUB. I want to go kick 1984 me’s ass.
16
u/1512832 Jul 04 '19
Did they ever fix this?
7
u/[deleted] Jul 04 '19
I mean it works I guess
7
u/jessek Jul 04 '19
hahaha at tab indenting basic... there's a reason why that wasn't done when monitors were 80 characters wide
7
u/droid_mike Jul 04 '19 edited Jul 04 '19
OK, they are mixing ANSI 1978 BASIC with line numbers and ANSI 1985 BASIC which allowed for procedures and function calls. The latter version eliminated (well, at least deprecated) line numbers, so they would have been redundant and bad form. Adding to the confusion is the fact that this looks like IBM PC GW-BASIC or BASICA, which would not have supported the ANSI 1985 extensions. That function call would have thrown a big syntax error.
Yes, I am a nerd!
5
u/AliasUndercover Jul 04 '19
I just watched this one. I was so happy I knew what he was doing. I haven't used BASIC in decades.
5
u/akulowaty Jul 04 '19
I didn’t even know there was an implementation of basic with functions. All I ever had was c64 and cpc464 and they were pretty limited.
Also what a waste of memory with all these indents
5
u/aaron__ireland Jul 05 '19 edited Jul 05 '19
It's close but not quite right... here's what this program would've most likely looked like in 1984:
5 REM PASSWORD CHECKER ROUTINE
10 DIM PWD, P, FND
15 FND=0
20 FOR I=0 TO 9
30 FOR J=0 TO 9
40 FOR K=0 TO 9
50 FOR L=0 TO 9
55 P=L*1000+K*100+J*10+I
60 GOSUB 10000
70 IF FND=1 THEN GOTO 140
80 NEXT L
90 NEXT K
100 NEXT J
110 NEXT I
120 PRINT "NOT FOUND!"
130 END
140 REM PASSWORD FOUND
150 PRINT P
160 END
10000 REM GET PASSWORD MAGICALLY
10010 PWD=PEEK(&65536)
10020 IF PWD=P THEN FND=1
10030 RETURN
4
u/Bourriks Jul 05 '19
Intendation in a Basic program?
10
u/Robert_leroy Jul 04 '19
Line 140 PRINTS the wrong variable name.
11
u/irbinator Jul 04 '19
Hackerman.jpeg
3
u/[deleted] Jul 04 '19
Where is the checkPasswordMatch function?
3
u/continuum-hypothesis Jul 05 '19
Was camel case common in the 80's? I always imagine variables and functions usually using underscores.
3
u/GodIsDead_ Jul 05 '19
Bob didn't deserve that fucking ending
3
u/Woooferine Jul 05 '19
With interdimensional satanic bloodhounds roaming just outside the door, Bob still made sure the code was elegantly indented...
I miss you, Bob.
4
u/arcxjo Jul 04 '19
Use of GOTO considered harmful.
2
u/FotographicFrenchFry Jul 04 '19
Weirdly enough, watched this episode last night and was thinking of posting a screenshot of this scene to this sub lol
2
u/Le_swiss Jul 04 '19
I only see a X-fighter in ASCII art.
2
u/bamman527 Jul 04 '19
I love that i can read code
2
u/[deleted] Jul 04 '19
Please, don't write something like if(boolean==true), you already have a boolean variable...
2
u/shortAAPL Jul 05 '19
sha256 in shambles
2
u/eldare Jul 05 '19
Why lines numbers jump
2
u/[deleted] Jul 05 '19
I wonder if basic supports receive calls
2
u/sixStringedAstronaut Aug 26 '19
If i recall correctly calling functions was not available in BASIC in the early 80s when the show is set though right?
2
u/oneoftwentygoodmen Nov 03 '19
if password = unknown:
get_password()
1
u/GridBuilder Jul 04 '19
Yesss stranger things 3 is out!!!
1
u/Fzohseven Jul 05 '19
Heh, cool
1
u/[deleted] Jul 05 '19
You can crack anything with brute force*
1
u/louis99945 Jul 05 '19
I thought it was the South-African flag on first glance
1
u/extation Jul 05 '19
Don't you need to declare i,j,k,l in basic before using them in a for-loop?
1
u/CommonLawl Jul 05 '19
"
Press any key to continue"
1
u/Acsvf Jul 06 '19
The pseudocode I had to learn looks strangely like this... my teacher wasn’t kidding when he said it was based off of basic
1
u/[deleted] Jul 11 '19
Did systems besides home micros even use BASIC? That bit's in a government lab. I'd be surprised of they weren't using UNIX. And if that's the case surely C would be more appropriate?
1
u/Person112358 Jul 20 '19
It’s not that bad
1
u/SpeedTuberYT Aug 25 '19
Get fourdigits
1
u/[deleted] Dec 05 '19
is that an IBM? because most if not all IBMs didn't come with BASIC out of the box
0
u/Paid_Corporate_Shill Jul 05 '19
Never used BASIC before, do you have to find and fix all your ‘GOTO $line’s every time you insert something? That sounds awful
0
u/[deleted] Jul 04 '19
[deleted] — view deleted comment
0
u/[deleted] Jul 04 '19
[deleted] — view deleted comment