LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-04-2010, 09:13 AM   #1
chutsu
Member
 
Registered: Nov 2003
Location: UK
Distribution: Debian Lenny
Posts: 255

Rep: Reputation: 31
Science/Engineering programming - Which is easier in extending C? Python/Ruby?


I've gotten to learn the basics of both languages (functions, loops, classes), and learned love both. However I have come to a point where I need to know which is easier to write C extensions to do the "heavy lifting" (ie. intensive calculations). I therefore am posting this question here to seek some advice on this.

So! What are thou thoughts?
 
Old 06-04-2010, 04:21 PM   #2
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by SweetChris View Post
However I have come to a point where I need to know which is easier to write C extensions to do the "heavy lifting" (ie. intensive calculations). I therefore am posting this question here to seek some advice on this.
I'm not quite sure what you mean by C extensions with regard to intensive calculations. Do you mean extensions like for example OpenMP or the (Open)MPI framework to realize parallel calculations? Or do you just mean libraries which do some intensive stuff like say (solving systems of linear equations) encapsulated within these libraries?

Maybe, you could give some more specific examples what you think about?

Andi
 
Old 06-04-2010, 04:30 PM   #3
chutsu
Member
 
Registered: Nov 2003
Location: UK
Distribution: Debian Lenny
Posts: 255

Original Poster
Rep: Reputation: 31
What I meant was to write libraries in a different language to the glueing language. In this case I would like to use C libraries or Programs and integrate them to Python per se.

The term both Python and Ruby programmers use are "extending" with C.
source:
Ruby -> http://www.rubyinside.com/how-to-cre...nutes-100.html
Python -> http://docs.python.org/release/2.5.2/ext/intro.html

I was hoping if someone has done both, can tell me how easy it is to transform a complex C library to work in either of these programming languages.

Hope that helps
 
Old 06-04-2010, 04:57 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by SweetChris View Post
What I meant was to write libraries in a different language to the glueing language. In this case I would like to use C libraries or Programs and integrate them to Python per se.

The term both Python and Ruby programmers use are "extending" with C.
source:
Ruby -> http://www.rubyinside.com/how-to-cre...nutes-100.html
Python -> http://docs.python.org/release/2.5.2/ext/intro.html

I was hoping if someone has done both, can tell me how easy it is to transform a complex C library to work in either of these programming languages.

Hope that helps
For that matter, look also at http://search.cpan.org/~ingy/Inline-0.44/Inline.pod , as well as http://www.swig.org/ .
 
Old 06-04-2010, 05:30 PM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Why not just do your entire scientific/engineering program in either C or C++ and obviate the need for glue functions to libraries?
 
Old 06-04-2010, 07:10 PM   #6
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
I've seen too much code written by scientists to trust them with C or C++, and I barely trust them with Python.

For C++/Python binding, I rather like Boost Python.

Last edited by tuxdev; 06-04-2010 at 07:12 PM.
 
Old 06-05-2010, 09:05 AM   #7
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by tuxdev View Post
I've seen too much code written by scientists to trust them with C or C++, and I barely trust them with Python.
I've seen too much code written by scientists to trust them with Python. C++ is safer.

In the moderate size sample of scientists and large sample of code that I have seen:

C and C++ code is written to either look like Fortran code or look like Matlab code. It is outrageously inefficient, defeating the point of coding it in C++ rather than just leaving it in Matlab. But it is organized, understandable and repairable (after profiling).

Python code is outrageously anti structured and scattered. It is incomprehensible and unrepairable.

Obviously, this depends significantly on the individual programmer. But a large part of it is in the language design. Python makes it very easy to violate the "encapsulation" concepts of object oriented programs to levels of disorganization that I don't think you would believe without seeing. Before I saw any Python code, I objected to the level of encapsulation pushed by languages like Java and C++ because sometimes that encapsulation makes the program structure worse and because a competent software engineer would encapsulate when appropriate even if the language doesn't push that. After seeing the abuses common in Python code from total anti encapsulation, I have a better appreciation for language features that recognize most people writing software aren't actually competent at it.
 
Old 06-05-2010, 10:47 AM   #8
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
I'm a scientist and I write good C code. Also good Fortran code. And good Matlab code.

Though, I must admit I've run across some really badly written code that was done by scientists.

But, then, I've also run across very badly written code in the FOSS world too, and more than once I've undertaken a project (when the money is right and I was in the mood) to fix a PHP website that had been "programmed" by someone who obviously didn't know what he was doing.
 
Old 06-05-2010, 01:33 PM   #9
ArthurSittler
Member
 
Registered: Jul 2008
Distribution: Slackware
Posts: 124

Rep: Reputation: 31
Octave has most of functionality of Matlab

You may wish to go the other direction. That is, start with a higher level language better targeted at task at hand and drop into a lower level language when you need functionality that is not provided by the higher level language.

Octave, developed as free open source software, provides the functionality of MatLab. Like MatLab, Octave permits extension functions written in C. Octave is a higher level language than C better suited to engineering problems.

I concur with your opinion about C written by scientists. I have seen a lot of software written by scientists that did not meet any reasonable standard of good programming practices. That sword cuts both ways. I have also seen software written by good programmers that is weak on the engineering and scientific implementation. The problem is that it takes a lot of time to become a good programmer and a lot of time to become a good scientist and a lot of time to become a good mathematician and a lot of time to become a good engineer. We also do other things in our lives.

I laud your efforts to become one of those rare persons who develop a deep understanding in several of those fields. It is a lofty goal, yet not unattainable. The people who succeed in developing expertise in multiple fields bridge the gaps between those fields. It also could be more than a little frustrating, because the most likely scenario in the work place is that you will end up working in one of your fields of expertise to the neglect of all the others that you have developed, with considerable investment of your resources.

I personally understand ones and zeroes and I also understand poles and zeroes. Yet what I have ended up doing is working on fixing up badly implemented software, digital hardware, and analog circuitry designed by nominal experts in each of those narrower specializations.

This is just my opinion, of course. I can not claim to be any authority on the subject.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Practical Programming: An Introduction to Computer Science Using Python LXer Syndicated Linux News 0 06-30-2009 10:40 PM
Engineering/Science/Tech Job Recommendations R00ts General 4 05-03-2007 07:32 PM
Computer Science vs. Software Engineering microsoft/linux General 17 04-20-2005 11:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration