14 Replies - 12171 Views - Last Post: 26 December 2011 - 07:31 AM

#1 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10773
  • View blog
  • Posts: 40,122
  • Joined: 27-December 08

Week #46- Legacy Languages

Post icon  Posted 19 December 2010 - 07:00 PM

This week's challenge is a blast from the past with Legacy Language week.

While legacy languages are dying out, many organizations are still relying upon and maintaining software that is more than twenty years old, and written in languages like COBOL, ObjectPAL, FORTRAN, and even Visual Basic 5. So this week's challenge is to utilize one or more of your favorite legacy languages.

Resourecs:

Is This A Good Question/Topic? 1
  • +

Replies To: Week #46- Legacy Languages

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Week #46- Legacy Languages

Posted 20 December 2010 - 11:46 AM

I hate Pascal(even that it kinda looks like vb i cant stand begin and end blocks) but some say that Delphi is OOP Pascal. Do you think someone is still using Delphi

This post has been edited by NoBrain: 20 December 2010 - 11:47 AM

Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10773
  • View blog
  • Posts: 40,122
  • Joined: 27-December 08

Re: Week #46- Legacy Languages

Posted 20 December 2010 - 01:05 PM

I've split the legacy language discussion into a thread in the Corner Cubicle for more visibility. :)
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5901
  • View blog
  • Posts: 12,806
  • Joined: 16-October 07

Re: Week #46- Legacy Languages

Posted 20 December 2010 - 01:15 PM

Good call.

I'd still add BASIC with line numbers to that list. Programming before procedural programming is an entirely different ride.
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10773
  • View blog
  • Posts: 40,122
  • Joined: 27-December 08

Re: Week #46- Legacy Languages

Posted 20 December 2010 - 01:22 PM

All legacy languages are welcome. I just listed a few off the top of my head up there. :)
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2270
  • View blog
  • Posts: 9,496
  • Joined: 29-May 08

Re: Week #46- Legacy Languages

Posted 20 December 2010 - 06:41 PM

View Postbaavgai, on 20 December 2010 - 08:15 PM, said:

Good call.

I'd still add BASIC with line numbers to that list. Programming before procedural programming is an entirely different ride.


vb.net still allow you write line numbers if so wish. I've seen an example of vb.net that will run in QBASIC with a tweak. See here
Was This Post Helpful? 1
  • +
  • -

#7 Blueline  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 55
  • Joined: 18-December 10

Re: Week #46- Legacy Languages

Posted 21 December 2010 - 06:13 AM

View Postmacosxnerd101, on 19 December 2010 - 06:00 PM, said:

This week's challenge is a blast from the past with Legacy Language week.

While legacy languages are dying out, many organizations are still relying upon and maintaining software that is more than twenty years old, and written in languages like COBOL, ObjectPAL, FORTRAN, and even Visual Basic 5. So this week's challenge is to utilize one or more of your favorite legacy languages.

Resourecs:


How about some definitions of what a legacy language is? Java and C++ both came out around 1993 I believe. So does it mean if you started programming in 1995 then Java and C++ are legacy languages to you? ;)

I would propose categories based on generations of languages, or simple definitions of obsolete, legacy, and current languages, etc.

I'm interested in the history of programming and languages at least on IBM systems. If nobody else is interested I'll just shut up now ;)

This post has been edited by Blueline: 21 December 2010 - 06:17 AM

Was This Post Helpful? 0
  • +
  • -

#8 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Week #46- Legacy Languages

Posted 21 December 2010 - 06:29 AM

Legacy languages are languages that had their kick at the cat and have faded from the lime light. Languages like FORTRAN, COBOL, and Pascal are good examples. They are still used in one form or another but not near as much as Java and C++.
Was This Post Helpful? 0
  • +
  • -

#9 Blueline  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 55
  • Joined: 18-December 10

Re: Week #46- Legacy Languages

Posted 21 December 2010 - 06:40 AM

View PostSixOfEleven, on 21 December 2010 - 05:29 AM, said:

Legacy languages are languages that had their kick at the cat and have faded from the lime light. Languages like FORTRAN, COBOL, and Pascal are good examples. They are still used in one form or another but not near as much as Java and C++.


Yeah we've been over this, that's one opinion but what is it based on? Is there a definition or is it just your list v. my list?

FORTRAN and COBOL are being used for new development, they have active standards comittees and COBOL has the highest line count of any source language ever invented. Those two languages haven't faded at all. Pascal was never a production language, so it may be a good example of a language that's not being developed or deployed, etc.

"Legacy" should have a defined meaning, like I said. If it's just based on what the English word legacy means then it depends when you started coding. Legacy just means something passed down to you. If you start coding today then Python, Ruby, C# etc. are all legacy languages. So that is too loose of a definition at least for me.
Was This Post Helpful? 0
  • +
  • -

#10 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Week #46- Legacy Languages

Posted 21 December 2010 - 06:53 AM

Languages that you don't find in mainstream use. Yes, COBOL and FORTRAN are still used. They are not heard of much in mainstream use though. That is considered legacy. If you want to discuss what is legacy and what is not please do it in the thread in the corner cubicle and not here. That is not what this thread is about. It is about stepping outside of your comfort zone as a programmer and trying something new.
Was This Post Helpful? 2
  • +
  • -

#11 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5901
  • View blog
  • Posts: 12,806
  • Joined: 16-October 07

Re: Week #46- Legacy Languages

Posted 21 December 2010 - 07:01 AM

View PostAdamSpeight2008, on 20 December 2010 - 07:41 PM, said:

vb.net still allow you write line numbers if so wish.


It's not just the line numbers, it's the lack of evolution.

BASIC had some notable characteristics. It exists before "procedural" programming. Think about that. Parameters aren't even an option. Everything is global. The program is organized by convention and little else. The only way to get around is GOTO and GOSUB; the GOSUB being a poor man's procedure call and considered advanced. Some versions didn't have line continuation.

You wrote BASIC programs a line at a time. You could write code in any editor, regardless of how crippled. The line numbers allowed for the line by line construction of the program. In some cases the editor was too stupid to allow line editing and you simply wrote a line with the number of an existing one to replace it.

When you get rid of the line numbers, you usually trade them in for procedural design. Now you've simply made another procedural language with wonky syntax.

Looking at "legacy languages", I find very few that are truly dead. They've all evolved in various ways, rather than being dropped outright. OO Pascal! VB.NET. Visual Basic is not BASIC, it's QuickBASIC for Windows. QuickBASIC removes the need for line numbers and adds labels. It will ultimately parameterized SUBs and become a different beast entirely. They can call BASIC their ancestor, but they aren't BASIC.

The point is that BASIC forced a way of thinking. I don't know if it was good. It was actually a lot closer to assembly in many ways. It was also simple. Real simple. Limited vocabulary. Lack of massive function libraries. Simple. I honestly can't think of any modern equivalent.

BASIC with line numbers has as much relation to modern "Basic" languages as a turkey does to TRex.

This post has been edited by baavgai: 21 December 2010 - 07:02 AM

Was This Post Helpful? 0
  • +
  • -

#12 scalt  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 342
  • Joined: 22-November 07

Re: Week #46- Legacy Languages

Posted 21 December 2010 - 12:36 PM

View PostNoBrain, on 20 December 2010 - 10:46 AM, said:

I hate Pascal(even that it kinda looks like vb i cant stand begin and end blocks) but some say that Delphi is OOP Pascal. Do you think someone is still using Delphi


You'd be surprised....
Was This Post Helpful? 0
  • +
  • -

#13 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5901
  • View blog
  • Posts: 12,806
  • Joined: 16-October 07

Re: Week #46- Legacy Languages

Posted 01 January 2011 - 06:43 AM

Well, I offered BASIC with numbers as a good example. I suppose, to be fair...

First, the compiler, GW-BASIC. The early BASIC is pretty simple; IBM even put it on a chip. I thought I could find a free implementation easy enough. I was wrong. None of the candidates were close to right. One of the more popular that was in my distro repository, bwbasic, was crap.

I used DosBox and a copy of GW-BASIC. I don't know the legality of the copy I grabbed, but I've purchased it many times over and thrown out the floppies so I feel I'm solid moral ground. Same with the DOS 5.0 image I used.

My thought was to write something demonstrate the foibles of BASIC, but it didn't seem fun. I went with a board favorite, tic-tac-toe. It was educational. It just wrote it from scratch, much of it in the GW-BASIC environment itself. The numbers are in no particular order; just stream of consciousness. I actually tried to make it legible, but line numbers do tend to run together.

1000 REM Tic-Tac-Toe
1010 REM GW-BASIC
1020 REM Written 2011-01-01!
1030 REM Baavgai
1040 REM
1100 REM Globals - Note you can only call DIM once in BASIC
1110 DIM BOARD(9)
1120 DIM BOARD.TMP(9)
1130 PLAYER.NONE=0 : PLAYER.X=1 : PLAYER.O=2
1150 GOSUB 5000
1199 END
1200 REM ---------------------------------------------------
1201 REM Show Board
1210 P=0 : CLS
1220 GOSUB 1260 : PRINT "-----------"
1230 GOSUB 1260 : PRINT "-----------"
1240 GOSUB 1260 : PRINT : PRINT
1250 RETURN
1260 REM ---------------------------------------------------
1261 REM Show row
1270 GOSUB 1280 : PRINT ":"; : GOSUB 1280 : PRINT ":"; : GOSUB 1280 : PRINT : RETURN
1280 REM ---------------------------------------------------
1281 REM Show then inc IN(P)
1290 GOSUB 1300 : P=P+1 : RETURN
1300 REM ---------------------------------------------------
1301 REM Show Value IN(BOARD,P)
1310 IF BOARD(P)=PLAYER.X THEN PRINT " X "; : RETURN
1320 IF BOARD(P)=PLAYER.O THEN PRINT " O "; : RETURN
1330 PRINT USING " #";(P+1); : PRINT " "; : RETURN
2000 REM ---------------------------------------------------
2001 REM Check for win IN(BOARD,PLAYER), OUT(IS.WIN)
2005 IS.WIN = 0
2010 P1=0:P2=1:P3=2:GOSUB 2100:IF IS.WIN THEN RETURN
2020 P1=3:P2=4:P3=5:GOSUB 2100:IF IS.WIN THEN RETURN
2030 P1=6:P2=7:P3=8:GOSUB 2100:IF IS.WIN THEN RETURN
2040 P1=0:P2=3:P3=6:GOSUB 2100:IF IS.WIN THEN RETURN
2050 P1=1:P2=4:P3=7:GOSUB 2100:IF IS.WIN THEN RETURN
2060 P1=2:P2=5:P3=8:GOSUB 2100:IF IS.WIN THEN RETURN
2070 P1=0:P2=4:P3=8:GOSUB 2100:IF IS.WIN THEN RETURN
2080 P1=2:P2=4:P3=6:GOSUB 2100
2090 RETURN
2100 REM ---------------------------------------------------
2101 REM Check row for win IN(BOARD,PLAYER,P1,P2,P3), OUT(IS.WIN)
2110 IS.WIN = (BOARD(P1)=PLAYER) AND (BOARD(P2)=PLAYER) AND (BOARD(P3)=PLAYER)
2120 RETURN
2200 REM ---------------------------------------------------
2201 REM Player Move
2210 PRINT "Choose an open square for X"
2220 GOSUB 8000 : REM sets CHOICE 0-9
2230 IF CHOICE=0 THEN GOTO 2260
2240 CHOICE = CHOICE - 1
2250 IF BOARD(CHOICE)=PLAYER.NONE THEN GOTO 2300 : REM Escape
2260 PRINT CHOICE;" is not an option."
2270 GOTO 2220
2300 BOARD(CHOICE) = PLAYER.X
2310 PLAYER = PLAYER.X : GOSUB 2000
2390 RETURN
2400 REM ---------------------------------------------------
2401 REM Computer Move
2410 REM
2420 PLAYER = PLAYER.O : GOSUB 4000
2430 IF WIN.POS = -1 THEN GOTO 2440
2435 CHOICE = WIN.POS : IS.WIN = -1 : GOTO 2510
2440 PLAYER = PLAYER.X : GOSUB 4000
2450 IF WIN.POS <> -1 THEN CHOICE = WIN.POS : GOTO 2500
2460 FOR I=0 TO 8
2470 IF BOARD(I) = PLAYER.NONE THEN CHOICE = I : GOTO 2500
2480 NEXT I
2490 PRINT "Oops, nothing to do." : GOTO 2520
2500 WIN.POS = -1
2510 BOARD(CHOICE)=PLAYER.O
2520 RETURN
4000 REM ---------------------------------------------------
4001 REM Get win pos, IN(BOARD,PLAYER), OUT(WIN.POS) WIN.POS=-1 if not found
4010 WIN.POS = -1
4020 FOR I=0 TO 8 : BOARD.TMP(I) = BOARD(I) : NEXT I
4040 FOR I=0 TO 8
4050 IF BOARD(I) <> PLAYER.NONE THEN GOTO 4080
4060 BOARD(I) = PLAYER : GOSUB 2000 : BOARD(I) = PLAYER.NONE
4070 IF IS.WIN THEN WIN.POS = I : GOTO 4090
4080 NEXT I
4090 FOR I=0 TO 8 : BOARD(I) = BOARD.TMP(I) : NEXT I
4092 IS.WIN = 0
4095 RETURN
5000 REM ---------------------------------------------------
5001 REM Game Main
5010 FOR I=0 TO 8 : BOARD(I) = PLAYER.NONE : NEXT I
5020 IS.WIN=0 : MOVENUM=0
5030 GOSUB 1200 : REM Show Board
5040 IF IS.WIN THEN IF MOVENUM MOD 2 = 1 THEN GOTO 5072 ELSE GOTO 5074
5050 IF MOVENUM>8 THEN GOTO 5080 
5060 IF MOVENUM MOD 2 = 0 THEN GOSUB 2200 ELSE GOSUB 2400
5070 MOVENUM=MOVENUM+1 : GOTO 5030
5072 PRINT "Player wins." : GOTO 5090
5074 PRINT "Computer wins." : GOTO 5090
5080 IF NOT IS.WIN THEN PRINT "Tie game."
5090 RETURN
8000 REM ---------------------------------------------------
8001 REM Digit From User, return CHOICE
8010 A$=INKEY$
8020 IF LEN(A$)=0 THEN GOTO 8000
8030 A = ASC(A$) : IF A=27 THEN GOTO 9999
8040 CHOICE = A-ASC("0")
8045 REM PRINT "Choice="; CHOICE
8050 IF CHOICE>=0 AND CHOICE<=9 THEN GOTO 8080
8060 PRINT "Value must be between 0 and 9."
8070 GOTO 8000
8080 RETURN
9999 REM Done



One of the reasons I ditched bwbasic is that it couldn't handle the most fundamental of constructs. e.g.
5010 FOR I=0 TO 8 : BOARD(I) = PLAYER.NONE : NEXT I



In classic GW-BASIC: "the characters allowed in a variable name are letters, numbers, and the decimal point." So my decimal points in the name is to simply get around a name construction limititation. The editor will also upper case everything unless it's in quotes.

As I fiddled with this, I thought if I just had lables I wouldn't need line numbers. That, and some white space, would make for a much more legible program.

In generations after the BASIC above, line numbers disappear and lables are intruced for jump points. Along with a myriad of other innovations. GW-BASIC ships with MS-DOS prior to DOS 5.0. DOS 5.0 intruces QBasic, a subset of QuickBasic. QBasic can acutally run the above.

Or we can take the above and banish the line numbers.
REM Tic-Tac-Toe
REM QBASIC
REM Written 2011-01-01!
REM Baavgai

Entry:
	REM Globals - Note you can only call DIM once in BASIC
	DIM BOARD(9)
	DIM BOARD.TMP(9)
	PLAYER.NONE = 0: PLAYER.X = 1: PLAYER.O = 2
	GOSUB GameMain
	END

GameMain:
	FOR I = 0 TO 8: BOARD(I) = PLAYER.NONE: NEXT I
	IS.WIN = 0: MOVENUM = 0
GameMainLoop:
	GOSUB ShowBoard
	IF IS.WIN THEN IF MOVENUM MOD 2 = 1 THEN GOTO PlayerWins ELSE GOTO ComputerWins
	IF MOVENUM > 8 THEN GOTO TieGame
	IF MOVENUM MOD 2 = 0 THEN GOSUB PlayerMove ELSE GOSUB ComputerMove
	MOVENUM = MOVENUM + 1
	GOTO GameMainLoop
PlayerWins:
	PRINT "Player wins."
	GOTO GameMainEnd
ComputerWins:
	PRINT "Computer wins."
	GOTO GameMainEnd
TieGame:
	IF NOT IS.WIN THEN PRINT "Tie game."
GameMainEnd:
	RETURN

CheckForWin: REM IN(BOARD,PLAYER), OUT(IS.WIN)
	IS.WIN = 0
	P1 = 0: P2 = 1: P3 = 2: GOSUB CheckForWinRow: IF IS.WIN THEN GOTO CheckForWinExit
	P1 = 3: P2 = 4: P3 = 5: GOSUB CheckForWinRow: IF IS.WIN THEN GOTO CheckForWinExit
	P1 = 6: P2 = 7: P3 = 8: GOSUB CheckForWinRow: IF IS.WIN THEN GOTO CheckForWinExit
	P1 = 0: P2 = 3: P3 = 6: GOSUB CheckForWinRow: IF IS.WIN THEN GOTO CheckForWinExit
	P1 = 1: P2 = 4: P3 = 7: GOSUB CheckForWinRow: IF IS.WIN THEN GOTO CheckForWinExit
	P1 = 2: P2 = 5: P3 = 8: GOSUB CheckForWinRow: IF IS.WIN THEN GOTO CheckForWinExit
	P1 = 0: P2 = 4: P3 = 8: GOSUB CheckForWinRow: IF IS.WIN THEN GOTO CheckForWinExit
	P1 = 2: P2 = 4: P3 = 6: GOSUB CheckForWinRow
CheckForWinExit:
	RETURN
CheckForWinRow:
	IS.WIN = (BOARD(P1) = PLAYER) AND (BOARD(P2) = PLAYER) AND (BOARD(P3) = PLAYER)
	RETURN

PlayerMove:
	PRINT "Choose an open square for X"
PlayerMoveEntryTop:
	GOSUB GetDigit
	IF CHOICE = 0 THEN GOTO PlayerMoveBadEntry
	CHOICE = CHOICE - 1
	IF BOARD(CHOICE) = PLAYER.NONE THEN GOTO PlayerMoveExit
PlayerMoveBadEntry:
	PRINT CHOICE; " is not an option."
	GOTO PlayerMoveEntryTop
PlayerMoveExit:
	BOARD(CHOICE) = PLAYER.X
	PLAYER = PLAYER.X: GOSUB CheckForWin
	RETURN

ComputerMove:
	IS.WIN = -1
ComputerMoveSelfWin:
	PLAYER = PLAYER.O
	GOSUB GetWinPos
	IF WIN.POS = -1 THEN GOTO ComputerMoveOtherWin
	CHOICE = WIN.POS
	IS.WIN = -1
	GOTO ComputerMoveExit
ComputerMoveOtherWin:
	PLAYER = PLAYER.X
	GOSUB GetWinPos
	IF WIN.POS = -1 THEN GOTO ComputerMoveRandomPick
	CHOICE = WIN.POS
	GOTO ComputerMoveExit
ComputerMoveRandomPick:
	WIN.POS = -1
	FOR I = 0 TO 8
		IF BOARD(I) = PLAYER.NONE THEN CHOICE = I: GOTO ComputerMoveExit
	NEXT I
ComputerMoveLimbo:
	PRINT "Oops, nothing to do."
ComputerMoveExit:
	BOARD(CHOICE) = PLAYER.O
	RETURN

GetWinPos:
	WIN.POS = -1
	FOR I = 0 TO 8: BOARD.TMP(I) = BOARD(I): NEXT I
	I = 0
GetWinPosLoop1:
	IF BOARD(I) <> PLAYER.NONE THEN GOTO GetWinPosLoop1Next
	BOARD(I) = PLAYER
	GOSUB CheckForWin
	BOARD(I) = PLAYER.NONE
	IF NOT IS.WIN THEN GOTO GetWinPosLoop1Next
	WIN.POS = I
	GOTO GetWinPosExit
GetWinPosLoop1Next:
	I = I + 1
	IF I <= 8 THEN GOTO GetWinPosLoop1
GetWinPosExit:
	FOR I = 0 TO 8: BOARD(I) = BOARD.TMP(I): NEXT I
	IS.WIN = 0
	RETURN

GetDigit:
	A$ = INKEY$
	IF LEN(A$) = 0 THEN GOTO GetDigit
	A = ASC(A$): IF A = 27 THEN END
	CHOICE = A - ASC("0")
	IF CHOICE >= 0 AND CHOICE <= 9 THEN GOTO GetDigitEnd
	PRINT "Value must be between 0 and 9."
	GOTO GetDigit
GetDigitEnd:
	RETURN

ShowBoard:
	P = 0: CLS
	GOSUB ShowRow: PRINT "-----------"
	GOSUB ShowRow: PRINT "-----------"
	GOSUB ShowRow: PRINT : PRINT
	RETURN
ShowRow:
	GOSUB ShowValue: PRINT ":";
	GOSUB ShowValue: PRINT ":";
	GOSUB ShowValue: PRINT
	RETURN
ShowValue:
	IF BOARD(P) = PLAYER.X THEN PRINT " X "; : GOTO ShowValueEnd
	IF BOARD(P) = PLAYER.O THEN PRINT " O "; : GOTO ShowValueEnd
	PRINT USING " #"; (P + 1); : PRINT " "; : GOTO ShowValueEnd
ShowValueEnd:
	P = P + 1
	RETURN



I rather like the completely linear yet named aspect of the above. We haven't moved into truly structured programming yet.

Both of the above burnt me with the globals. Or, rather, the inherent complete lack of scope. Still, it was kind of fun.

To be fair to QBasic, it is the first recognizable ancestor of Visual Basic. It's also near identical to VBScript, which is really more QBScript.

Here is a more honest QBasic implementation of the above.
REM Tic-Tac-Toe
REM QBASIC
REM Written 2011-01-01!
REM Baavgai

REM Constants
PLAYER.NONE = 0
PLAYER.X = 1
PLAYER.O = 2

CALL GameMain
END

SUB BoardCopy (SRC(), DST())
	FOR I = 0 TO 8
		DST(I) = SRC(I)
	NEXT I
END SUB

FUNCTION ComputerMove (BOARD())
	SHARED PLAYER.NONE, PLAYER.X, PLAYER.O
	WinPos = GetWinPos(BOARD(), PLAYER.O)
	IF WinPos = -1 THEN WinPos = GetWinPos(BOARD(), PLAYER.X)
	IF WinPos = -1 THEN
		I = 0
		WHILE I < 9 AND WinPos = -1
			IF BOARD(I) = PLAYER.NONE THEN WinPos = I
			I = I + 1
		WEND
	END IF
	ComputerMove = WinPos
END FUNCTION

SUB GameMain
	SHARED PLAYER.NONE, PLAYER.X, PLAYER.O
	DIM BOARD(9)
	PLAYER = PlayGame(BOARD())
	CALL ShowBoard(BOARD())
	SELECT CASE PLAYER
		CASE PLAYER.X:
			PRINT "Player wins."
		CASE PLAYER.O:
			PRINT "Computer wins."
		CASE ELSE:
			PRINT "Tie game."
	END SELECT
END SUB

FUNCTION GetDigit
	N = -1
	WHILE (N = -1)
		A$ = INKEY$
		IF LEN(A$) <> 0 THEN
			N = ASC(A$)
			IF N = 27 THEN END
			N = N - ASC("0")
			IF N < 0 OR N > 9 THEN N = -1: PRINT "Value must be between 0 and 9."
		END IF
	WEND
	GetDigit = N
END FUNCTION

FUNCTION GetWinPos (BOARD.SRC(), PLAYER)
	DIM BOARD(9)
	CALL BoardCopy(BOARD.SRC(), BOARD())
	I = 0: WinPos = -1
	WHILE I < 9 AND WinPos = -1
		IF BOARD(I) = PLAYER.NONE THEN
			BOARD(I) = PLAYER
			IF IsWin(BOARD(), PLAYER) THEN
				WinPos = I
			ELSE
				BOARD(I) = PLAYER.NONE
			END IF
		END IF
		I = I + 1
	WEND
	REM PRINT "GetWinPos("; PLAYER; ") = " ; WinPos
	GetWinPos = WinPos
END FUNCTION

FUNCTION IsWin (B(), P)
	IsWin = IsWinRow(B(), P, 0, 1, 2) OR IsWinRow(B(), P, 3, 4, 5) OR IsWinRow(B(), P, 6, 7, 8) OR IsWinRow(B(), P, 0, 3, 6) OR IsWinRow(B(), P, 1, 4, 7) OR IsWinRow(B(), P, 2, 5, 8) OR IsWinRow(B(), P, 0, 4, 8) OR IsWinRow(B(), P, 2, 4, 6)
END FUNCTION

FUNCTION IsWinRow (BOARD(), PLAYER, P1, P2, P3)
	IsWinRow = (BOARD(P1) = PLAYER) AND (BOARD(P2) = PLAYER) AND (BOARD(P3) = PLAYER)
END FUNCTION

FUNCTION PlayerMove (BOARD())
	PRINT "Choose an open square for X"
	CHOICE = 0
	WHILE CHOICE = 0
		CHOICE = GetDigit
		IF CHOICE = 0 OR BOARD(CHOICE - 1) <> PLAYER.NONE THEN
			CHOICE = 0
			PRINT CHOICE; " is not an option."
		END IF
	WEND
	PlayerMove = CHOICE - 1
END FUNCTION

FUNCTION PlayGame (BOARD())
	SHARED PLAYER.NONE, PLAYER.X, PLAYER.O

	FOR I = 0 TO 8
		BOARD(I) = PLAYER.NONE
	NEXT I
	MOVENUM = 0: Winner = PLAYER.NONE
	WHILE MOVENUM < 9 AND Winner = PLAYER.NONE
		IF MOVENUM MOD 2 = 0 THEN
			CALL ShowBoard(BOARD())
			CHOICE = PlayerMove(BOARD())
			PLAYER = PLAYER.X
		ELSE
			CHOICE = ComputerMove(BOARD())
			PLAYER = PLAYER.O
		END IF
		BOARD(CHOICE) = PLAYER
		IF IsWin(BOARD(), PLAYER) THEN Winner = PLAYER
		MOVENUM = MOVENUM + 1
	WEND
	PlayGame = Winner
END FUNCTION

SUB ShowBoard (B())
	SHARED PLAYER.NONE, PLAYER.X, PLAYER.O
	P = 0: CLS
	FOR ROW = 1 TO 3
		FOR COL = 1 TO 3
			IF B(P) = PLAYER.X THEN
				PRINT " X ";
			ELSEIF B(P) = PLAYER.O THEN
				PRINT " O ";
			ELSE
				PRINT USING " #"; (P + 1);
				PRINT " ";
			END IF
			IF COL <> 3 THEN PRINT ":";
			P = P + 1
		NEXT COL
		PRINT
		IF ROW = 3 THEN PRINT  ELSE PRINT "-----------"
	NEXT ROW
	PRINT
END SUB



QBasic is still quirky. In it's attempt to avoid globals, it's made them even more difficult. The way it handles arrays isn't too elegant. There's no "Option Explicit." Strangely, there's no RETURN from SUB blocks. I got hurt by all of the above. It a strange way, the more primitive BASIC was easier. Having SUB, FUNCTION, and END IF makes for a drastically different design. I consciously excised all GOTO and GOSUB.

In "unstructured" BASIC, you must revel in GOTO and GOSUB without shame. I mean, they're what you have. It's messy, but simple. You must think logically and solve problems within the restrictions of the language.

While the GOSUB style of BASIC is pretty dead, it's simplicity keeps calling people back. Most recently, a startup is advocating teaching it to kids.

BASIC was my first language, along with anyone who played on computers at the dawn home computing. Teens and pre teens learned BASIC from things like magazine articles and dissecting simple programs that ran on their systems. While it might teach "bad habits", I believe it could probably still teach.
Was This Post Helpful? 2
  • +
  • -

#14 Rhymer  Icon User is offline

  • D.I.C Regular

Reputation: 23
  • View blog
  • Posts: 282
  • Joined: 21-April 09

Re: Week #46- Legacy Languages

Posted 24 March 2011 - 01:13 PM

I started programming on a TI-994A in early 80's. I bought a Tandy 1000 w/8088 cpu, 128K memory and CGA graphics.
I used Zbasic ™ for many years. It was very close to the original BASIC with some improvements. I just happen to have a zip file with some of my old programs. I hope I am using this thread correctly.
This one reads any file but is intended to fish out the string data listed in lines 90 and 100.
I really miss the utility of the DATA statement.


The entire program:
00010 REM by James Moomey 7/26/94
00020 REM DLL & DRV PEEKER
00030 DIM 16K$(12),250W$(12),250HOLD$(3)
00040 DEF TAB=8
00050 F$=COMMAND$:IF F$<>"" THEN 60
00060 PRINT "DLL or DRV filename:  ";:INPUT F$
00070 IF F$=CHR$(27) OR F$="" THEN END
00080 Z=INSTR(1,F$,"."):IF Z=0 THEN F$=F$+".dll":PRINT "DLL file assumed..."
00090 DATA "CompanyName"   ,"FileDescription" ,"FileVersion","InternalName"  ,"LegalCopyright"
00100 DATA "LegalTrademark","OriginalFilename","ProductName","ProductVersion","VarFileInfo","Translation"
00110 FOR I=1 TO 11:READ K$(I):NEXT
00120 ON ERROR GOSUB "noifile"
00130 OPEN "I",1,F$
00140 CLOSE
00150 GOTO 180
00160 "noifile"
00170 ERROR=0:PRINT "Cannot find ";F$;" in ";PATH$(0):RETURN 60
00180 ON ERROR GOSUB "eof"
00190 OPEN "R",1,F$,1
00200 PRINT "Searching..."
00210 READ #1,C$;1
00220 IF C$<>"C" THEN 210
00230 READ #1,C$;10
00240 IF C$<>"ompanyName" THEN 210
00250 READ #1,HOLD$(1);190:HOLD$(1)="C"+C$+HOLD$(1)
00260 READ #1,HOLD$(2);200 :READ #1,HOLD$(3);200
00270 CLOSE:HOLD$=""
00280 FOR J=1 TO 12:IF J=12 THEN 480
00290   LONG IF LEN(HOLD$)<101
00300     HOLD$=HOLD$+LEFT$(HOLD$(1),100)
00310     HOLD$(1)=MID$(HOLD$(1),101)+LEFT$(HOLD$(2),100)
00320     HOLD$(2)=MID$(HOLD$(2),101)+LEFT$(HOLD$(3),100)
00330     HOLD$(3)=MID$(HOLD$(3),101)
00340   END IF
00350   Z=INSTR(1,HOLD$,K$(J)):IF Z=0 THEN 470
00360   FOR K=J+1 TO 11
00370     Q=INSTR(Z+1,HOLD$,K$(K))
00380     LONG IF Q<>0
00390       S=Z+LEN(K$(J))+1:T=Q
00400       W$(J)=MID$(HOLD$,S,T-S)
00410       HOLD$=MID$(HOLD$,Q)
00420       FOR I=1 TO LEN(W$(J))
00422         Q$=MID$(W$(J),I):Q=ASC(Q$):IF Q<32 THEN W$(J)=LEFT$(W$(J),I-1)+MID$(W$(J),I+1):I=I-1
00430       NEXT
00440       GOTO 470
00450     END IF
00460   NEXT
00470 NEXT
00480 PRINT "File Snooper"
00490 PRINT "~~~~~~~~~~~~"
00500 PRINT "Company name     :  ";LEFT$(W$(1),59)
00510 PRINT "File Description :  ";LEFT$(W$(2),59)
00520 PRINT "File Version     :  ";LEFT$(W$(3),59)
00530 PRINT "Internal name    :  ";LEFT$(W$(4),59)
00540 PRINT "Legal Copyright  :  ";LEFT$(W$(5),59)
00550 PRINT "Legal Trademarks :  ";:Z=INSTR(1,W$(6),K$(6))
00552 LONG IF Z<>0
00554   TEMP$=LEFT$(W$(6),Z):PRINT LEFT$(TEMP$,59):W$(6)=MID$(W$(6),Z+15)
00556   PRINT "Legal Trademarks :  ";LEFT$(W$(6),59)
00557 XELSE
00558 PRINT LEFT$(W$(6),59)
00559 END IF
00560 PRINT "Original Filename:  ";LEFT$(W$(7),59)
00570 PRINT "Product Name     :  ";LEFT$(W$(8),59)
00580 PRINT "Product Version  :  ";LEFT$(W$(9),59)
00590 PRINT "Var File Name    :  ";LEFT$(W$(10),59)
00600 PRINT "Translation      :  ";LEFT$(W$(11),59)
00610 END
00620 "eof"
00630 ERROR=0:RETURN 270

Was This Post Helpful? 0
  • +
  • -

#15 111027  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 141
  • Joined: 26-December 11

Re: Week #46- Legacy Languages

Posted 26 December 2011 - 07:31 AM

I've done quite a bit of Pascal (pure Pascal, no objects, no pointers) in High School and i admit to liking it for its simplicity. Later on, i went to use it for a Tetris project (standard pascal), a mock compiler (heavily relying on inline assembly) and a car crash simulator (forensic level). Modern dialects like Oxygene really do own!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1