我目前正在将一堆旧的GWBASIC代码重构成python,以便它可以在较新的机器上运行。它们都是旧的工程数学程序,数学很重,而且在整个过程中大量使用GOTO语句。
??
Snippet of code below:
25 INPUT "EXISTING FILE (Y/N)";EF$
30 IF EF$="Y" OR EF$="y" THEN 4000
40 LOCATE 4,1:PRINT USING "<######> NUMBER OF JOINTS";NON+1;:GOSUB 1400:IF D$="" THEN 50 ELSE NON=VAL (D$)-1
50 PRINT:PRINT USING "<######> NUMBER OF MEMBER GROUPS";MG+1;:GOSUB 1400:IF D$="" THEN 60 ELSE MG=VAL (D$)-1
60 PRINT:PRINT USING "<######> NUMBER OF MEMBERS";M+1;:GOSUB 1400:IF D$="" THEN 70 ELSE M=VAL (D$)-1
70 PRINT:PRINT USING "<######> NUMBER OF SUPPORTS";NS+1;:GOSUB 1400:IF D$="" THEN 75 ELSE NS=VAL (D$)-1
75 E=200000!:PRINT:PRINT USING "<#########> YOUNGS MODULUS (MPa)";E;:GOSUB 1400:IF D$="" THEN 80 ELSE E=VAL (D$)
80 TEC=.0000117:PRINT:PRINT USING "<##.##^^^^> THERMAL EXPANSION COEFFICIENT";TEC;:GOSUB 1400:IF D$="" THEN 90 ELSE TEC=VAL (D$)
90 GRAV=7850:PRINT:PRINT USING "<#########> MATERIAL DENSITY (kg/m^3)";GRAV;:GOSUB 1400:IF D$="" THEN 180 ELSE GRAV=VAL (D$)
180 DIM N(NON,1),MG(MG,1),M(M,3),ID(M,10),NC(NON,2),SD(NS,3),FE(M,5),R(5),C(5,5),E(5),T(5),SR(NS,2),LD(30,7),LN$(30),TE(M),MD$(MG)
190 F=-1:GOTO 200
195 CLS:F=-1:PRINT:PRINT USING "<###> JOINT NUMBER";F+2;:GOSUB 1410:IF D$="" THEN 200 ELSE F=VAL (D$)-2
200 CLS:PRINT:PRINT"JOINT DATA"
205 F=F+1:IF F>NON THEN 250
210 PRINT:PRINT"JOINT ";F+1;:PRINT TAB(15);:PRINT USING "<#######> X CO-ORD (mm)=";N(F,0)*1000!;:INPUT ;D$:IF D$="R" OR D$="r" THEN 1500
220 IF D$="" THEN 230 ELSE N(F,0)=VAL (D$)/1000
230 PRINT TAB(50);:PRINT USING "<#######> Y CO-ORD (mm)=";N(F,1)*1000!;:GOSUB 1410::IF D$="" THEN 240 ELSE N(F,1)=VAL (D$)/1000!
240 GOTO 205
250 IF FL=1 THEN 1500
290 F=-1:GOTO 300
最佳答案
My two cents:
从GOSUB语句开始并标识
实现函数(从不依赖于其他块的小函数开始)
为它编写一个python测试(基于所移植的gwbasic代码部分的预期/实际输出)
port function (gwbasic block identified in point 1) to Python
运行测试以检查是否通过/失败
这个想法是使用测试来证明新系统的行为与旧系统一样。
哦。
Reference:
paper on test-driven porting