Talk:C to Pascal

From Free Pascal wiki
Revision as of 00:12, 24 February 2016 by KevinLoughrey (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The wiki (http://wiki.freepascal.org/C_to_Pascal - which can be found here by pressing the 'page' tab above) makes a number of negative assertions regarding the usefulness of converting C Source Code into Pascal syntax and, when viewed in a narrow isolated, resigned context, most are valid.

This is not the case if you approach the matter of Pascal and C influenced by a different overarching view of computer science and the general philosophy regarding the role of source code.

Starting with the last first, the point of source code is to make it easy for a person to rapidly create executable code. Niklaus Wirth, the creator of Pascal, decided to take this idea to another level. He not only wanted people to be able to write code but also to write it with a minimum number of errors. So Pascal had a far stricter structure than, for example, BASIC. Wirth also wanted to have Source Code that was easy to read. Almost like a story. That's when things become interesting from a psychological perspective.

Verbose languages are hard for a person to remember. Make one small error in the long-winded statement and it will fail to run. COBOL is one such example. When you are punching out cards by hand to be read by a Hollerith reader, that can be really tedious.

Cryptic languages are also hard to remember and to read until you have become inured and expert in the syntax. This is because they bear only a slight resemblance to the English language; almost like a string of acronyms. When that happens, you don't so much read the code, but recognise patterns.

FORTRAN, Pascal and BASIC found that point of compromise where the language was not so cryptic as to be indecipherable to the novice and not so verbose as to require an encyclopedic memory. The Pascal syntax....

If NOT(A>B) then

 Begin
    doWork;
 End;

is a lot more readable to a novice than C syntax which would go something like this...

if (!(A>B))

{

 doWork;

}

There are many examples contrasting the syntax of Pascal with C where it is obvious that Pascal makes for much more readable code; especially to novices.

Why then didn't Pascal succeed over C? The answer can be found in the fact that Borland, the eventual owners of Turbo Pascal, and by far the most popular commercial implementation of the Pascal language, never ported the language to a UNIX platform. Simple as that. C filled a vacuum. There is no reason why Pascal can't run as fast as C for the simple reason that when they are compiled, the complier can be made to produce identical code. So it wasn't about performance. Turbo Pascal supported the "inline" reserved word where, if you were wanting to be truly adventurous, you could insert machine code. Some may say that Pascal didn't support this or that but the realities of a computer language is that it evolves just like a spoken one to accommodate new situations. Fundamentally, the language was sound. Indeed, Borland were one of the first to publish a commercial object oriented programming language that is now represented in the modern Free Pascal.

So why not admit that C has won, albeit, not because it is the best but because it is the default standard? Well that's where philosophy comes into it.

It is important for humanity that as many people as possible can write code. The more diversity, the more likely you are to have that once in a lifetime, history-changing idea surface.

The problem the computer science world now faces is that source code has become so cryptic and unfriendly that only those who have an aptitude and huge enthusiasm for computer science actually persevere long enough to become proficient in it. Some computer scientists like it that way. I've often heard the sentiment that idiots should not be allowed to write code. I've heard that criticism levelled particularly at PHP programmers. Some say PHP is too easy to use so a lot of code has been written by amateurs but has found it way onto some pretty important websites. In saying that, they overlook the role that an Integrated Development Environment(IDE) should play in the writing of code. A properly developed IDE has, built within it, numerous wizards that help a person write good code. Pascal, itself, because of its structure is helpful in making this a reality. An IDE can help you write code by completing reserved words or even constructs. This overcomes one of the objections C programmers have with Pascal. They don't like having to type those extra keystrokes. Easier to type a '{' and '}' than a 'Begin' and 'End'. In holding to that view, they don't worry that the curly brackets, once they are nested, are difficult for the human eye, particularly novices, to discern and give cause to many mistakes in C. Imagine for example, you are writing code and wish to create a new variable. The IDE can detect that you haven't before used this variable nor have you declared the variable. The IDE, at that point, asks you to define the variable and to provide a note as to the purpose of the variable. In that way, you are writing code and, at the same time, documenting it. In many modern programming languages, variables are created and disposed of "on the run". Eventually the code looks like a dysfunctional student's room. Litter everywhere! The IDE can also help you with things like whether the variable should be local or global. There are ways to help people write good code that are superior to excluding people of low expertise from "code creativity". It is in the interests of everyone and industry that as many people as possible get to participate in this activity as it is now fundamental to modern technology and society.

Some say that having lots of languages is good. That one language is better for this and another language is better for that. There is an argument that says languages should be functional, ie, a programmer is only able to modularise code by hiving it off into functions. Java takes obscurity to a new level by allowing programmers to have the same function name for two different functions; the only difference between the two is their argument list!! What were they thinking of??!! Case sensitivity is another example of how the inventors of some programming language have little regard for the needs of humans. Humans typically do not see 'Name' as being any different to 'NAME', but C and C-based languages like Java do. The justification for functional programming is to facilitate code portability. This is wrong. Code portability is facilitated through the use of classes not by imposing on programmers an artificial and restrictive program paradigm. The reality is Pascal superbly serves a wide range of application types. Having lots of languages, just like having lots of spoken languages in the world, is an overhead humanity carries. Different languages, or more precisely, the inability of one group to communicate freely with another has led to wars in the past. It would be far better for this world to speak only one language. That is likely to happen in the next 100 years or so with globalisation. Some people who like studying languages or make their living out of the fact there exist different languages are not happy with this trend. The same applies in computer science. There are those that actually delight in, and gain kudos from, the fact they have mastered a wide range of languages.

As I study web technology, I find there are a multitude of languages and frameworks and that nearly all do exactly the same thing. Some are more obvious and easier to learn than others but they all do the same thing in the end. I also often find they are incomplete and it seems to me that they are like that because there is not enough labour to go round. If everyone agreed on one syntax a lot more would be completed because a lot more labour could be focussed on the language's development. Having to learn them slows down development and, like spoken language, if you speak more than one language, chances are you are not expert in either. The brain can only handle so much. Although C is the dominant language where speed and compactness of code is desired, there has grown another language, also to fill a vacuum, and that is Python. Python started as a scripting language, that is, something you would write a batch file with. It's prime purpose was to call program modules written in C. As the years have gone by, this was not enough and so it has expanded to the point where we have a compiled Python and even Python, Jython, designed to work closely with Java and the Java Virtual Machine.

This neatly brings me to Java. When Pascal was used to teach the basics of computing to non-computer science courses at universities, the pass rate was around 70%. When Java, a language based on the syntax of C, was introduced the pass rate fell to around 40%. This tells you something. C and its young successor Java are not easy to learn. Indeed, some Java constructs make no sense to the novice at all and are vexing even to experienced programmers! If we are to have everyone contribute to computer science and to our industry, we have to make participation as easy as possible, particularly novices; not the reverse.

So, to get to the point, there is a need to have the means to rewrite (I think that is now the correct term) all C applications into Pascal. I'll go even further. Having mastered that, I would turn my attention to developing a tool to rewrite, Visual Basic, Python and Java applications into Pascal syntax as well. In doing that, there is a good probability we would find inadequacies in the present Free Pascal and these could be remedied during the process. What a wonderful world that would be if we could develop software to do this automatically and to error-check, optimise and document the code whilst it was performing the rewrite. Think also what a public relations coup it would be if, for example, you could convert the Linux kernel entirely into Pascal.

Using C headers, rather than rewriting the code, is just plain lazy. It not only avoids the challenge but it means people end up having to learn and use C (yuk!) and then learn Pascal. Eventually, they say, why bother with Pascal?!. When that happens, this website will disappear, all your work will have been in vain and a beautiful language will be relegated to the pages of history. I wouldn't want that. I would like there to be a lasting legacy from the work done within this great group of talented people.

If you're happy with C then you should not be here. Any suggestion that we Pascal programmers should use it and get used to it, is just plain disloyal. The posit it has won is defeatist. It hasn't won until Free Pascal is dead and it is far from that. The assertion that C is dominant because there are far more libraries available in C than Pascal fails to comprehend the whole point of rewriting C to Pascal. What if it were possible with a software tool to automatically take all of the C source code of all of those libraries and convert it into Pascal. What if, whilst doing that you not only rewrote the code but checked it for errors and vulnerabilities. What if you could do that same thing to Java, Python and Visual Basic. The argument that there are more C libraries than Pascal would be turned on its head. If ever there was a reason for concentrating on an artificially intelligent rewriting tool to convert code to Pascal, this is the one. I find it very, very exciting and believe a lot more would come out of such a project besides the unification of language. This project would advance humanity and human knowledge.

I'll leave you with these thoughts.

One of these days, if I live long enough, when I have the time, I plan on making a project of this and, if I have the resources, funding it. I particularly want to extinguish C and Java. I think both have held back humanity and, particularly, C has been the cause of many of the vulnerabilities that have been exploited by malicious code writers and criminals. It's time we did what is happening with human language and that is eventually evolve one language to be spoken by all. What a wonderful world it could be!