Forum > Suggestions

Subforum about converting libraries from other languages

<< < (2/2)

My apologies to ArNy, "the Turbo Rascal", for putting this suggestion in the wrong place in the forum. :(  I couldn't find any "How to" so I just jumped in :o.  I am totally new to this and so didn't know how to use this forum.  I will seek some advice from a colleague who is much better at these things than I!.  (Hope he doesn't get too exasperated. %))

It's nice to see some comment coming back.  I appreciate the points of view expressed but worry that some comments touch on complex subjects that would involve us in long and unsatisfying debate.

Some think this would be a difficult task and more than a few think it would be pointless.  I take a different view.  I think it would be a very interesting adventure taking encouragement from these words:
"Nonetheless, we have been able to grow enthusiastic over our vision of these unconvincing exercises. We have put ourselves to work for the sake of an idea, seeking by magnificent exertions to arrive at the incredible. And in the end, we have arrived there. Beyond all doubt, it is one of the vital sources of human capability that we are able to kindle enthusiasm from the mere glimmer of something improbable, difficult, and remote
~ José Ortega y Gasset"

Here's a thought (possibly a mad one!) Let's take the C source code of the Linux kernel and, by parsing the source, turn it into the equivalent Free Pascal source code.  Think what an impact that would make on the world of Computing Science and those that are so enamoured of C and so disparaging of Free Pascal!

So, ArNy, I'd be very happy to do the right thing and put this in the right place in this forum.  I just need a little coaching as to how I do that as this is my first time in such a forum.  Sorry for causing any irritation. 

Personally, I'd be ecstatic if we could have "Converting the Source Code of other Languages to FP", or whatever would be the correct title, as a separate main heading for this forum and see how many enthusiasts could be attracted to this endeavour.  If it were to gain traction, I think it would do a lot to promote Free Pascal as a viable, modern, multi-platform programming language; helping Lazarus once again rise up!


--- Quote from: marcov on September 16, 2012, 05:37:07 pm ---FPC/Delphi can access plain C headers by only translating the headers (which can be done semi automated). It can interface COM/activeX controls too. (one of the avenues used to communicate between VB and VSC++), which can be used as a bridge to .NET and C++ libs.

--- End quote ---
... which brings me to one of my hobby horses: SWIG.
SWIG lets other language use C++ object-oriented code.
Stefano Moratto apparently wrote a Delphi unit for that although it was not finished. I just wrote him an email asking for details.

Why reinvent the wheel by translating code from other languages if we can easily use proven code from within Object Pascal?

As for starting another forum section to get traction for doing this: I think leading by example is the only way people get attracted (yes, me asking people to help finish a SWIG module is a bit ironic in that context.)

If you could do a one-to-one conversion from C to Pascal, the code would be as ugly as C, or actually worse.
It would not look like modern Object Pascal at all.

Besides, there are many (Object) Pascal libraries out there. Which library you are missing?
I bet someone will come up with a solution if you have a detailed problem.
It is true that for a specific problem you may find 100 C solutions but only 10 Pascal solutions. It should still be enough if you only need one.

... And please calm down. Your ecstatic feelings will go away after you have actually converted some big C-libraries (or Linux kernel).
So please just do it and tell us how it was.


I've deliberately waited a few weeks before coming back to write another post on this subject.  I'm heartened that over 500 people have visited this post to read my suggestion and the comments of my respondents.

I'd like to put a few random thoughts out there for those that are interested to digest.

The first relates to the recreational sport of snow skiing. One thing that has always impressed me about that industry is the effort they expend on beginners.  We, in the world of computing science, could learn from that.  Without beginners there is no future.  I've seen many clubs and associations that come to be dominated by long-time members and they atrophy and eventually cease to exist.  So we should try to help beginners.

The second relates to the game of squash.  It managed to be popular for quite a time even though it had to compete against tennis for membership because it was a game that even beginners could derive some enjoyment from.  After all, the ball can't go very far.  It has to remain somewhere within those four walls and the people designing squash obligingly provided beginners with balls that bounce well and so are easy to play with.

The third relates to diversity.  Without diversity you don't really have an effective team.  If your team is comprised of only one type of person, chances are it is going nowhere.  That's why generally large corporations eventually wither and disappear, like those clubs I mentioned.  The selection and promotion systems in large organisations more or less guarantee that all of the top management will be clones.  That's why the military, without National Service (the "Draft"), is such a desert when it comes to new ideas.

The fourth relates to source code and computer languages generally.  Source code was invented to make it easy for people to read and write programs.  Unfortunately, as those participants became expert in the art (and to some extent lazy), they liked cryptic constructs which they instantly recognised but which were a mystery and torment to newcomers.  Some of these people graduated to writing new programming languages such as Java.  And so we get back to snow skiing and squash, if you make it hard for people to learn and use a programming language they will soon move on to more rewarding pursuits.  You will be left only with those who have had a long-time involvement (the old club members!) or a particular affinity for programming (Asperger personality types) or the people who have few options and are unusually persistent. (OCD).  Whatever, you end up with a team that has little variation.  Not only does it not do well, it is ripe for exploitation by others.

The last of these series of thoughts relates to language and to Maths.  Mathematics went into overdrive when the Arabic numeral set was adopted.  Can you imagine doing long division or square roots with Roman Numerals?  Western culture drove past the Chinese even though the Chinese had a huge head-start on the Europeans 3,000years ago.  The reason for this was both language and writing.  The Western languages are made up of words that are comprised of prefixes, roots and suffixes.  This made is easier for people to remember or construct words as they needed to.  Chinese does not have this construct.  Indeed, Chinese as a language is memory intensive and crude.  Western languages have a phonetic alphabet (except for the French bless them!! :( They delight in having letters in words that are not pronounced!!)  With phonetically spelt words it is possible to guess how to say a word.  In Chinese, if you don't know the ideogram, you don't know what the person is trying to tell you.  Mankind has advanced largely through the sharing of knowledge.  Chinese doesn't aid in this and that's why Chinese culture stagnated; as did other societies similarly encumbered.  The point I'm making here is that if you chose a programming language that is difficult to learn and difficult to remember, you are placing an obstacle in the path of innovation and participation.  Source code should be obvious and easy to follow; even for beginners.  Language can make all the difference between radically rapid progress and plodding advancement by the determined and dedicated.

I have a nephew who recently was granted a PhD in Chemistry.  He's brilliantly mercurial.  In his degree course, he had to study Java and was close to failing (and tears).  When I looked into the matter, I found out that the pass rate at his university had slipped from ~70% when they were teaching Pascal to around 40% when they transitioned to Java.  This is a little like going from classes in English to Chinese!

I've always regarded C as a bastard language and given that Java has a lot in common, you can guess where I place it in the pecking order of things.  C's genesis was from two chaps who wanted to play a game on a computer and they didn't want to write in Assembly.  It is a language with a syntax designed for situations where you have 16k of core memory (if you are lucky).  That's why "not" is abbreviated to "!".  That's why you don't find anything as verbose as Begin and End in C syntax.

Turbo Pascal was a revolutionary advancement when it happened.  Here was a language beginners could learn.  It compiled in a flash and so was comparable to writing in Basic with an interpreter.  It had an editor that tried to help you write code and as it developed you were able to trace program execution and have breakpoints, etc.  It was so much more friendly than C yet it executed at comparable speeds and was compact as an object executable.

In my career, I have learnt FORTRAN IV (and later 77), have dabbled in C, done a lot of programming in Wang Basic, then advanced COBOL, then Turbo Pascal, then Visual Basic and latterly Java with some hope of finding the time and energy to one day learn Scala if time permits.  When I look back on my life, I think of the months, possibly years, of my life I have wasted learning all these different languages to effectively do the same thing.

This leads me to the conclusion of this piece.  Why bother with FPC and Lazarus?  Why don't we give up on this and go and learn Java, Python and Scala?  Well if you think that, maybe you should.  I think what's been done here is magnificent.  I would like the whole world to join in and start using this language and this IDE.  I would like as many diverse personality types to participate in the future development of this language and the programming environment so that it is a living thing; constantly developing and getting better, friendlier, more powerful and more versatile.

One part of this, has to be to swallow up the other mainstream languages such that people, like my unimaginative colleagues, can't say that there is more support in this and that.  I want to see FPC and Lazarus being taught in Schools and Universities.  If you don't feel this then I genuinely would like to know why you are here.  I'd like to know why the people who have built Lazarus have persisted despite the geese, all around them, cackling that it was a waste of time because there were perfectly adequate programming languages already well established and available.  The fact is, Lazarus has the potential to be the best.  I would love to see it succeed and develop far beyond what it presently is.

Yes, programmatically converting code from one language to another is challenging but it is no more challenging than, say, writing a compiler.  Done properly, the code would be easy to read and optimised.  Provision could be made, for example, for variable names to be easily changed to be more obvious through a translation table; making the code easier to follow if necessary.  I think amongst the membership of this forum there are people who have the knowledge and the skill to make this happen.  Providing the means by which FPC can interoperate with other languages (such as reading C headers), as suggested by some, constitutes progress but it is not everything.  In many ways, it is a compromise, a further complication.

I hope by writing this, I have stimulated the imagination of some that will come to this page and participate in this forum.  I look forward to the day when I can finance the development of a code translator and better support the Lazarus project.

I also hope you enjoyed reading this as much as I have enjoyed writing it! :D

So you're saying:
1. FPC+Lazarus is easy to learn and it should be kept that way.
2. We should need to do automatic translation of code in other languages.
3. FPC+Lazarus should take over the world.

I agree with 1+3, but don't see how 2 especially contributes to 3. But to each his own.

BTW, I found the SWIG Delphi module that could be extended to automatically (! ;) ) generated object-oriented Pascal bindings for C++ code.,18631.msg105353.html#msg105353
That would allow us FPC people to build on the slow laborious error prone work of C++ programmers - who nevertheless often deliver quite nice functionality.

Of course, if anybody wants to translate say C++ code to Object Pascal native code, I won't stop them...


[0] Message Index

[*] Previous page

Go to full version