Recent

Author Topic: Subforum about converting libraries from other languages  (Read 11389 times)

Kalaco

  • Newbie
  • Posts: 3
Subforum about converting libraries from other languages
« on: September 15, 2012, 07:41:19 am »
I have been waiting for years for Lazarus to reach this stage and I am very, very impressed with, and thankful for, the work of the people involved.  I think they have done the world a great service through these efforts.  (See http://www.nvtech.com.au/Index/index-Project_Nicaea.html for an insight as to why work such as this is so important.)

On hearing the news about Lazarus 1.0 being issued, I spoke to one of my co-developers about converting the work we have done across to Free Pascal (Lazarus) and doing future work in this language and development environment as well as contributing wherever we could to this effort, either through our work or by donation.

His response was entirely negative.   One of his main reasons for not adopting Lazarus was that there was much more material in the way of existing applications and libraries in Java, C, Python and Visual Basic than there is for applications using a programming language with Pascal-like syntax.  He also pointed to the fact that Pascal programmers are a diminishing population and finding programmers in the future would be problematic.

I believe that, of all the programming languages, Pascal achieves the best compromise between rigour and ease of use.  Additionally, Free Pascal, as a compiled language, achieves speed and compactness comparable to C yet it is much easier for beginners, especially, to work in.  This means that applications written in this environment will run faster on lower-power machines; making them suitable for developing countries and for 1st world commerce in general.

As a way of countering the objections raised by my colleagues, I believe that there would be merit in encouraging investigation into ways by which it could be possible to take C, Java, Visual Basic and Python source code and convert it into Free Pascal.  Imagine for example, the effect of all of those various libraries being available to Free Pascal programmers.  Imagine also how much more simple the world would be if there were fewer programming languages without losing power or capabilities in the process.

For that reason, as a starting point, I would like to suggest that there be a separate section for discussion on this topic in this forum.  It would be interesting to see if we could start a project to convert the source code of these various languages into Free Pascal.  In doing this, there is every possibility, in some instances, of Free Pascal being found wanting.  When/if that should happen, suggestions could be made to the Free Pascal project to extend the language in order to cover any validated deficiency.

I'd be very grateful for the thoughts and opinions of the membership of this forum on this matter.

With best wishes to all

Kalaco

TurboRascal

  • Hero Member
  • *****
  • Posts: 672
  • "Good sysadmin. Bad programmer."™
Re: Subforum about converting libraries from other languages
« Reply #1 on: September 15, 2012, 09:40:46 pm »
@Kalaco, your input is appreciated, but you should have posted it in the Suggestions subforum, not here in a sticky notification thread...
Regards, ArNy the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Subforum about converting libraries from other languages
« Reply #2 on: September 16, 2012, 03:20:39 am »
TurboRascal: I agree. Topic split.

Kalaco: It usually works the other way around. First there is some discussion
(I'd suggest "Packages and Libraries" and "Third party" subforums).
Then, if enough interest exists, a separate subforum may be created.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Subforum about converting libraries from other languages
« Reply #3 on: September 16, 2012, 05:37:07 pm »
His response was entirely negative.   One of his main reasons for not adopting Lazarus was that there was much more material in the way of existing applications and libraries in Java, C, Python and Visual Basic than there is for applications using a programming language with Pascal-like syntax. 

I think that is a bit of a knee jerk reaction. The fact that those languages are all used for different things (Java :serverside and only a bit on the desktop ERP clients, Python: serverside on *nix, VB Classic: desktop, but even more dying than Pascal is.) says enough. The main contender (C#) is even missing from the list.

That brings us to the strong points of Delphi/Lazarus : creating relative standalone clients (mostly for Database use), usually done by smaller companies.
Because these companies are small, they can't dictate deployment options (read: runtimes and -versions) to their customers, but have to accomodate.

Another big area is the so called small programming. Small inhouse utility apps. I can't walk into a customers IT or engineering department without finding a Delphi 6 or 7E license for that. Small DB apps,
often with hardware connectivity. (e.g. scanners). Not Java, not Python, not VB, but Delphi. nine times out of ten.  The zero deployment requirements and the easy and productive designer, combined with a lot of third party source is one of the main reasons.

Quote
He also pointed to the fact that Pascal programmers are a diminishing population and finding programmers in the future would be problematic.

Another typical knee-jerk remark. While the first part is true,  the second IMHO is not. It is easier to turn a C++ programmer into a Delphi programmer than
moving a VB or Java programmer to something else. In my previous job we usually advertise for Java/C++ programmers with a certain relevant skillset. The C++
ones generally worked out better than the Java ones. Even after preselection. Of course they would whine about Delphi being the problem forever, but they would
get things done. Some even learned to like it :)

Quote
As a way of countering the objections raised by my colleagues, I believe that there would be merit in encouraging investigation into ways by which it could be possible to take C, Java, Visual Basic and Python source code and convert it into Free Pascal.  Imagine for example, the effect of all of those various libraries being available to Free Pascal programmers.  Imagine also how much more simple the world would be if there were fewer programming languages without losing power or capabilities in the process.

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.

Classic VB is mostly dead Python is irrelevant on Windows.

And no, general source to source code translation is hard, very hard.  Forget about it for most realistic scenarios.

 

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Subforum about converting libraries from other languages
« Reply #4 on: September 16, 2012, 06:46:02 pm »
Python is irrelevant on Windows.

The many GIS professionals who use Python in their Windows work might differ with you on that. Whether they're using an open-source GIS like QGIS or SAGA on Windows:

http://www.qgis.org/pyqgis-cookbook/

http://sourceforge.net/apps/trac/saga-gis/wiki/The%20Philosophy%20of%20SAGA

Or the MS Office of the GIS world, ArcGIS:

http://video.esri.com/tag/12/python

One thing is common: Python. And not on the server either.

Python is often selected whenever a cross-platform scripting language is used. For example, the qooxdoo JavaScript framework's entire tool set is written in Python:

http://manual.qooxdoo.org/current/pages/tool/sdk_requirements.html

Again, desktop tools, not server tools.


It looks to me like the language landscape is diversifying. For example, within the last few months we've seen not one but two commercial tools that translate Object Pascal to JavaScript. And this week info emerged about RemObject's "Nougat" Pascal language, with extensions for working with the Objective-C runtime (notably following FPC's own ObjC extensions by about 2 years).

If true, why is this happening? I believe it's related to more general trends initiated with the introduction of the iPhone and the subsequent success of the App Store: rejuvenation of traditional compiled languages like Objective-C, a longtime niche language, and an interruption of the slow drift to .NET-ness. It might even track the larger platform shifts going on:

http://www.businessinsider.com/wintel-monopoly-2012-9

And no, general source to source code translation is hard, very hard.  Forget about it for most realistic scenarios.

Instead, focus on using multiple languages cooperatively, eg, Pascal with .NET or Python:

http://wiki.lazarus.freepascal.org/Using_Pascal_Libraries_with_.NET_and_Mono

http://wiki.lazarus.freepascal.org/Developing_Python_Modules_with_Pascal

Thanks.

-Phil


Kalaco

  • Newbie
  • Posts: 3
Re: Subforum - Converting the Source Code of other languages into Free Pascal
« Reply #5 on: September 22, 2012, 04:00:16 am »
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!

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Subforum about converting libraries from other languages
« Reply #6 on: September 22, 2012, 09:20:56 am »
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.
... which brings me to one of my hobby horses: SWIG.
SWIG lets other language use C++ object-oriented code.
http://www.swig.org/exec.html
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.)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Subforum about converting libraries from other languages
« Reply #7 on: September 22, 2012, 09:26:48 am »
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.

Regards,
Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Kalaco

  • Newbie
  • Posts: 3
Re: Subforum about converting libraries from other languages
« Reply #8 on: October 03, 2012, 09:47:05 am »
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

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Subforum about converting libraries from other languages
« Reply #9 on: October 19, 2012, 01:13:33 pm »
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.
http://lazarus.freepascal.org/index.php/topic,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...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018