On 4/17/2025 8:56 AM, Arne Vajhøj wrote:
On 4/17/2025 8:50 AM, Simon Clubley wrote:
On 2025-04-17, bill <bill.gunshannon@gmail.com> wrote:
On 4/16/2025 9:29 PM, Dan Cross wrote:
Most modern code-counting tools _are_ language aware. Whether
they do a better or worse job for each given language may be a
matter of debate, but most at least recognize different
languages and have some knowledge of their semantics.
>
I wonder how they would handle BASIC? :-)
>
10 FOR X = 1 TO 10
20 PRINT X
30 NEXT X
>
10 FOR X = 1 TO 10:PRINT X:NEXT X
>
Is the snippet above one line of code or three?
>
3 lines of code.
Other replies cover what the tools actually does.
If we discuss what is the "right" answer, then I would
actually say 2.
for i := 1 to 10 do writeln(i)
for i := 1 to 10 do
writeln(i)
for i := 1 to 10 do begin
writeln(i)
end;
for i := 1 to 10 do
begin
writeln(i)
end;
for(i = 1; i <= 10; i++) printf("%d\n", i);
for(i = 1; i <= 10; i++)
printf("%d\n", i);
for(i = 1; i <= 10; i++) {
printf("%d\n", i);
}
for(i = 1; i <= 10; i++)
{
printf("%d\n", i);
}
I would say 2 for all.
And unless Basic next has some subtle functionality I am not
aware of then I would say 2 for Basic as well.
Interesting concept. But the NEXT is a requirement of the
language, does take time to type and if it is left out does
require debugging to fix the problem. So, if we are counting
lines in some attempt to determine the cost of writing and
maintaining the program it seems it would have to count as
a line. If you are going to determine what constitutes a
valid line by comparing other languages then the whole thing
just become silly.
Sieve of Eratosthenes
APL:
sieve2←{
b←⍵⍴1
b[⍳2⌊⍵]←0
2≥⍵:b
p←{⍵/⍳⍴⍵}∇⌈⍵*0.5
m←1+⌊(⍵-1+p×p)÷p
b ⊣ p {b[⍺×⍺+⍳⍵]←0}¨ m
}
COBOL:
IDENTIFICATION DIVISION.
PROGRAM-ID. Sieve-Of-Eratosthenes.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Max-Number USAGE UNSIGNED-INT.
01 Max-Prime USAGE UNSIGNED-INT.
01 Num-Group.
03 Num-Table PIC X VALUE "P"
OCCURS 1 TO 10000000 TIMES DEPENDING ON Max-Number
INDEXED BY Num-Index.
88 Is-Prime VALUE "P" FALSE "N".
01 Current-Prime USAGE UNSIGNED-INT.
01 I USAGE UNSIGNED-INT.
PROCEDURE DIVISION.
DISPLAY "Enter the limit: " WITH NO ADVANCING
ACCEPT Max-Number
DIVIDE Max-Number BY 2 GIVING Max-Prime
* *> Set Is-Prime of all non-prime numbers to false.
SET Is-Prime (1) TO FALSE
PERFORM UNTIL Max-Prime < Current-Prime
* *> Set current-prime to next prime.
ADD 1 TO Current-Prime
PERFORM VARYING Num-Index FROM Current-Prime BY 1
UNTIL Is-Prime (Num-Index)
END-PERFORM
MOVE Num-Index TO Current-Prime
* *> Set Is-Prime of all multiples of current-prime to
* *> false, starting from current-prime sqaured.
COMPUTE Num-Index = Current-Prime ** 2
PERFORM UNTIL Max-Number < Num-Index
SET Is-Prime (Num-Index) TO FALSE
SET Num-Index UP BY Current-Prime
END-PERFORM
END-PERFORM
* *> Display the prime numbers.
PERFORM VARYING Num-Index FROM 1 BY 1
UNTIL Max-Number < Num-Index
IF Is-Prime (Num-Index)
DISPLAY Num-Index
END-IF
END-PERFORM
GOBACK
.
PL/M:
100H:
DECLARE PRIME$MAX LITERALLY '5000';
/* CREATE SIEVE OF GIVEN SIZE */
MAKE$SIEVE: PROCEDURE(START, SIZE);
DECLARE (START, SIZE, M, N) ADDRESS;
DECLARE PRIME BASED START BYTE;
PRIME(0)=0; /* 0 AND 1 ARE NOT PRIMES */
PRIME(1)=0;
DO N=2 TO SIZE;
PRIME(N)=1; /* ASSUME ALL OTHERS ARE PRIME AT BEGINNING */
END;
DO N=2 TO SIZE;
IF PRIME(N) THEN DO; /* IF A NUMBER IS PRIME... */
DO M=N*N TO SIZE BY N;
PRIME(M) = 0; /* THEN ITS MULTIPLES ARE NOT */
END;
END;
END;
END MAKE$SIEVE;
/* CP/M CALLS */
BDOS: PROCEDURE(FUNC, ARG);
DECLARE FUNC BYTE, ARG ADDRESS;
GO TO 5;
END BDOS;
DECLARE BDOS$EXIT LITERALLY '0',
BDOS$PRINT LITERALLY '9';
/* PRINT A 16-BIT NUMBER */
PRINT$NUMBER: PROCEDURE(N);
DECLARE (N, P) ADDRESS;
DECLARE S (8) BYTE INITIAL ('.....',10,13,'$');
DECLARE C BASED P BYTE;
P = .S(5);
DIGIT:
P = P - 1;
C = (N MOD 10) + '0';
N = N / 10;
IF N > 0 THEN GO TO DIGIT;
CALL BDOS(BDOS$PRINT, P);
END PRINT$NUMBER;
/* PRINT ALL PRIMES UP TO N */
PRINT$PRIMES: PROCEDURE(N, SIEVE);
DECLARE (I, N, SIEVE) ADDRESS;
DECLARE PRIME BASED SIEVE BYTE;
CALL MAKE$SIEVE(SIEVE, N);
DO I = 2 TO N;
IF PRIME(I) THEN CALL PRINT$NUMBER(I);
END;
END PRINT$PRIMES;
CALL PRINT$PRIMES(PRIME$MAX, .MEMORY);
CALL BDOS(BDOS$EXIT, 0);
EOF
bill