Skip to main content
Welcome guest. | Register | Login | Post

Better lang?

14 replies [Last post]
Offline
Joined: 2005-12-20

Hi,

What would be a better language to learn for CLI programming, something easy, to the point that works please Smiling

i really have no idea

supermike's picture
Offline
Joined: 2006-02-17

CLI is probably owned by Perl on the Linux platform. It has the widest array of libraries, the largest network of free code sharing, and runs about the same on Linux, Unix, Mac, and Windows, etc. But, it looks a bit like Bash and isn't my forte. I do see some strengths in Bash and Perl and use it when appropriate. Instead, for almost 96% of my work on my servers, I use PHP for all my CLI coding. You have to call it like:

$ php -d max_execution_time=10000 -q "myscript.php"

with PHP4. I think PHP5 is a little easier. Also, midstream in PHP4 development, the errors generated from PHP CLI switched from HTML output to being more CLI friendly without HTML tags. So, depending on which version you have of PHP4, you could get ugly HTML errors when you have an error, or pretty command-line messages. As well, I think some of the php -switches have changed here or there, so you have to do php -h or php --help to see what works and what doesn't. The -d max_execution_time is to allow my script to run a bit longer than the average website page. Website pages should run fairly fast, you see, but scheduled jobs you run at CLI often could take as much as 15 minutes, depending on what you're doing.

I've become much more adept at PHP than any other language since VB6, so I leverage that at CLI.

dylunio's picture
Offline
Joined: 2005-12-20

onlinebacon, I don't realy know which language you should learn, but continuing from supermike, you may find this usful: http://www.ascentsoftware.org.uk/ it's aimed at school kids our age, so it should be cool.

dylunio

free-zombie's picture
Offline
Joined: 2006-03-08

first of all, what is your programming expierience ? I am assuming you can not program at first; more later

I'm all for python. I think it's a very nice and easy language. A saying goes "python comes with batteries included": you have a lot of well documented functions in the standard python library and there are numerous other python libraries available; I find that debian includes a fairly large set. Python wins for me with elegant and simple syntax; it uses strict (but implicit) typing, which is a good practice, but can make things more difficult. Python will also run the same on different platforms

Perl - it lets you do whatever you want in 10.000 different ways and has/encourages ugly, not easily readable code. I hate it for that reason, However, Perl is very widespread and has a sheer endless fundus of libraries available, meaning coding in perl can be faster. It is dunamically typed, that is you can basically forget about types. However, if you get into this habit, it may be difficult to pick up strictly typed languages later on, but I cannot say, as I grew up with strictly typed Microsoft languages.

PHP can be seen as a cleaner, more limited, simpler perl. The syntax is similiarly C-style. PHP was originally meant for web programming, and is geared to that area more than command line programming AFAIK. dynamically typed as well.

I have also heard a lot of good about Ruby. I don't know much about it, though.

Summary: I love and would recommend Python, I hate Perl, I have my doubts about PHP+non-web, Ruby is prolly good as well.

If you already know how to program in another language, I can recommend http://diveintopython.org/ (good book to learn python as a programmer. got it in print)

-- fz

Offline
Joined: 2005-12-20

Ok, cool, it is either php, python, perl or bash, i will give all three a shot and see what i prefer Smiling

And thanks for the linux dylunio, it rocks

supermike's picture
Offline
Joined: 2006-02-17

The thing that kills me about Python is the PyGTK interface. Sometimes you have to do the oddest things to achieve an effect. And the API is not entirely consistent in PyGTK like you would thing. Some similar widgets may have two completely different ways to write to a "label" property inside it, to give a roundabout example.

I came from the Microsoft environment where, for most people, the only way to get things done productively and fast was to do it in VB. It had become like a one-language world for a great while there. So I'm more of a fan of sticking with a language and not varying from it, whenever I can. That's why I've invested so much time in my PHP skills over Perl, Python, or Bash.

Besides, Perl and Bash have the strangest ways to do string comparisons and conditional logic on files. It's unorthodox. I prefer the C, Python, and PHP syntax for such things.

free-zombie's picture
Offline
Joined: 2006-03-08

hmmm... I also come from Visual Basic Eye
I don't do much GUI in python. The litte I've done was with Glade (keeping a safe difference from raw GTK and TkInter (in that situation the only choice... a wiser choice would have been pygame, but w/e) I might add that PyGTK is by far not "the" python GUI toolkit... my guess is that Tkinter is most used, after it wxPython, which is better than GTK on windows (GTK on Windows is, from what I have heard, not very good (it stops some people from using Gaim...). I might have a look at PyQT in future.

Ok, couldn't help defending the language I have been known to call sexy Eye GUI isn't what onlinebacon is after anyway...

tbuitenh's picture
Offline
Joined: 2005-12-21

Everyone has their personal preferred language in which they can solve problems most quickly. Mine is Python, but I think that might change soon. Python2 isn't Python1, it has started suffering featuritis. Yes, those list expressions (such as [(x,x*x) for x in range(1,10)] ) are very neat for writing code quickly, but they don't exactly make your program readable, and readable code used to be one of the big advantages of Python.

PHP - it is very popular for websites, but it has grown away from its original design and purpose. Nowadays it is said you shouldn't do things like

<?php if (condition) { ?>
some html
and some more
...
and even more
<?php } ?>

But do

<?php
if(condition) {
echo "some html\nand some more\n...\n...\n...\nand even more";
}
?>

instead. But why not use perl then???
I used to think PHP outside the web is a silly idea, but if it's just another scripting language, then why not... Except for the fact that my first thought will still be "silly idea" for the rest of my life.

Perl - I don't like it. 1000 ways to do the same thing, 999 ways to make your code unreadable.

Bash - it works. Also consider tcsh, it can do about the same things, but sometimes it's easier. I hear zsh is even better than both.

Tcl - not bad at all. It's old, which makes it uninteresting for the crowd who always wants the newest language even if it's worse than what they already had.

All these are scripting languages. You should learn one of these, and also both C and C++.

supermike's picture
Offline
Joined: 2006-02-17

PHP has grown and continues to grow. It's branched away from the web. I use it for ordinary scripts that:

* Check status of our FTP and web servers.

* Pull data from one system on HTTP, uncompress it, and email it out to clients.

* By using PHP to parse the syslog file, I can check disk space and all other events, including security logs, on all our Linux, Unix, and Windows servers, filter this information, and produce not only web pages and charts, but email a core set of admins about it. (Thanks to SNARE syslog forwarding agent.)

free-zombie's picture
Offline
Joined: 2006-03-08

"Pull data from one system on HTTP, uncompress it, and email it out to clients."
uh... that sounds like a shell one-liner Sticking out tongue

supermike's picture
Offline
Joined: 2006-02-17

Yeah, that would be one heck of a wicked one-liner! Unfortunately there's some business logic to be applied, as well as different email addresses per certain rules, etc.

Offline
Joined: 2006-03-28

I also use PHP for quite a lot of things, web and non-web.
Most of the time I use it non-web is to test a few things. Anyway, I'm always testing new things in order to enhance my knowledge about what you can do with PHP and to let my script-collection grow. Laughing out loud
My only CLI-only script is a ping, since this requires to run as root to create the socket.
Then there's some scripts which I usually use in the web-server but sometimes also run on the CLI.

I'm also running a project on Sourceforge offering some handy classes for PHP5. I think I'm going to extend this soon by offering the PHP4-versions of these classes and also some other scripts too. Also have to get the rest of my classes ready to publish.
Maybe you like to have a look at it, and maybe you find something useful for you: http://www.sourceforge.net/projects/php-classes

PHP can do a lot of nice and useful things, also on the CLI. And it's easy to use. I guess with readline you could even get PHP ask you for some values while it's running so that you don't need to pass everything as parameter. Also there's PHP-GTK, but I don't really know what to think about it. PHP for CLI and web is okay, but I think it doesn't need to go GUI.

libervisco's picture
Offline
Joined: 2006-05-04

PHP is pretty much becoming a must for me considering that most of web applications, and all that I currently use, are written in php, so there.

But I like bash. I think it wouldn't be hard to learn to do more advanced bash scripting. It's all rather straightforward if you're used to the bash terminal, which most of us are.

Offline
Joined: 2005-12-20
90% of the time I use shell

90% of the time I use shell scripts. I don't care one bit for perl, and php is very useful too. Though I really like good, small, and efficient C. Coreutils, for example, is a load of bloat. Take a look at the basename program. A replacement could be written in about 10-15 lines max. Back to php though, it's awesome. Install the cli binary, then just put #!/usr/bin/php up top of the scripts and mark them exec.

libervisco's picture
Offline
Joined: 2006-05-04
Funny I haven't yet tried

Funny I haven't yet tried php command line. I suppose I should set that up ASAP considering I have to learn php. Smiling

Having a command line for a language and using it to test certain commands is probably a great way to learn.

Comment viewing options