A r t i c l e s
Navigation

Note: This site is
a bit older, personal views
may have changed.

M a i n P a g e

D i r e c t o r y

Pascal Less Verbose Than C


Let's get one thing straight. C is not always terse.

The word terse means "short and to the point". C is not always terse. There is a difference between being obfuscated and being terse. Perl is sometimes terse and obfuscated. Pascal is readable, sometimes terse and sometimes too verbose. Being terse and readable is a good thing. Being terse and unreadable is a bad thing. Being verbose and unreadable is an extremely bad thing. C is unreadable and verbose many times! Look at the example below.


An age old example of using pointers in Pascal vs C. Which one is more verbose now?

The code in Pascal looks like this:

 program test;  

 var    
   myint: ^integer;  

 begin    
   new(myint);    
   myint^:= 10;    
   writeln(myint^);    
   dispose(myint);  
 end. 
The code in C looks like this:
 #include  
 
 void main()  

 {    

      int *myint; 
      myint = (int *) malloc (sizeof(int));    
      *myint = 10;    
      printf("%d\n",*myint);    
      free(myint);  

 } 

Both programs are 9 lines (not including whitespace). However, the actual code on each line is bizarre and verbose looking in the C example.

In the Pascal example, it is to the point and short. In the C example, it is verbose and obfuscated at the same time.

It is reasonable to be terse and readable. Normally one would consider being terse with being obfuscated. But this is not the case in C. In C, you happen to walk into many situations that are obfuscated and verbose - which means shooting yourself in the foot twice before you knew it.


And for all those programmers out there who think pascal is still too verbose...

Here is the example in Qompute Language:

 prog test;  

 v    
   i: ^int;  

 b    
   new(i);    
   i^ = 10;    
   outln(i^);    
   rid(i);  
 e. 


Now let's look at another example:

In Pascal, the code looks like this:

 program samp;  

 type    

   rec = record      
     i: integer;      
     f: real;      
     c: char;    
   end;  

 var    
   p: ^rec;  

 begin    
   new(p);    
   p^.i:= 10;    
   p^.f:= 3.14;    
   p^.c:= 'a';   
   writeln(p^.i, p^.f, p^.c);    
   dispose(p);  
 end. 
In C, the code looks like this:

 #include  

 struct rec 

 { 
     int i; 
     float f; 
     char c; 
 }; 
 

 void main() 

 { 
     struct rec *p; 
     p = (struct rec *) malloc (sizeof(struct rec)); 
     (*p).i = 10; 
     (*p).f = 3.14; 
     (*p).c = 'a'; 
     printf("%d %f %c\n", (*p).i, (*p).f, (*p).c); 
     free(p); 
 } 

Both programs are 17 lines long. But the C code block is verbose and obfuscated, while the pascal code block is to the point, obvious, and short.
In many cases, C is not terse - it is just obfuscated. Remember that terse is not the same as obfuscated.
Big note: I do not advocate Standard Pascal. I'm talking about modern Pascal which is completely different than standard Pascal. Modern Pascal maybe shouldn't even be called Pascal because it is more like Modula 2/delphi/oberon. Names are only names.

About
This site is about programming and other things.
_ _ _