ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I program for a living.
Mostly small tools, filters, file parsing and reporting, XML
general purpose.
I reckon perl and python.
I have found:
perl is often faster than C if you put proper error checking and stuff for file opens in. But essentially the speed difference is minimal and easily outweighed by the power.
so i rarely use C (haven't since found perl) as i can knock up fifteen perl tools in the time to do one in C.
have started to learn python too and i think it's a beautiful language.
It seems more more maintainable; perl gets really ugly
with complex data structures (all lists are flat) and can
often be unreadable even by myself after a few weeks.
(and I am careful to make maintainable code)
practically, 99% of unix boxes have perl and most in my expereience don't have python.
I do not agree with you... I beleive that every code can be very well-organized and very massy too not depending on the programming language. I guess it depends on the programmer. I usually create a documentation for my works to find everything later if I have too.
What you told about the speed of perl is amazing. I knew that it is that fast but I did not know that this is that fast. ^_^
There is one more issue I would like to speak about... Some people beleives that perl is already a dead language, nobody uses it nowadays. Is it true? Do you thing that perl will ever disappear or sth. like this?
Do you thing that perl6 will be a huge change? I read a few thing about the parrot or how thay call it. What is the main difference bw. perl 5 and perl 6?
If you want to learn a language with a bit of chest hair, check out LISP. It's a scripting language, but it can be translated into the assembly mnemonics through the COMPILE function.
Perl was the first language I ever learned, and I still use it from time to time for small tasks (converting all files in pwd of type a to type b). I've constantly been itching to learn C and/or C++ and everytime I finally muster up the courage to sit down and try to learn it, I just fall apart (usually when it comes to pointers). I thought my Perl knowledge would have helped, absolutely not. Over the years I've learned other languages like QBASIC, VB, Gambas, and Java. While three of those languages are BASIC derivatives, they're all extremely different from one another.
QBASIC/QuickBASIC, I love the language, the only problem is that it's dead. It's old, no longer supported by the company that implemented it (Microsoft), but still a fun and easy language (not object-oriented by any means, but then again, by definition, neither is C).
VB. Arguably the object-oriented evolved entity of QuickBASIC. The only was that it got tricky to do certain tasks in an efficient amount of LOC. And it incorporated GUIs, which was really nice.
Gambas is the Unicised version of VB. However, I find it to be less like BASIC, and more like some wierd hybrid between C, C++, Java, and BASIC (with more emphasis on C, C++ and Java).
As for Java, I have really mixed feelings about it. It's about as object-oriented as any language could get. Perhaps a bit too object-oriented; everything's an object. While I like it for creating console-based applications, graphical applications are a whole new world of drudgery and inane boredom...excuse me whilst I mop up the puddle of brains.
Over the years, too, I've grown tired of finding nothing but languages that are based off of other languages. I eventually looked at LISP, and it's rather odd - yet graceful - syntax intrigued me. I decided to give it a shot, and I've yet to be let down. Programs that would normally take me several hundred lines of declarations, functions and loop structures are done effortlessly and seamlessly in LISP. Yes, LISP is a REALLY old language, but there's a reason it's still around. The only precaution I feel the need to mention is it's syntax structuring: in C/C++/Java a variable declared once is forever, within that method, declared. Not true in LISP. Here's a comparison: defining a variable and referencing it each time through an infinite loop.
Code:
// Java
public class Test {
public static void main(String[] args) {
int i = 0; // i is defined here.
int limit = Integer.parseInt(args[0]);
boolean b = true;
while (b == true) {
System.out.println(i);
i++; // it still exists here
if (i > limit) break;
}
System.out.println(i); // and it still exists here
}
}
----------------------------------------
;;; LISP
(defun test-function (limit &rest values)
(let ((i 0)) ; Here, i is defined.
(loop
(format t "~a~%" i)
(incf i)
(if (> i limit) (return))))
(format t "~a~%" i)) ; Here, i isn't defined, and you'll get thrown an error.
LISP is a supremely fun language. I recommend giving it a shot. Like you, vargadanis, I've been caught up weighing languages against each other, but in the end, I just use LISP. Some things in LISP seem scarily easy, and that's because they are. All I can say is, if you decide to learn LISP, you're going to have to remap your logical pathways from the C way of thinking to the LISP way of thinking (the world makes a lot more sense for me now ).
If you decide you'll take a look at LISP, email me at nicksaika <at> gmail <dot> com, and I can send you a few eBooks I've found on LISP and detailed instructions on how to get set up with LISP.
Well, I used to use C years ago and liked it, but when I moved onto Perl it certainly made my life easier/quicker as a lot of the fiddly stuff in C is handled for you by Perl itself.
As for the speed qn, if you really want to know what's going on behind the scenes, take a look at this: http://www.perl.com/doc/FMTEYEWTK/comp-vs-interp.html
Personally, I really like having hashes as a basic data type in Perl. Anytime I want to represent a data structure (and this happens a lot), it means I can used named fields, instead of multi-dimensional arrays and having to remember what rec/field $arr[0][1][3] represents. Kind of self-documenting.
Also, of course, I can index straight into it when looking for an entry.
I can assure vargadanis that Perl is very much alive and heavily used, it's just not trendy like eg Java, PHP.
It's used a lot in the background by sysdamins and DBAs and data massaging programs.
Checkout http://www.perlmonks.com/ and search.cpan.org (pre-written perl modules to save you re-inventing the wheel).
Nonetheless, pick the lang that you think best suits the problem, unless it's dictated by where you work.
Keep in mind there's a limit to how many you can know well. (and your colleagues/successors).
all the above depending on the implementation ;-)
I use clisp
which i usually compile to byte-code.
I think you can compile to binary but it's lots more work
defining types and stuff so it gets boring.
That is why i like lisp, not much effort for lots of result.
I like sbcl myself, it compiles into full ELF executable pretty easily. I'm actually trying to learn both lisp and Ruby in a useful way right now. What I've noticed is that Ruby is essentially lisp with M-expressions instead of S-expressions. Ruby just doesn't have the same level or orthogonality than lisp because of that.
Java as a language is really bad with code density. Also, doing the loop that way is really, really bad form. In C, a simpler functionally identical program is
Code:
#include <stdio.h>
int main(int argc, char **argv)
{
int i = 0;
int limit = atoi(argv[1]);
puts("0");
while(i++ < limit)printf("%d\n", i);
}
Unlike in Java, where things exist until the java GC gets around to cleaning things up, in C++, you can see exactly where an object is created and exactly where an object is destroyed. One of the really cool things about that is that the file objects will automatically close themselves at the end of scope, like
Continuing on scope, the more correct way to write the Java version to act like the lisp version is to make sure you have all the right scope, like
Code:
// Java
public class Test {
public static void main(String[] args) {
{
int i = 0; // i is defined here.
int limit = Integer.parseInt(args[0]);
boolean b = true;
while (b == true) {
System.out.println(i);
i++; // it still exists here
if (i > limit) break;
}
}
System.out.println(i); // Compile error
}
}
I want to learn perl or ruby or python but I do not know which one is the best.
It's a little like asking someone what their favorite film is, IMO. All a matter of opinion, because the three languages are comparable in many ways.
So here's my opinion, FWIW:
perl is ok, not great. Frequently tagged as a write-only, difficult to maintain language. Maybe that's not very fair. In any case, I don't care for it.
python is an easy to learn, easy to read (by virtue of compiler/checker-enforced whitespace), productive language.
ruby? Probably very similar to python, but I was introduced to python first so that is my preference.
perl is a wonderful thing. you just need to persevere. It's really worth it.
when I first tried vi years ago i was a small boy using windows 3.11
and i hated and detested it with a deep and profound loathing.
I felt the same about perl when I first tried.
now i love them both and even invited them to my wedding
I am partial to Perl since I have been working on and then with the WebAPP Network Team at web-app.net
Its where the WebAPP Perl Portal is developed... you guys should check it out...
It is a great script to play with to get you energized about perl... I see it all the time that phpers and other programming language users start messing around with the script and get into Perl big time...
of course the beauty there is then they contribute back and we end up with an even better portal script
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.