Recent

Author Topic: Lazarus to write a UI around Python code - good idea?  (Read 7213 times)

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8898
  • FPC developer.
Re: Lazarus to write a UI around Python code - good idea?
« Reply #15 on: August 10, 2020, 03:58:57 pm »
Can't you communicate more directly with an embedded Python interpreter (like python4delphi) ?

Or on Windows something COM?

Warfley

  • Sr. Member
  • ****
  • Posts: 323
Re: Lazarus to write a UI around Python code - good idea?
« Reply #16 on: August 10, 2020, 04:29:29 pm »
Can't you communicate more directly with an embedded Python interpreter (like python4delphi) ?

Or on Windows something COM?

There are several ways to "directly" interact with python. For C and C++ this is documented here: https://docs.python.org/3.5/c-api/index.html

That said, simply comunicating via streams is more often than not much easier. Also it has much less restrictions on your system. When you do this you basically load a custom interpreter and talk to it, so you are restricted to exactly that interpreter.

While when you do this via streams, no matter if the target system uses python 2 or python 3 or python at all, it just works. One can just rewrite the whole program in bash, java or what not and it would still work (as long as this interface stays the same).

And with formats like json or xml you can transmit arbitrarily complex data between the systems without putting restrictions on their implementation. It also should be noted that python and Pascal types are not compatible at all. So you need to do a hell of a lot conversion anyway, so you don't even have less complexity in your code but most likely even more.

It also removes the locality from the project, meaning you can have both processes running on completely different machines and communicate via tcp (even when using stdin and stdout, netcat is your friend here)

I honestly don't see much reason to use such native interfaces, because this is usually much more complicated without giving you any advantages. There might be certain corner cases (e.g. when high performance is required) but in that case I wouldn't use python at all.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8898
  • FPC developer.
Re: Lazarus to write a UI around Python code - good idea?
« Reply #17 on: August 10, 2020, 04:58:08 pm »
Believe it or not, I'm actually doing my-first-python these last few weeks. Under protest of course.

Anyway, mucking with streams and pipes is not my experience of a smooth programming experience, specially not on windows( just look at the history of Lazarus and GDB on Windows, with some GDB builds not working at all)

I know that what you say is the often iterated party line, but do you have explicit experience on Windows with this?

In my experience such approach is fraught with problems and complaining will only yield "it works on Linux, and everybody should drop micro$haft anyway" like arguments.

Warfley

  • Sr. Member
  • ****
  • Posts: 323
Re: Lazarus to write a UI around Python code - good idea?
« Reply #18 on: August 10, 2020, 05:28:30 pm »
Believe it or not, I'm actually doing my-first-python these last few weeks. Under protest of course.

Anyway, mucking with streams and pipes is not my experience of a smooth programming experience, specially not on windows( just look at the history of Lazarus and GDB on Windows, with some GDB builds not working at all)

I know that what you say is the often iterated party line, but do you have explicit experience on Windows with this?

In my experience such approach is fraught with problems and complaining will only yield "it works on Linux, and everybody should drop micro$haft anyway" like arguments.

My experience with windows is, I don't use python on windows. Python is pretty much "build" for writing (console) I/O applications (there are things like PyQT but it is horrible) so this is the way python is "intended to be used" (the "" are because of course Python is a general purpose language, but the main python developers and users are using it mainly for these things). Windows is pretty bad at that (even though it is getting better with the windows terminal project).

Even when I'm on windows I either use docker, WSL or a Linux VM for doing my python stuff, because it is just easier. (I must confess I didn't manage to install matplotlib on Windows, it just wouldn't work). And I think, as all these solutions are pretty straight foreward, work perfectly fine and are also free, I think one can expect from someone to be able to use Linux software when necessary (at least in the tech world). It's not like windows or macOs which is gated behind a pay wall

That said, in principle this should also work on Windows, because even though windows is not the greatest at terminal applications, simple piping to stdin and stdout is supported. AFAIK you can't implement COM interfaces in python (you can use them but not provide them), at least not easiely, because this is not portable and python tries to be as machine independent as possible. Therefore these general interfaces (stdin/stdout and program args) are usually "the way to go" because these work on nearly any machine with nearly any system, BSD, Linux, Mac and Windows.
« Last Edit: August 10, 2020, 05:31:09 pm by Warfley »

 

TinyPortal © 2005-2018