Comparing languages

new topic     » topic index » view thread      » older message » newer message

I'm still finding goodies buried in my new Linux system, including a lot of
compilers.
To get started learning them, I wrote this simple program in various languages
(skipping
perl, forth, and intercal!) The simularities and differences are kinda
interesting:

# Payroll program in Python - 8 lines
# (comments and blank lines not counted)

tax = 25.00
print 'Payroll in Python'
hours = input("Enter hours worked: ")
rate  = input("Enter hourly rate:  ")
gross = hours * rate
net = gross - tax
print 'Gross pay: %8.2f'%gross
print 'Net pay:   %8.2f'%net

/* Payroll program in C - 14 lines - compiles to 25K bytes */

#define TAX 25.00
float gross, net, hours, rate;

main()
{
 printf("Pay written in C\n");
 printf("Enter hours worked: ");
 scanf("%f",&hours);
 printf("Enter payrate:      ");
 scanf("%f",&rate);
 gross = hours * rate;
 net = gross - TAX;
 printf("Gross pay: %8.2f\n",gross);
 printf("Net pay:   %8.2f\n",net);
}

{ Payroll program in Pascal - 14 lines - compiles to 30K bytes}

program Payroll (Input, Output);

const tax = 25.00;

var hours, rate, gross, net : real;

begin
 writeln('Payroll in Pascal');
 write('Enter hours worked: ');
 readln(hours);
 write('Enter hourly pay:   ');
 readln(rate);
 gross := hours * rate;
 net := gross - tax;
 writeln('Gross pay: ', gross:10:2);
 writeln('Net pay:   ', net:10:2);
end.

10 REM Payroll program in BASIC - 8 lines
20 TAX = 25
30 PRINT"Payroll written in BASIC"
40 INPUT"Hours worked: ";HOURS
50 INPUT"Payrate:      ";RATE
60 GROSS = HOURS * RATE
70 NET = GROSS - TAX
80 PRINT"Gross pay:",GROSS     -- sorry, I can't remember the syntax for
PRINT USING
90 PRINT"Net pay:  ",NET

-- Payroll in Euphoria - 20 lines

include get.e -- Euphoria was the only language to require "outside support"
for this simple task.

constant TAX = 25.00
atom hours, rate, gross, net

function input(sequence prompt) -- note the hoops we have to jump thru to get
keyboard input.
object result
puts(1,prompt)
result = value(gets(0))
puts(1,"\n")
if result[1] = GET_SUCCESS then
   return result[2]
else return result[1]
end if
end function

puts(1,"Payroll in Euphoria\n")
hours = input("Enter hours worked: ")
rate  = input("Enter payrate:      ")
gross = hours * rate
net = gross - TAX
printf(1,"Gross pay: %8.2f\n",gross)
printf(1,"Net pay:   %8.2f\n",net)

Question: Euphoria knows hours has been defined as an atom | sequence | object.

Why cannot the next version of Euphoria include a proper built-in input()
function
which will handle these things better? It would make learning and using he
language a bit
easier.

Regards,
Irv

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu