Lazarus

Miscellaneous => Other => Topic started by: bill0287 on June 27, 2016, 11:21:02 pm

Title: Thoughts on Python?
Post by: bill0287 on June 27, 2016, 11:21:02 pm
I started learning pascal when Delphi 1 came out and I am very comfortable with the language. I also hear about python a lot, and was wondering if anyone had any thoughts on learning python as well? Is it an easy language to learn? What kind of programs are best suited for it? etc.

I've looked over some content online, but would also like a gut feel reaction of some others who have python experience.

Thanks
Title: Re: Thoughts on Python?
Post by: Phil on June 27, 2016, 11:26:22 pm
Certainly there's many cases these days where you don't have the choice of doing everything in Pascal, for a variety of reasons. One good way to do parts of virtually any project in Pascal is to put your Pascal non-UI code into a dynamic library, then learn enough of one or more languages to demonstrate that the library can be used with those languages.

See article series here on how-to:

https://dl.dropboxusercontent.com/u/28343282/MacXPlatform/PascalDynLibs.html

-Phil
Title: Re: Thoughts on Python?
Post by: Leledumbo on June 28, 2016, 12:50:11 am
Just learn if you want to learn, no need to ask anyone first before getting your hands dirty with any language. Even learning a really dead language (no (recent) implementation, just a bunch of specs or docs) is not a bad idea. You'll find what a language is good for after you gain enough knowledge for the language. It's typically "everything" for a general purpose language, ignoring the technical aspects (speed, memory). Don't limit yourself from people's opinion.
Title: Re: Thoughts on Python?
Post by: JD on June 28, 2016, 01:30:07 am
Python
 - Great language
 - Easy to learn
 - Interpreted language so not as fast as compiled languages
 - Best language for string manipulation (in my opinion)
 - Wonderful for writing system scripts (especially on Linux)  :D
 - Hard to find a good free GUI for Python (PyQt is the best that I know of and it is not free)
 - Lots of frameworks exist for writing web applications (I've used web2py and I like it)
 - Lots of tutorials everywhere on the Internet
 - Everything is already included in the language (Tcl/tk is there also but I think it is an ugly GUI)

JD
Title: Re: Thoughts on Python?
Post by: marcov on June 28, 2016, 09:15:42 pm
IMHO I never really understood which kind of apps python was suitable for.

Of course the believers say everything, but, as JD says, as soon as you need a GUI, or work on windows, it is already second rate (if not third).

So unless writing strictly for the Linux distributions IMHO there is no point.
Title: Re: Thoughts on Python?
Post by: Phil on June 28, 2016, 10:03:31 pm
IMHO I never really understood which kind of apps python was suitable for.

Scripting and plugins, not legacy desktop "apps".

In some areas, Python is about the only thing you would use. For example, in GIS. See this list of plugins for the open-source QGIS:

http://plugins.qgis.org/plugins

Other languages need not apply, except perhaps for developing dynamic libraries to be called from Python, eg,

https://dl.dropboxusercontent.com/u/28343282/MacXPlatform/PascalDynLibs_3.html#QGIS

Title: Re: Thoughts on Python?
Post by: sfeinst on June 28, 2016, 10:07:47 pm
Of course the believers say everything, but, as JD says, as soon as you need a GUI, or work on windows, it is already second rate (if not third).

I don't use Python myself, nor any apps using it, but I'm pretty sure EverNote is written in Python.  I know ZIM (a local Wiki/Treepad tool) is also written in Python.

Not saying it is great or that its UI can't be improved, but there are apps with GUIs that seem to work fine.  Just wanted to point out that a UI can be built with the tool.  I'm not sure what libs you need to do it.
Title: Re: Thoughts on Python?
Post by: JD on June 28, 2016, 11:31:37 pm
Not saying it is great or that its UI can't be improved, but there are apps with GUIs that seem to work fine.  Just wanted to point out that a UI can be built with the tool.  I'm not sure what libs you need to do it.

Anything built using the Qt library looks great. That is where the heavy lifting is done. But it is not free. I also prefer Python for anything related to Data Mining. Python makes parsing data files for data manipulation easy. If you're into Big Data/Data Mining, sooner or later you'll run into Python.  :)

JD
Title: Re: Thoughts on Python?
Post by: Phil on June 29, 2016, 01:19:11 am
Anything built using the Qt library looks great. That is where the heavy lifting is done. But it is not free.

I believe Qt and PyQt are free for some types of open source projects. Qt is what QGIS is built on and QGIS is free.

And yes, QGIS looks great even on Mac, certainly better than LCL widgets look on Mac.

Title: Re: Thoughts on Python?
Post by: JD on June 29, 2016, 01:24:54 am
Anything built using the Qt library looks great. That is where the heavy lifting is done. But it is not free.

I believe Qt and PyQt are free for some types of open source projects. Qt is what QGIS is built on and QGIS is free.

And yes, QGIS looks great even on Mac, certainly better than LCL widgets look on Mac.

You're right. The restriction is for commercial projects. I actually meant to say not free for commercial projects.  :D

JD
Title: Re: Thoughts on Python?
Post by: JD on June 30, 2016, 01:45:04 pm
IMHO I never really understood which kind of apps python was suitable for.

Of course the believers say everything, but, as JD says, as soon as you need a GUI, or work on windows, it is already second rate (if not third).

So unless writing strictly for the Linux distributions IMHO there is no point.

As an example of a Windows based Python application, take a look at the new PgAdmin 4 (desktop & web interface)
http://pgsnake.blogspot.fr/2016/04/pgadmin-4-elephant-nears-finish-line.html
https://www.postgresql.org/ftp/pgadmin3/pgadmin4/

I believe the developers have tried to create something similar to phpMyAdmin. The problem is that being a Python application, it really shows in the speed of queries. Compared to pgAdmin 3 which was written with C++ with Qt, pgAdmin 4 is SLOW! dBeaver a Java based database management application is even faster than pgAdmin 4. I would keep my pgAdmin 3 & dBeaver for some time to come.

This is why the pros & cons of developing desktop applications with Python should be carefully considered.

Another web based application built with Python is OpenERP/Oddo https://www.odoo.com/.

JD
Title: Re: Thoughts on Python?
Post by: cdavidson on June 30, 2016, 02:39:05 pm
I like the language and have used it for quite a few utilities, but - so far for me - it seems to fall short when I try it on a major desktop app.  I usually fall back to Lazarus, C# or C/C++.

Instead of QT look at PySide http://wiki.qt.io/PySide (http://wiki.qt.io/PySide) it is basically PyQT but allows both free open source and proprietary software development.
Title: Re: Thoughts on Python?
Post by: marcov on June 30, 2016, 03:20:33 pm
IMHO I never really understood which kind of apps python was suitable for.

Scripting and plugins, not legacy desktop "apps".

Yes, but  scripting/prototyping is about the first thing ANY language is said to be good for. Even Delphi was with its RAD approach.

And plugins are only doable when the system is specially prepared for Python plugins. Again very general (if system X accepts only  plugins in X... is that a language advantage or the preference of an author?)
 
Quote
In some areas, Python is about the only thing you would use. For example, in GIS. See this list of plugins for the open-source QGIS:

An example of the above.

Quote
Other languages need not apply, except perhaps for developing dynamic libraries to be called from Python, eg,

If I look at the reasons, it seems it only does so because they want vet plugins themselves. (share a plugin program)

Still, Android has the same disease (with Java)
Title: Re: Thoughts on Python?
Post by: Dasun on July 02, 2016, 03:27:40 am
Calibre is a really nice mult-platform Python  GUI Application ... I set out to learn Python for a multi-platform application and somehow ended up learning Lazarus/FreePascal instead.  One thing that scared me about Python was  no Begin End/{ } construct using whitespace indenting instead .. I have had instances in the past of whitespace being trashed in files and the thought of that happening to a large Python program leaves me stone cold.  Of course, Python is hugely popular and Pascal - well it is considered a little retro in some corners :-)
Title: Re: Thoughts on Python?
Post by: Phil on July 02, 2016, 03:46:34 am
I like the idea of combining good indentation with getting rid of unnecessary begin/end or {}. Apple's new Swift language appears to borrow some nice features of Python (returning tuples as function result) and I had hoped that maybe {} would be optional the way semicolons are optional in Swift.

As for trashing white space, maybe you just need a better editor. I use TextWrangler on Mac - never a hiccup in all the years I've used it.

-Phil
Title: Re: Thoughts on Python?
Post by: tsiros on July 07, 2016, 02:10:59 pm
My thoughts on python? "Laughable".

I never once in my life felt that the begin/end keywords were a nuisance.

Making whitespace semantically significant, though? What does that accomplish, except add one literally invisible thing to look out for?

Oh, it's for defining *blocks of code*? Oh well, there are blocks of code and there are lines of code. Why not also require each line of code to terminate in one, exactly one, space character? Imagine the headache.
Title: Re: Thoughts on Python?
Post by: graemex on July 09, 2016, 12:16:55 pm
Python is what I use for everything - but I rarely desktop GUI applications. In fact, I came to the forum today to ask a question about using Pascal/Lazarus to write a GUI wrapper around some Python code.

Stuff I have developed in Python:


I do use a lot of Python GUI software, even though I have never written anything non-trivial myself.

Examples of Python GUI software I use:


That excludes all Python development related stuff, and non-GUI applications such as Mercurial. I am probably missing a lot because Python is so pervasive on Linux and I often do not know what language applications I use are written in.

Python is a brilliant language. Significant whitespace makes it extremely readable and means you never do things like forgetting a end of line semi-colon or a closing brace. It is concise, multi-paradigm, and has lots of libraries. It has a huge breadth of application. Its biggest weaknesses are:


Quote
Oh, it's for defining *blocks of code*? Oh well, there are blocks of code and there are lines of code. Why not also require each line of code to terminate in one, exactly one, space character?]

Python does use whitespace to define lines of code. A newline ends a line of code. It uses the appropriate whitespace in each case. Your rhetorical question is a bit like asking "oh it uses words to end blocks of codes. Why not end each line of code with "antidisestablishmentarianism"?  Imagine the headache."

Quote
I have had instances in the past of whitespace being trashed in files and the thought of that happening to a large Python program leaves me stone cold]

Python has been my main language for the last 10 years and that has never happened. How did it happen to you? What trashed the whitespace?

Quote
it seems to fall short when I try it on a major desktop app.  I usually fall back to Lazarus, C# or C/C++.

That may be the case. That is why I am interested in learning Free Pascal and Lazarus. That said, other people seem to use Python for desktop apps successfully.

Quote
Instead of QT look at PySide http://wiki.qt.io/PySide it is basically PyQT but allows both free open source and proprietary software development.

I think PyQt is more actively developed, and if you are selling proprietary software you should be able to afford the license.

There are also a LOT of other GUI libraries for Python: tkinter (part of the standard library), wxPython, PyGTK, Kivy (good for mobile) and others. That is part of the problem though - I am not sure which one to use in a particular case.

Quote
The problem is that being a Python application, it really shows in the speed of queries

I do not really see how that can happen. All the Python code really does is hand the queries to a C library that then sends them to the DB server. Something else must be going wrong.
Title: Re: Thoughts on Python?
Post by: Thaddy on July 09, 2016, 01:08:44 pm
I do not really see how that can happen. All the Python code really does is hand the queries to a C library that then sends them to the DB server. Something else must be going wrong.
Well the thing is indeed that Python is a -some would say glorified - scripting system to access high performance C (or FPC!) libraries. It is a weak typed scripting languange. If you need real performance in Python it is either by accident or because libraries written in a strongly typed compiled language are available. Mind you, I know 'Python can be compiled to native code' excuses, but that is half the story.

And: I use Python a lot and like it. Don't confuse the purposes of languages. One is convenience the other is performance.
Title: Re: Thoughts on Python?
Post by: graemex on July 09, 2016, 02:03:59 pm
Quote
It is a weak typed scripting languange.

It is dynamically strongly typed. Unlike, for example, Javascript, TCL, or PHP which are dynamically weakly typed. For example "2" + 2 in Python will give you a TypeError, whereas expr {"2" +2} in TCL will return 4.

Quote
Mind you, I know 'Python can be compiled to native code' excuses, but that is half the story.

There is a bit more to it than that. You can improve Python performance by doing certain things (e.g. using comprehensions instead of for loops), you can call existing libraries, you can rewrite performance critical code in Cython (essentially a statically typed subset of Python), or you can use PyPy (a lot faster than the usual Python implementation, but still a lot slower than C or Pascal).

Quote
Don't confuse the purposes of languages. One is convenience the other is performance.

I agree with the principle. I use Python for almost everything I do because I usually find the performance bottlenecks are outside my code (database or network), or there are existing libraries for in a faster language (e.g. numpy, lxml, etc.), or Python is fast enough and using a faster language will not make a difference users will notice.

Going back to the original question:

Quote
Is it an easy language to learn?

Yes, and there are lots of tutorials, documentation, and online courses.

Quote
What kind of programs are best suited for it?

It is good for a lot of different things, because it has a lot of libraries. Anything that does not require really high performance (not for games, not for numerical work that requires higher performance than Numpy can deliver) or lots of low level system access (device drivers, OSes).

The languages may well complement each other quite well. I can imagine writing a application in Python, with performance critical stuff in Pascal, and wrapped in a Lazarus GUI.
Title: Re: Thoughts on Python?
Post by: Thaddy on July 09, 2016, 02:17:09 pm
Quote
It is a weak typed scripting languange.
It is dynamically strongly typed.
Yes it is typed after first use. Half-baked compared to strongly typed. This is not really a criticism, it is not strong typing but something in between.
Quote
Quote
Mind you, I know 'Python can be compiled to native code' excuses, but that is half the story.

There is a bit more to it than that. You can improve Python performance by doing certain things (e.g. using comprehensions instead of for loops), you can call existing libraries, you can rewrite performance critical code in Cython (essentially a statically typed subset of Python), or you can use PyPy (a lot faster than the usual Python implementation, but still a lot slower than C or Pascal).
Any self respecting scripting language has the ability to call out existing libraries. Have you seen any Phyton code that is really build in Python from the ground up? Of course not.
With FPC or C you have that ability.To the extend that you can write real OS's in it. Impossible in Phyton. And not the use-case for Phyton.
Title: Re: Thoughts on Python?
Post by: graemex on July 10, 2016, 10:39:32 am
With regard to strong typing, we are just using slightly different definitions. I prefer the definition that treats strong vs weak as separate from static vs dynamic, because then you can pin languages down as dynamic and weakly typed, dynamic and strongly typed, static and strongly typed or static and weakly typed.

My ideal language would probably be something like Python with type inference.

As for the rest, I am not suggesting you can do everything any developer may want to do in Python, but that it is a productive and easy to maintain language you can use for a lot of different things.
Title: Re: Thoughts on Python?
Post by: Leledumbo on July 10, 2016, 01:14:56 pm
With regard to strong typing, we are just using slightly different definitions. I prefer the definition that treats strong vs weak as separate from static vs dynamic, because then you can pin languages down as dynamic and weakly typed, dynamic and strongly typed, static and strongly typed or static and weakly typed.
Correct, the two should indeed be separated so there are 4 possibilities.
My ideal language would probably be something like Python with type inference.
Have you tried Nim? It looks like Python with type inference, influenced by Pascal units functionalities and LISP metaprogramming capabilities.
Title: Re: Thoughts on Python?
Post by: x2nie on July 10, 2016, 03:59:17 pm
My ideal language would probably be something like Python with type inference.
Have you tried Nim? It looks like Python with type inference, influenced by Pascal units functionalities and LISP metaprogramming capabilities.
Wow ~!
I see the Nim's syntax is sexy. as sexy as Python's syntax.
Personally I felt Nim's syntax is sexier than Python's syntax.
Plus, Nim's syntax is more similar/familiar as pascal declaration syntaxes.
@Leledumbo, thanks you for letting us know about Nim existence.
Title: Re: Thoughts on Python?
Post by: tsiros on July 11, 2016, 12:24:13 am
Python does use whitespace to define lines of code. A newline ends a line of code. It uses the appropriate whitespace in each case. Your rhetorical question is a bit like asking "oh it uses words to end blocks of codes. Why not end each line of code with "antidisestablishmentarianism"?  Imagine the headache."

can you tell the difference between spaces and a newline or a word, or do i need to show you a screenshot?
Title: Re: Thoughts on Python?
Post by: graemex on July 11, 2016, 09:19:19 am
Yes, Nim looks really nice. I have not tried it yet, but plan to.

Its main disadvantage at the moment is it is still not mature (and there are still changes that break thing) and it lacks libraries. Both will be fixed with time, hopefully (and I gather it is easy to use C libraries with Nim which will help in the meantime).
Title: Re: Thoughts on Python?
Post by: Leledumbo on July 11, 2016, 01:24:21 pm
and it lacks libraries.
Actually, it has quite a lot, just not shipped by default. Nimble is its package manager (yes, it has working package manager already, which fppkg trails behind despite being much older). `nimble list` will show a bunch of existing packages.
Title: Re: Thoughts on Python?
Post by: serbod on July 11, 2016, 02:28:01 pm
Typed parameters in Nim is very good step. But Nim have same trouble, as Golang - weak class definition. Methods and properties can be added anytime and anywhere, and it's brings disorder, increase chance of design mistakes.
Title: Re: Thoughts on Python?
Post by: Thaddy on July 11, 2016, 05:40:28 pm
My ideal language would probably be something like Python with type inference.
I somewhat agree with that... would look a lot like Object Pascal with type inference, though :) Except for whitespace  O:-)
Title: Re: Thoughts on Python?
Post by: Leledumbo on July 11, 2016, 07:45:45 pm
Typed parameters in Nim is very good step. But Nim have same trouble, as Golang - weak class definition. Methods and properties can be added anytime and anywhere, and it's brings disorder, increase chance of design mistakes.
Yup, same as golang too, it is by design. Well at least it doesn't abuse the already well known semantics of := operator.
Title: Re: Thoughts on Python?
Post by: Quiser on May 23, 2018, 11:49:52 am
I apologize, guys, I know that this topic is very old, but maybe my answer will help someone in the future.
JavaScript - because it was always the dark horse, has had the huge advantage of monopoly over front end. And server side JavaScript is finally becoming mature enough. It just needs one meaty web framework to spice things up.

Python - because it is the equivalent of Java in scripting world. Has been around for a long time. Has tons of libraries. Any big project is unlikely to have only web dev concerns. At some point they are going to need other generic or domain specific libraries. Python wins here by miles. Add maintainability as another plus. They got one thing damn right - the emphasis on readability and explicitness. This alone will ensure that it will continue to remain the most favorite general purpose language for a long time to come.

Scala - because it combines the best of several worlds and the smartest minds are already moving there. Being on JVM is a big plus, as is the flexibility of using both functional and OO approaches. Those who cannot use Clojure ( due to lack of frameworks or developers ) will switch to Scala and this will keep the quality of the community high.
PHP will still hang around for a lot of time as legacy language. The code base is huge and it is not going to go away anytime soon.
If you interesting, check out this article where compare this two languages between each other https://diceus.com/what-technology-is-better-for-big-data-projects-comparing-python-and-java-r/ I hope it helps
Title: Re: Thoughts on Python?
Post by: Phil on May 24, 2018, 12:18:21 am
If you interesting, check out this article where compare this two languages between each other https://diceus.com/what-technology-is-better-for-big-data-projects-comparing-python-and-java-r/ I hope it helps

That article is about comparing the use of Java and Python in so-called "Big Data" projects. It's not really very useful for comparing those languages in general or discussing the use of those languages in the kinds of projects that you see done here (ie, not "Big Data" proejcts).

The article, although recently written, also feels just a big outdated to me. It's my impression Python has pretty much run away with everything in the area of "Big Data".

For example, a typical Python project:

https://medium.com/@DescartesLabs/using-petabytes-of-pixels-with-python-to-create-3-new-images-of-the-earth-9216fcbccdc5
Title: Re: Thoughts on Python?
Post by: RobbieL91 on May 24, 2018, 10:42:01 pm
If you interesting, check out this article where compare this two languages between each other https://diceus.com/what-technology-is-better-for-big-data-projects-comparing-python-and-java-r/ I hope it helps

That article is about comparing the use of Java and Python in so-called "Big Data (https://www.studypug.com/statistics-help/measures-of-dispersion/spread-of-a-data-set-standard-deviation-variance)" projects. It's not really very useful for comparing those languages in general or discussing the use of those languages in the kinds of projects that you see done here (ie, not "Big Data" proejcts).

The article, although recently written, also feels just a big outdated to me. It's my impression Python has pretty much run away with everything in the area of "Big Data".

For example, a typical Python project:

https://medium.com/@DescartesLabs/using-petabytes-of-pixels-with-python-to-create-3-new-images-of-the-earth-9216fcbccdc5

Thank you, it's an nice article.
Title: Re: Thoughts on Python?
Post by: Phil on May 25, 2018, 12:09:23 am
Thank you, it's an nice article.

Not sure which article you're referring to, but never mind.

Perhaps more evidence of Python's importance in areas like Big Data, data science and machine learning: the addition of Python interoperability to the Swift language as part of Google's TensorFlow project:

https://github.com/tensorflow/swift/blob/master/docs/PythonInteroperability.md


What about something for the Pascal developer who's looking at Python?

A good way to extend the usefulness of your Pascal code is to put it in a dynamic library and add a Python extension module so you can call the library from Python code.

An older article is here:  http://wiki.lazarus.freepascal.org/Developing_Python_Modules_with_Pascal

Newer articles and examples are here:  https://macpgmr.github.io

And if you like puzzles, a jumble of confusing information about Python4Delphi is here:  http://wiki.freepascal.org/Python4Delphi

TinyPortal © 2005-2018