LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python - worth learning? (https://www.linuxquestions.org/questions/programming-9/python-worth-learning-339503/)

vharishankar 07-03-2005 12:30 AM

Python - worth learning?
 
I just have a question. I am beginning to learn Python, but so far I've not been impressed with the language structure. It resembles BASIC too much and it's syntax is quite awkward for me coming from a C, C++ background. Also I am uncomfortable with the loose typing (no variable declarations) and so on.

But I have heard many good things about Python. My question to experienced Python programmers is : Is it worth learning Python?

I am familiar with PHP and find it much more comfortable although I haven't really had too much to do using it so far.

Thanks.

redhatrosh 07-03-2005 12:36 AM

I dont really know much about Python and haven't learnt it. But becoz Python is a Object Oriented Programming I feel it is an important language to learn and develop things much better.
Well, I also have one question!

Is Python Cross platform oriented like Java...or how is it functioning actually...(again to all the programmers who are experienced!)

vharishankar 07-03-2005 12:38 AM

Python is an interpreted language and it is cross-platform (to the extent that systems with Python interpreters will run any python program).

I really don't know whether it's object oriented capabilities are superior to Java. At first sight Python's lack of structure or strong typing seems to be pretty much against it.

NCC-1701&NCC-1701-D 07-03-2005 05:13 AM

Every language is worth learning. Pyhton can help you create very good apps, cross platform and it's easier than C/C++/Java. If you have a look at sourceforge you'll see that many projects are in python. Give it a try!

phil.d.g 07-03-2005 05:45 AM

Whilst I don't know python, I know a few friends who do and they love coding in python and think its a great language, I intend to learn python, but one thing at a time - I'm learning C at the moment.

vharishankar 07-03-2005 06:10 AM

Maybe it's just my basic aversion to any language that does not have formal and compulsory variable declaration... :D

Also maybe I am just used to ending all statements with a semicolon :p

Python looks good, but I don't see what it offers beyond Java to be honest. But I'm going to learn it anyway and see what I can do with it.

Any ideas for a good project with python?

Michael Johnson 07-03-2005 07:41 AM

Try a programme to organise you photographs. This will test almost every aspect of your capabilities apart from mutlimedia (unless add sound).
Second thought turn your photographs into a movie and really test your skills.

jlliagre 07-03-2005 09:14 AM

Quote:

Python looks good, but I don't see what it offers beyond Java to be honest.
You can try Jython or Groovy, for the best of both worlds ...

carl.waldbieser 07-03-2005 12:53 PM

Python is definitely worth learning. It is becoming more and more prevelant as the scripting language of choice in certain areas (e.g. the Ubuntu distro makes use of Python considerably to provide various add-ons like their menu editor project).

The fact that variable types are not decalred is often met with reservation by folks who come from a background of languages that require lots of type declarations. For example, I have a C++ background. I was a little concerned that not having the types of variables explicitly declared might lead to some headaches. But I found that in practice, not declaring the types just saved me a lot of extra typing on the keyboard. A parallel I like to draw is that in modern practice, a lot of emphasis in C++ is being placed on the practice of using templates and meta-programming techniques. The idea is to get the compiler to infer and generate types for you. It turns out that the actual type of an object isn't so important as th fact that it conforms to a set of behaviors that operate on it. It turns out that in Python, this is exactly what you get. Here is a quick example:

Code:

template<typename T1, Typename T2, Typename T3>
T3 add(T1 t1, T2 t2)
{
  return t1 + t2;
}

def add(t1, t2):
  return t1 + t2

What is interesting in both these cases (C++ and Python), is that the types of the operands are not particularly significant. What is important is that you must be able to add the first and second parameters together and return the result. In C++, the compiler will catch this problem at runtime if the types don't support the addition operator (+). In Python, the error is caught at runtime with a nice, built-in stack trace. The fact that I can focus on coding the problem at hand rather than focusing on the syntax of what I want to describe more than makes up for the early constraint checking, in my opinion.

Also, Python is considered a very straightforward language with very few surprising idioms. This makes it easy for someone who does not have a lot of hard-core programming experience to work with the language.

johnMG 07-03-2005 08:12 PM

Hari,

I'm not a huge fan of Python either. You wrote:

> Python looks good, but I don't see what it offers beyond Java to be honest.

and I'm inclined to say that I don't see what it offers beyond Java either.

In general, scripting languages are for gluing together command line apps and for dealing with text. bash does this pretty well, Perl does it too, and Python can do it well enough also. When you want a general purpose programming language though, I'll head straight for Java. It's not flashy and it's a bit verbose, but for large apps, I think it's the way to go. It seems to me that Pythonistas try to sell Python as a general purpose programming language, but I don't buy it. My hunch is that lack of static type checking at compile time just sets you up for hunting hard-to-find bugs later on at runtime.

BTW, Python is in fact a strongly typed language. Types matter -- it's just that they matter at *runtime*, rather than when you actually compile the code (yes, Python is compiled, just like Java or Perl -- it happens quickly first thing when you run the script). Python is strongly typed, but also *dynamically* figures out the types of objects when required.

vharishankar 07-03-2005 09:16 PM

JohnMG thanks for that interesting bit of info.

Regards.

vharishankar 07-04-2005 05:53 AM

Success. I learnt two new things today. :D :D

Python and ncurses with Python.

I developed a tiny little 'thought for the day' program using it, reading lines from a file and randomly displaying any one of them in a terminal window.

It is a bit like fortune program, but this is displayed in an ncurses window with a blue screen.

Nice!

Python tends to grow on you. But I still am not convinced of its true 'object' oriented nature though.

carl.waldbieser 07-04-2005 12:55 PM

Not sure what you mean by "...true 'object' oriented..." nature. I have observed the object-oriented model is somewhat vague and open to various interpretations. There are certainly commonalities throughout various languages, but it is hard to say "here is archetypical example of object-orientedness".

Python provides multiple avenues of approaching programming. OOP is one valid approach, but I have seen procedural and functional approaches used as well.

Tinkster 07-04-2005 01:03 PM

Quote:

Originally posted by carl.waldbieser
"here is archetypical example of object-orientedness".

I'd most certainly say that smalltalk does deserve that title ;)



Cheers,
Tink

YaHu 07-04-2005 03:25 PM

Quote:

Originally posted by carl.waldbieser
[B]Python is definitely worth learning. It is becoming more and more prevelant as the scripting language of choice in certain areas (e.g. the Ubuntu distro makes use of Python considerably to provide various add-ons like their menu editor project).

...]
Python's nice, but if you don't need the Python libraries I prefer Ruby.
OTOH, Pyrex is a nice extension to python, that lets you easily blend Python, where you want flexibility, with C where you want performance. (Note that there is, as one would expect, overhead in the connection, but if you properly divide things that can be minimized.)

Python doesn't have much in common with Basic...actually, I feel that it has less in common with it than C does. It's mode of structuring code through indentation can take getting used to, but really isn't THAT bad once you get used to it.

Relatively speaking, Python is a slow language. It's certainly no faster than Java. OTOH, writing the code is a lot faster once you get used to it. (There's LOTS of libraries to make some things easy, and slow things fast.)

Worth learning? Depends on your purpose. Languages I currently find worthy are Ruby, Python, D (Digital Mars D == dmd). On the fringe are Eiffel, Ada and Smalltalk. I don't consider either C or C++ as worthwhile because of the mess they cause with their insistance on pointers everywhere. A compiler should HIDE that garbage from you, for two reasons:
1) It's quite easy to make mistakes
2) It makes garbage collection difficult to impossible.
(Note that all of my top tier of languages have garbage collection built in. If you're into hard real-time programming, then you have considerations that make these languages a poor choice.)

It's not that I can't program in C (and a doggerel of C++), it's that I despise doing so. My disgust with pointers didn't come quickly, but only through bitter experience...and trying to figure out what someone's code was doing when he cast a int to a pointer...without decent documentation, and with obscurely named variables.

(All that said, I do prefer C over Basic, but it's a close try...and I prefer Java over either, but even Java didn't make it into the top two levels of what I consider a good programming language. [P.S.: My comment about Eiffel is a couple of years old. The language appears to have been going through a bunch of redesigns recently, and I don't know what the current version is like. The rumors haven't been encouraging, so perhaps it should be moved down below the second tier...but it DOES have garbage collection.])

caminoix 07-04-2005 03:36 PM

i've started learning python not long ago and so far i have to say:
python ROCKS!

it's easy but not simple. writing in it is a real pleasure :)

rsheridan6 07-04-2005 05:07 PM

Experienced Python programmers will all agree that you should learn Python
Experienced Perl programmers will all agree that you should learn Perl
Experienced Java programmers will all agree that you should learn Java
Experienced COBOL programmers will all agree that you should learn COBOL

etc..

Personally, I find Python to be a nice enough language to be "worth using", but there's nothing interesting enough about it to make it "worth learning." It's good for some things, not so much for others. It depends on your motivation for wanting to learn it.

If you don't like it, you may prefer Perl or Ruby, which solve the same sorts of problems Python solves, but in different ways.

deiussum 07-04-2005 08:28 PM

I know of at least a couple of things that use Python, such as scripting in Blender, and it is also used for Scons scripts. (A build system designed to try and replace the usual ./configure make make install process...) There may be other things that use it as well.

If you are interested in doing either of these, it is worth learning. Otherwise, I'm not sure. I really haven't used it much myself other than writing a few Blender scripts.

vharishankar 07-04-2005 08:53 PM

Python is interesting, but I really feel that Java is more "cross-platform" than Python because so far I have been able to run 100% of my Java programs on Linux which were created on Windows, but a certain Python program which used ncurses did not successfully run in another OS.

Is there any way to ensure that Python programs are 100% cross-platform or should one just avoid using the modules that appear to be specific to OSes?

carl.waldbieser 07-04-2005 11:45 PM

If you do not use platform specific extensions (e.g. win32com for Windows), you should be OK. Anything in the Python standard library will note if a particular feature is only available on certain systems. Many third party modules will also point this out in their basic requirements.

Also, if you are really into Java, you may be more interested in jython-- it is the Java implementation of Python, and it has good integration with Java. You can access the Java libraries from jython. Jython does tend to lag Python in terms of development, however. Still, many of its proponents find it useful for quickly prototyping GUIs or whatnot or adding a scripting engine to their Java programs.

http://www.jython.org

jlliagre 07-05-2005 01:20 AM

If you are really into Java, you may have a look to groovy
http://groovy.codehaus.org/
and beanshell
http://www.beanshell.org/

vharishankar 07-05-2005 01:50 AM

You have got it wrong about my intentions, I think. I am not looking for something that is a blend of Python and Java.

Sure, I like Java, but I will also continue learning Python for its own sake as well. It's a very powerful scripting language while Java is a general purpose language.

Both are good. And as I said before, I enjoyed programming a little "thought for the day" app in Python using ncurses.

File handling is a breeze. Constructs like for loops are very easy in Python as well.

And for me, given the basic documentation it takes a couple of hours for me to learn a new language (minus all the library/API and so on).

The only disadvantage with Python is that it needs all those modules installed on the target machine to work properly. If you are developing a large, feature-rich application, I think Java would definitely rank as a better choice because the Sun JRE is more standard across distributions. Python I think is better suited for UNIX-like environments although I know it's available for Windows too.

chrism01 07-05-2005 02:09 AM

For somebody who's used to C, Perl may be more appropriate, as it's heavily based on C syntactically (& written in C underneath), inc ending standalone statements with
';'.
Also, if you use
use strict;
(and you should), it'll force you to declare your variables before use.
Use 'my' vars in subs to emulate C's private vars; avoid globals where possible.

jlliagre 07-05-2005 02:18 AM

Quote:

Please do not post Linux vs. Windows threads or tell us why Linux sucks so much.
I see more "Windows sucks" than "Linux sucks" in this forum actually ...
Quote:

This is primarily a Linux help site.
True, but this particular forum (Programming) is not limited to Linux, and some others (*BSD, Solaris, AIX, Uther *NIX) are clearly targetting a wider audience.

vharishankar 07-05-2005 02:23 AM

Hey jlliagre,

That's my signature. Nothing to do with this topic ;)

Hko 07-05-2005 11:38 AM

Bruce Eckel wrote the "Thinking in ..." books (donwloadable as well) about C++, Java and python.

Here's what he thinks of Python:
http://www.artima.com/intv/aboutme.html

vharishankar 07-05-2005 09:45 PM

Hko, thanks for that link. Very interesting read. I am beginning to understand why people tend to love Python. It is quite powerful while making programs easier to write.

The only gripe I have is the documentation. Function parameters are hardly explained and I have had hell trying to pass "options" into certain functions, guessing each value one by one. Why don't the documentation writers tend to list out all the options for functions? I noticed this especially in the Tkinter documentation.

How the hell am I supposed to know the "options" passed to certain functions without having them listed out somewhere?

JoshR 07-05-2005 11:16 PM

Very nice thread. I've been wondering about which languages to delve into for quite some time. I programmed a bit when C++ first came out, maybe 20 years? I don't really recall, but my thinking at the time was:

"Gee, this is a bit constipating, don't you think?" I gave it up and went on to other pursuits. (designing airplanes and such).

I got a bit excited again with VB. Don't laugh, I didn't even have to pay for the packages.

New pursuits........sky diving, building houses, and driving race cars. Put on hold.

Next up: I'm using my computer for practical stuff, Excel for running my biz, Word for writing, I'm thinking of really doing some Access apps, too. All this on a custom Win 98SE machine, don't you dig?

A few months ago, my box went borg up. I'm pissed, I've re-installed a zillion times, I can do it in my sleep. But still.........I get XP. I've got to do WHAT to validate??? Sure.........Go online, get some Linux and learn like crazy. What?? I feel like I've been raped. Sure, I played with Linux 10 years ago. But, where have I been? (Doing fun stuff, right?). Anyway, I'm learning a few distros at once, and am searching for a language to write custom apps.......My body won't let me jump out of perfectly good airplanes anymore.......

So, out of happenstance, I find this thread. I've been thinking perl? Python? Java? I don't have the lifespan of an orangutan, now do I? No way do become expert on all these.......It comes down to these two.......

Python or perl. I know, I know........"what are you going to do with it?"

HAVE FUN, naturally. My apps? Some specialized data bases, some work-arounds for Linux stuff, some apps for doing fun stuff with all the new hardware out there.......Mainly I'm on a mission: To tranform every sing win user to free software. What could be better?

JoshR

caminoix 07-06-2005 03:28 AM

everyone, including JoshR ;)

there's a great site called 99 bottles (http://www.99-bottles-of-beer.net/abc.html) where you can see a simple program which prints on the screen the very well known song '99 bottles on the wall', written in 729 variations (some languages have more than one version).

it's a superb way to peek a little at what you're going to have to deal with.

(for perl, make sure you choose the 'standard version' (on the right))


JoshR

i don't know perl, so i can't really tell you but as you say you only want to have fun, i think python is the right choice for you. you say you have an idea about c++; i knew pascal, javascript and a bit of assembler when i started learning python, and i did start learning it because i tried to learn how to fetch a website with c++ and got scared by this whole socket stuff.
now, i couldn't help laughing at myself when learning python. i wasn't at all prepared to meet something that easy! yet it's not like python doesn't let you do anything, and is just a scripting thing. you can do really quite a lot in it, you can write guis with qt (an excellent designer tool they provide), you can write a daemon, or you can just play with superkaramba.

finally, if you say
Quote:

Mainly I'm on a mission: To tranform every sing win user to free software. What could be better?
why not switch to linux? linux is pretty much like windows with loads of extra software, all for free.
for the first try, you could choose knoppix (http://www.knoppix.org/), which you run directly off a cd, without installing anything.

oneandoneis2 07-06-2005 04:26 AM

Well, FWIW, my take on it is this:

I'm not a programmer. Much as I love Linux, FOSS et al, I'm not a computer professional, I'm merely a hobbyist.

I've wanted to be able to code for ages, but I've never been able to understand how to use languages like C. The definitive experience was probably when I borrowed a library book on learning C++ and was unable to understand any of the code used to generate "Hello, world!".

I gave up at that point. There was just too much to try and understand before even the basics would make sense. It reminded me of the joke "To understand recursion, you must first understand recursion." - To learn to code, you must first know how to code?

However, when I recently began looking at online Python documentation, I understood everything. I could follow the examples and build upon what they taught me to make more powerful examples.

It was enough to convince me to buy the O'Reilly book on Python (Which has a rat on the cover, go figure). I'm about eight chapters in, and so far I've understood everything.

This is unprecedented: I've never gotten anywhere with any other language. Not C, not Java, not even VB FFS!

So, while it might not be the best choice if you already can code, IMHO it is the single best language to try and learn if you can't code but want to.

dr_zayus69 07-06-2005 05:58 AM

if your serious about programming you should learn at least one new language a year. Even if you don't end up using it much each language does things differently so if you go to do something in C/C++ you may be able to use something you learned from python. Python is also a "popular language" so it is good as any to learn.

vharishankar 07-06-2005 07:11 AM

I current can program in C, C++, Java, PHP and now learning Python. I like learning new languages. :)

The language I don't believe is the real learning part. The real learning aspect is the API and the documentation for the API. It is so important to have good online documentations and tutorials (for the basics) for any language.

Learning the syntax, keywords and very basic data structures takes hardly half an hour. The challenge is to put them together and use that language to the best use.

When I learn a language I usually look at tutorials and then create several programs using various aspects of the API on my own. It is a great exercise. I recommend it to anybody learning a programming language.

Once you have a good hold of the structure of programming in that particular language then you can easily develop applications using the API documentation alone.

Crashed_Again 07-06-2005 12:37 PM

Here's a python review from the legendary Eric Raymond:

http://www.linuxjournal.com/article/3882

JoshR 07-06-2005 05:24 PM

Quote:

Originally posted by caminoix
everyone, including JoshR ;)


JoshR


finally, if you say why not switch to linux? linux is pretty much like windows with loads of extra software, all for free.
for the first try, you could choose knoppix (http://www.knoppix.org/), which you run directly off a cd, without installing anything.

He, he! Saw my OS did you? Well, here's the deal.......I've got 3 other boxes just for Linux. I'm installing Slack, Deb, Arch, Gentoo, and LFS........

I'll be off this Win box in no time:D But thanks for the reply!! I'm starting Python too............

JR

caminoix 07-06-2005 05:52 PM

oh, what stupid cow i am! i am so sorry!
i was so sure you're using win out of what you said that i never thought to take a look what distros you've got written there and even failed to realize this forum is called *linux*questions!

please, accept my deepest apologies.

btw, once you've managed to install gentoo and lfs, i imagine you also managed to run network in arch. perhaps you could help me out with the following problem:
i use dhcp but setting it in rc.conf won't work. setting a specific ip does help and everyting looks like it's fine until i try to ping anything or update pacman.
do you have any idea where my problem might be?

JoshR 07-07-2005 12:35 AM

Quote:

Originally posted by caminoix
oh, what stupid cow i am! i am so sorry!
please, accept my deepest apologies.

btw, once you've managed to install gentoo and lfs, i imagine you also managed to run network in arch. perhaps you could help me out with the following problem:
i use dhcp but setting it in rc.conf won't work. setting a specific ip does help and everyting looks like it's fine until i try to ping anything or update pacman.
do you have any idea where my problem might be?

Well, don't worry about it! I said "I'm installing them" NOT that I've been sucessful with them all. Hit a snag with Debian a few minutes ago......Installing an old Mandrake to check it out!

Sorry, can't help you just yet.........but thanks for asking!!

JR:p

caminoix 07-07-2005 12:26 PM

ok :)

may i have a perhaps stupid and certainly unrelated question? in your signature, it says "you think YOU'RE new? i WAS born yesterday!", and to my non-native-english mind, it would look like the opposition is you:me whereas the words emphasized are you and was. do you think there could be a way to explain it to me?

sundialsvcs 07-07-2005 12:41 PM

I would say that it's wise to learn all of the major languages you're likely to encounter as a scripting-language here:
  • Python
  • Perl
  • PHP
  • Shell scripting yeech! ;)
You will naturally gravitate toward having a personal preference, but you need to be conversant in whatever you might see. The time spent doing so will be well-spent.

JoshR 07-07-2005 09:37 PM

Quote:

Originally posted by caminoix
ok :)

may i have a perhaps stupid and certainly unrelated question? in your signature, it says "you think YOU'RE new? i WAS born yesterday!", and to my non-native-english mind, it would look like the opposition is you:me whereas the words emphasized are you and was. do you think there could be a way to explain it to me?

Ok. What the sig means is that "whenever somebody says they are new to Linux, my answer is that I'm more new!"

In other words, I'm saying I don't know what I am talking about, and give me a break. (don't hold it agains't me).

I had some guys in my apartment that had immigrated from Poland. Nice guys and we had some conversations. One was fluent in English. one was not. I like them both. I think you may be like them, in that you want to really learn what the English are saying. Good for you! Send me an e-mail, I'll answer better, ok?

JR

caminoix 07-08-2005 02:38 AM

erm, this is not exactly what i was asking about. i did get the meaning, only i can't understand why you put 'was' in capitals, because i would only put 'i' in capitals though i could only hradly imagine how it could be even more capital...
thank you for the proposition but i'm afraid the forum does not let me send you an e-mail. do you think you could please send me an e-mail first at kstachowski@o2.pl?


All times are GMT -5. The time now is 07:06 AM.