electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Developers' Corner
Python for obeject oriented programming ?
Post new topic   Reply to topic Moderators: DrJustice
Page 1 of 1 [17 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
jksuperstar



Joined: Aug 20, 2004
Posts: 2488
Location: Denver
Audio files: 1
G2 patch files: 18

PostPosted: Thu Dec 07, 2006 2:56 am    Post subject: Python for obeject oriented programming ? Reply with quote  Mark this post and the followings unread

Quick OT - I never sat down and learned a good object oriented language, but would like to. Would you recommend python over Java, Smalltalk, C++, etc? I really just want to teach myself how to break problems down into an object based system, rather than the more rigorous methods (like Verilog/HDL languages, C, assembler). I pick up semantics very easily, when I use them, so I figure once I know how to break apart a problem, I can learn another language at another time when needed. But for now, just don't want the language to get in the way, if that makes sense. I've used perl, but only for parsing and text munging, and really only in a C-like fashion, without defining my own methods, etc. It seems the other languages can go way beyond perl very quickly.

[Note, Blue Hell : I split this topic off from http://electro-music.com/forum/post-98105.html#98105]
Back to top
View user's profile Send private message Visit poster's website
qfingers



Joined: Nov 16, 2006
Posts: 183
Location: Tucson, AZ
G2 patch files: 2

PostPosted: Thu Dec 07, 2006 6:32 am    Post subject: Reply with quote  Mark this post and the followings unread

jksuperstar wrote:
Quick OT - I never sat down and learned a good object oriented language, but would like to. Would you recommend python over Java, Smalltalk, C++, etc? I really just want to teach myself how to break problems down into an object based system, rather than the more rigorous methods (like Verilog/HDL languages, C, assembler). I pick up semantics very easily, when I use them, so I figure once I know how to break apart a problem, I can learn another language at another time when needed. But for now, just don't want the language to get in the way, if that makes sense. I've used perl, but only for parsing and text munging, and really only in a C-like fashion, without defining my own methods, etc. It seems the other languages can go way beyond perl very quickly.


I would recommend python because the language is simple. It's huge set of modules makes it usable to develop tools and applications quickly. Plus most of the modules are written in python. This is good for examples of how to do "real" things. Because those modules are used in developing applications, you get to see how stuff really should be coded. I have even used the python modules as basis for libraries I've wrriten in other languages. I wouldn't recommend smalltalk because "everything is an object" is taken to the extreme. Java and C++ try to protect the programmer from himself. Alot of times I spend more time fighting with syntax errors and compiler warnings then getting the job done. The language sytax of python removes much of the wasted characters by forcing you to indent blocks of code at the same indentation level. The other nice thing is python also included a set of "functional" programming constructs (map, reduce, filter) which becomes useful in may situations.

As I said, check out the tutorial. If you're having a hard time, do a google search for "python tutorial". There are numerous ones on the web. Some simpler then others. The one on the main python site is just a complete overview. I still look at it when I have questions about something I haven't done in awhile.

q
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 3730
Location: Sweden
Audio files: 275
G2 patch files: 96

PostPosted: Thu Dec 07, 2006 6:43 am    Post subject: Reply with quote  Mark this post and the followings unread

jksuperstar wrote:
Quick OT - I never sat down and learned a good object oriented language, but would like to. Would you recommend python over Java, Smalltalk, C++, etc? I really just want to teach myself how to break problems down into an object based system, rather than the more rigorous methods (like Verilog/HDL languages, C, assembler). I pick up semantics very easily, when I use them, so I figure once I know how to break apart a problem, I can learn another language at another time when needed. But for now, just don't want the language to get in the way, if that makes sense. I've used perl, but only for parsing and text munging, and really only in a C-like fashion, without defining my own methods, etc. It seems the other languages can go way beyond perl very quickly.


This maybe should be kept in a separate topic, since it's flame war-prone. Anyway, personally, I'd say Java is the best bet, avoid C++. One of the greatest assets for Java is the amazing documentation at java.sun.com, I've never seen anything like it - online or in on paper - and it's free. I've been trying to learn Objective-C/Cocoa/XCode on my Mac, and those docs are very hard to wade through, and the interspersed sales pitching only makes it worse.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
cappy2112



Joined: Dec 24, 2004
Posts: 2240
Location: San Jose, California
Audio files: 2
G2 patch files: 1

PostPosted: Thu Dec 07, 2006 11:35 am    Post subject: Reply with quote  Mark this post and the followings unread

Quote:

his maybe should be kept in a separate topic, since it's flame war-prone.
Anyway, personally, I'd say Java is the best bet, avoid C++.

yep- we need to move this thread to a new forum

You can have the best of both worlds with Jython (used to be Jpython)
It is a Python implementation written in Java.

The guy who started it (and mostly finished it),Jim Hugunin(sp?) has been working for Microsoft integrating Python with the Common Language Runtime. (even Bill Gates has seen the light of Python)
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20623
Location: The Netherlands, Enschede
Audio files: 150
G2 patch files: 318

PostPosted: Thu Dec 07, 2006 12:54 pm    Post subject: Reply with quote  Mark this post and the followings unread

Ok, I split this off from the original discussion, see note in topmost post here.

From what I've read sofar the Python object / class mechanism seems to be atypical (more like clever name spaces) but quite powerful.

When the object is to find your way in the OO paridigm there may be languages that are more suitable. However when its work that you want to have done Python seems more suitable than a purist language (like Smalltalk )- to me.

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
qfingers



Joined: Nov 16, 2006
Posts: 183
Location: Tucson, AZ
G2 patch files: 2

PostPosted: Thu Dec 07, 2006 1:19 pm    Post subject: Reply with quote  Mark this post and the followings unread

My suggestion is to try both. I'm not sure what it takes to setup java, but the installation of python is rather simple. Plus the tutorial can be done in a couple of hours. I'm not sure where the java one's are, but I'm sure there are. The python tutorial was written by the author of the language and can speak of the nuances of the language becuase of that. Mind you, I run most my stuff from the command-line because I'm not a big fan of IDE's. They are available for both java and python. Eric is one of python's IDE's and Eclipse is one of java's. Eclipse I think is even a mixed language IDE.

A couple of hours for python and some for java should point you in the direction you want to go. It's still a personal preference. I am very productive in python. That's why I chose it. I program C mostly because I'm a linux kernel, linux driver, embedded system developer. I've built embedded systems with python as the main application because I could squeeze it in less then a couple of megabytes with all I needed to control my device. I'm sure the same could be done in java but that's what I chose.

A little research goes a long way.

q
Back to top
View user's profile Send private message
DrJustice



Joined: Sep 13, 2004
Posts: 2048
Location: Morokulien
Audio files: 3

PostPosted: Thu Dec 07, 2006 4:50 pm    Post subject: Reply with quote  Mark this post and the followings unread

jk, considering your VHDL experience, how about looking at Ada too? It might make you feel at home. Don't be put off by it not being at the top of the language popularity index. It has many other nice features besides its OO support; some of which may appeal to someone with a penchant for logic design.

DJ
--
Back to top
View user's profile Send private message Visit poster's website
jksuperstar



Joined: Aug 20, 2004
Posts: 2488
Location: Denver
Audio files: 1
G2 patch files: 18

PostPosted: Thu Dec 07, 2006 7:10 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks guys for the replies, and sorry for the original OT, but there's times when you decide to do something, and suddenly I start seeing Python mentioned by every website I see. So, I had to ask.

BTW - I'm after creating some OpenGL user interface/front-ends that are OSC capable. At least, that's the goal.
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Dec 08, 2006 10:45 am    Post subject: Reply with quote  Mark this post and the followings unread

jksuperstar wrote:

BTW - I'm after creating some OpenGL user interface/front-ends that are OSC capable. At least, that's the goal.


That sounds very interesting! If at all possible I'd like to hear about your progress and findings (asuming this isn't something that invloves non-disclosure thinges), I imagine the Max, SC and ChucK fanatics around here would all love to hear about what you are doing as well. Great plan!

If you are after OpenGL and OSC this might be worth a look; http://www.pawfal.org/Software/fluxus/

But I'm not sure how OO it is because I'm neither a expert in OO nor FLuxus (though interested in both...)

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 17618
Location: Allentown, PA
Audio files: 125
G2 patch files: 60

PostPosted: Fri Dec 08, 2006 11:46 am    Post subject: Reply with quote  Mark this post and the followings unread

Arrgggg. On this web site I have been supporting applications in Python, Perl, Java, Javascript and PHP (also Flash, but that's something completely different). Kyma is written in Smalltalk so I have used it a bit too. People have been very skilled at developing unreadable code in all of these languages. Rolling Eyes

OO can sometimes make code much more complex than necessary. I think it is overused. Python and PHP both have good approaches to OO. It is available if you need it, but it doesn't get in the way if you don't.

_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Dec 08, 2006 12:40 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yeah, that's true but you can make unreadable code in anything. I think OO coding also has the potential for extremely readable code. It mainly depends on making good and sensible abstractions which is basically the core of any coding issue anyway.

It's not like writing everything into one great straight flow-controled loop will inherently make it readable....

Excepting Perl, of cource, I have yet to see any readable Perl.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
DrJustice



Joined: Sep 13, 2004
Posts: 2048
Location: Morokulien
Audio files: 3

PostPosted: Fri Dec 08, 2006 1:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

mosc wrote:
OO can sometimes make code much more complex than necessary. I think it is overused.

This I have to agree with. There is quite a bit of untimely and/or badly applied OO out there. A good procedural solution is better than a bad OO solution - OO is a good thing but not a panacea. There is a time and place for everything.

Quote:
Python and PHP both have good approaches to OO. It is available if you need it, but it doesn't get in the way if you don't.

A bit like Ada in this respect then (and totally different in others...). (Yes, I'm an Ada fan Smile)

And Kassen - yes, if there is one thing I have learnt in all these years: readability is king!

DJ
--
Back to top
View user's profile Send private message Visit poster's website
jksuperstar



Joined: Aug 20, 2004
Posts: 2488
Location: Denver
Audio files: 1
G2 patch files: 18

PostPosted: Sat Dec 09, 2006 12:47 am    Post subject: Reply with quote  Mark this post and the followings unread

readability is absolutely king, which is one reason why I've found a liking to python already...indents are consistent! that goes a long way (for me) to reading a file. When at work, and I have to pick up someone else's code, the first thing I do is make all the indents consistent and turn on emac's colorization. Ahh, like breathing clean air!!

Kasson wrote:
If at all possible I'd like to hear about your progress and findings


I'm currently finding Pd's GEM and GRiPd nice, but damn ugly. And not exactly what I want, either. What I really find is hardware interfaces limiting, but necessary (limiting - I don't want to carry around 100 pieces of gear to accomplish playing drums, sequencing, patterns, melodies/harmonies, multi-dimensional parameters, etc)(necessary, touching/feeling is as much a part of improvising music as is hearing, there's a completely different energy for me when I click a mouse or type, vs. turning a knob, or hitting pads). But, I really like some of the multi-touch graphical interfaces popping up (especially the DIY kind), and would like to tie that approach together with hardware. Don't ask me exactly how, just yet. I don't know. But I would like to see what I can do with graphics, and it seems OO programming is the only feasible method for handling graphical objects, especially representative ones. Of course, it still has to be fast, because I don't like pauses of any kind in my interfaces. Maybe that's why I'm an embedded designer. Or vice versa.

For example, I'd like multi-track pattern sequencers to look like a loop (round/oval), with concentric circles (1 for each track, so you can see timing). With variable resolution so I'm not stuck looking & working with a 16 step sequencer, but wanting to use triplets in a 17-step pattern, and also want to edit the note length of each output step (ie- note of beat 1 is a whole note, but beat two is a quarter note). ie- A sequencer that needs a polyphonic sound source to be heard. I'd also like to be able to zoom "out" and see the whole pattern, then zoom in to tweak 32nd note flams or ghost notes (typically sub-resolution to most pattern sequencers). A multi-touch interface (like the many videos circulating around here lately) would be a beautiful thing. Currently this is all a labored process even in a fast editor such as Live. But I'd like to make it improvisable. And natural. Like the way you feel when you pick up a drum...it's just understood what you are "supposed" to do to play it.
Back to top
View user's profile Send private message Visit poster's website
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20623
Location: The Netherlands, Enschede
Audio files: 150
G2 patch files: 318

PostPosted: Sat Dec 09, 2006 6:39 am    Post subject: Reply with quote  Mark this post and the followings unread

jksuperstar wrote:
When at work, and I have to pick up someone else's code, the first thing I do is make all the indents consistent


I thought I was the only "fool" doing so .. but it's the only way for me to get into someone else's code.

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
DrJustice



Joined: Sep 13, 2004
Posts: 2048
Location: Morokulien
Audio files: 3

PostPosted: Sat Dec 09, 2006 9:41 am    Post subject:   Reply with quote  Mark this post and the followings unread

Blue Hell wrote:
jksuperstar wrote:
When at work, and I have to pick up someone else's code, the first thing I do is make all the indents consistent


I thought I was the only "fool" doing so .. but it's the only way for me to get into someone else's code.

That's just about the least foolish thing you can do to a badly formatted piece of adopted source. There has been conducted a bit of research about source code comprehension, and the scanning of the left hand margin is the number one cognitive aid to structural comprehension. Personally, I'm slightly obsessed with formatting; the code has to look beautiful in such a way that you can clearly see the mechanics of it, and that is a real help both in avoiding errors at the time of writing as well as effortlessly understanding it later on.

DJ
--
Back to top
View user's profile Send private message Visit poster's website
kkissinger



Joined: Mar 28, 2006
Posts: 1218
Location: Kansas City, Mo USA
Audio files: 29

PostPosted: Sat Dec 09, 2006 10:36 am    Post subject: Reply with quote  Mark this post and the followings unread

DrJustice wrote:
Blue Hell wrote:
jksuperstar wrote:
When at work, and I have to pick up someone else's code, the first thing I do is make all the indents consistent


I thought I was the only "fool" doing so .. but it's the only way for me to get into someone else's code.

That's just about the least foolish thing you can do to a badly formatted piece of adopted source. There has been conducted a bit of research about source code comprehension, and the scanning of the left hand margin is the number one cognitive aid to structural comprehension. Personally, I'm slightly obsessed with formatting; the code has to look beautiful in such a way that you can clearly see the mechanics of it, and that is a real help both in avoiding errors at the time of writing as well as effortlessly understanding it later on.

DJ
--


Like you, I do the same thing when I have to slog through poorly-designed and poorly-documented code.

Once I have the indentations worked out, then I put in comments.

Often, just working out the indentations reveals that the logic can be simplified.

Code:
          BCT  RG1,*   assembler language is efficient  (sometimes)
Back to top
View user's profile Send private message Visit poster's website
play



Joined: Feb 08, 2004
Posts: 490
Location: behind the mustard
Audio files: 2

PostPosted: Wed Feb 07, 2007 11:09 am    Post subject: Reply with quote  Mark this post and the followings unread

Sort of on both topics, another reason why python is great is the auto-documentation features, right from the interpreter. Got some unreadable source? Just help(module) and you can get a quick overview of the interface.

I program in python and c++ mostly but I like to play around with a lot of different languages. I'd say the language you use depends on the domain of the problem you are trying to solve, what libraries are available or easily ported and also on personal preference. That said, python is by far a better language for beginners than c++ or java if only because there is no compile step so the whole trial and error cycle is much faster.

For audio processing, python is tricky though. It's hard to get good performance. I wrote a python wrapper for the RtAudio library only to discover that python just couldn't perform well enough for complex applications. Although this guy seems to be doing ok: http://www.patrickkidd.com/pk/trac/wiki
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: DrJustice
Page 1 of 1 [17 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Developers' Corner
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use