Showing posts with label pascal. Show all posts
Showing posts with label pascal. Show all posts

2007-02-26

What is taught in schools...

I discussed with my little sister her university programming tasks again. Even if to abstract from the maxim «Pascal is the best language for teaching» ™ IMHO still there are two important problems:

1 Something is told prematurely — the necessity of such solutions can be understood only conforted by the problem by oneself
2 Not the process of how somebody came to the idea of a solution it is told but the result only.

The separation to a file system and an on-line storage is not necessary, binary number notation was chosen because it is easy to implement; if you so need to bind a program into one big execution file beforehand then you will need the separate compilation for really large projects only.

The modules support in the language is not better than the simple agreement: «do not call functions with names start with xxx».

The knowledge of the result only forms one-sided view of things — it can be done in this way only... misunderstanding of why the result is exactly like this leads to non-using it where it is really needed.

Next time I'll summon my strength and try to explain what the procedures and functions are, what is the black box abstraction and so on.
For my sister has no doubts any more that to write the whole program inside one switch is not good.


Update One more interesting point have come to the surface — students visit lectures, study algebra, math logic, analytic and differential geometry. Teachers say: would you like a bonus? Write a program... find how many non-isomorphic graphs there are for the given number of edges and vertices or factorize a symmetric polynom to prime factors.

Oh... in Pascal? I'm curious how many lines of code a student will write until he stops to understand what sort of FL1, FL2 means, where RuntimeError 210 occurs and what is required to get at all?

2006-11-27

Emacs: Free pascal interaction

Hum... I googled, but have not found. Evidently, nobody was concerned with the problem of interaction emacs and fpc.

Well, I've readjusted what I can - highlight uses, support of compile errors messaging and the default compile-command.

;;Pascal mode
(require 'compile)
(pushnew '("^\\([a-zA-Z0-9\\.]+\\)(\\([0-9]+\\),\\([0-9]+\\))\s\\(.*$\\)" 1 2 3)
compilation-error-regexp-alist)
(defun pascal-mode-additional-init ()
(local-set-key "\C-c\C-c" 'compile)
(unless (or (file-exists-p "makefile")
(file-exists-p "Makefile"))
(set (make-local-variable 'compile-command)
(concat "fpc -g " buffer-file-name)))
(font-lock-add-keywords 'pascal-mode
'(("^[ \t]*\\(uses\\)\\>[ \t]*\\([a-z]\\)" 1 font-lock-keyword-face prepend))))


What should else I do so good?

2006-11-01

What is taught in schools...

Who said that Pascal is suitable language for the programming studying?

Well, about stack, heap, the difference between on-line storage, hard disk and above all why this separation is necessary I explained to my sister without a flub.

Took a time-out... I'm fussing about the syntax.

Such a doltish samples are given in books:
Type
vector = array[1..1000] of real;
p_vector = ^vector;

Var
a p_vector;

getmem(a,sizeof(vector));


Just an amazing possibility of declaring in the heap an array of fixed size.
Common sense waved me goodbye.

I had to dig in my old university programs.

Aha! To have a possibility of creation arrays of really beforehand unknown size a little trick is required:

row =  array[1..1] of real;


Little sister, have not you understood yet?

Look further:
Type
row = array[1..1] of real;
p_row = ^row;
Var
a p_row;
i integer;
Begin
getmem(a,10*sizeof(real));
for i := 1 to 10 do
a^[i] := i;
for i := 1 to 10 do
writeln(a^[i]);
End.


By declaring array of one element we deceive the compiler and later it allows us to refer to the array element by dereferencing the pointer.

Before this moment the inner organization of arrays was not very important for us but now the agreement that array elements are located close to each other has become critical.
Using it, we allocate memory for array with getmem function and calculate the size of the required piece just by multiplying the size of one element to their number. And we sure that the reference to an element number i is done by a^[i] expression.

Aha, and how many pupils spoiled by Pascal will guess how to create 2-D array, after all mentioned above?
Taking into account that the answer
row = array[1..1,1..1] of real;
is wrong?

I'm going to check my sister shrewdness.