SIGforum.com    Main Page  Hop To Forum Categories  The Lounge    Need advice for a scripting language
Go
New
Find
Notify
Tools
Reply
  
Need advice for a scripting language Login/Join 
Baroque Bloke
Picture of Pipe Smoker
posted
I use SPITBOL to write my programs. That’s not going to change.

SPITBOL is an ancient, but wonderful, language that few know of today, and it fits my way of thinking. But it has limited facilities for interaction with the OS (macOS in my case).

So I also use scripting languages. I’ve used ‘bash’ as my terminal shell for 30 years, so no surprise that my scripting language is bash. Very direct.

But bash isn’t a great language, to put it politely, so I’m looking for something better. Years ago I was reasonably proficient with ‘perl’, so reacquainting myself with perl is one possibility. But I’d like to know of other options.

One option that I wonder about is ‘python’. I’ve never written a single program in python, but I know that it’s immensely popular nowadays. I have experience with many programming languages, including some obscure ones, so I’m sure that I could learn python.

So, two questions:

Question #1: Is python a viable option as a scripting language?

Question #2: Suggestions for a scripting language other than perl or python?

BTW – I suppose that ‘zsh’ scripting might be better than bash scripting (I don’t know). But even if it is I’d likely stick with bash for my terminal shell.



Serious about crackers
 
Posts: 9699 | Location: San Diego | Registered: July 26, 2014Reply With QuoteReport This Post
Optimistic Cynic
Picture of architect
posted Hide Post
quote:
Originally posted by Pipe Smoker:
So, two questions:

Question #1: Is python a viable option as a scripting language?

Yes

quote:
Question #2: Suggestions for a scripting language other than perl or python?
Lots of programmers sing the praises of Ruby. Not really a scripting language, but interpretive JIT compiled. I'm a little surprised that you haven't felt the siren song of JavaScript. And, of course, there is also the formidable Lisp/Scheme world.

quote:
I suppose that ‘zsh’ scripting might be better than bash scripting (I don’t know). But even if it is I’d likely stick with bash for my terminal shell.
I'm a csh/tcsh guy myself, but nothing wrong with bash once you get used to the syntax. For utility working with various assemblages of data I usually turn first to awk, sed, and their friends before tackling an actual procedural script.

WRT to Python, I first got acquainted with hands-on Python by having to maintain a Mailman mailing list manager instance. This, to my mind, was a far more gracious introduction than manuals/tutorials, etc. Look for a substantial piece of software written in the language that interests you, and start hacking on the code base.
 
Posts: 6937 | Location: NoVA | Registered: July 22, 2009Reply With QuoteReport This Post
Member
posted Hide Post
Python is definitely a viable option.
 
Posts: 2384 | Registered: October 24, 2007Reply With QuoteReport This Post
member
Picture of henryaz
posted Hide Post
 
The current default shell on MacOS is zsh (since Catalina). You can, of course, change it back to bash.
 
I do not program, other than extensive shell scripts, but I understand python is an excellent choice. I have occasionally dabbled with editing existing python scripts for my needs, and the language appears fairly straightforward. As of Monterey 12.3, python is no longer included in macOS, but you can easily install the latest version.



When in doubt, mumble
 
Posts: 10887 | Location: South Congress AZ | Registered: May 27, 2006Reply With QuoteReport This Post
Member
Picture of wrightd
posted Hide Post
Read architect's response to your OP post, he's exactly right on everything. I started out with Perl, wrote a large Deverlopers' code compilation and dev/test/prod deployment tool using it, and it works, but later went in to maintain it, and found it a little painful because though the syntax is extremely powerful, it can be confusing unless you use it all the time. After that I tried Python on another software engineer's recommendation, and I've been hooked on in since. It's just as powerful and flexible as Perl, and has LOTS of support and free downloadable plug-ins, but is orders of magnitude easier to read and code, my guess is you'll love it. And it talks to the OS using multiple techniques, and all those techniques are pretty elegant, and not frustrating or confusing at all, you won't need to write your own wrapper to do so, unless you want to. I didn't need to and my scripts talk to the opsys and other systems and utilities a LOT, since I'm a server side guy.

I've never known anyone to abandon Python for something easier unless their use case needed a different language. So for all kinds of general and special use cases, you should give it a try.

I've heard good stuff about Ruby as well, but I've been so tickled w/Python I never bothered to try it.




Lover of the US Constitution
Wile E. Coyote School of DIY Disaster
 
Posts: 9091 | Location: Nowhere the constitution is not honored | Registered: February 01, 2008Reply With QuoteReport This Post
Serenity now!
Picture of 4x5
posted Hide Post
I'm a software engineer by day, university instructor by night. I recently started teaching a beginning programming course using python, and I have to say, I am VERY impressed with what python can do, and how dead-nuts easy it is to use. In python, I can have a semi-complicated app running in a fraction of the time it would take to do in C#. It's a great language!



Ladies and gentlemen, take my advice - pull down your pants and slide on the ice.
ʘ ͜ʖ ʘ
 
Posts: 4950 | Location: Highland, UT | Registered: September 14, 2006Reply With QuoteReport This Post
Caught in a loop
posted Hide Post
I work in cyber security. All of our daily/weekly scripts are written in Python. I'd say that makes it pretty viable. Cool


"In order to understand recursion, you must first learn the principle of recursion."
 
Posts: 3390 | Location: Memphis, TN | Registered: August 23, 2010Reply With QuoteReport This Post
Baroque Bloke
Picture of Pipe Smoker
posted Hide Post
Thanks for the informative and thoughtful replies. I'm thinking that
python is in my future. But just to be clear, I present a simple bash
scrip, 'find_includes', below. In this case bash is perfectly adequate,
doing the job simply and cleanly. Would a python script do this easily
too?

== the script ======================================
#! /bin/bash
# $Id: find_includes,v 1.23 2022/11/23 23:06:05 doug Exp $

####################################################
# This script lists paths to all files in and below
# ~/Documents that "INCLUDE" the arguement function.
# Paths that have '/RCS/' are excluded.
# Paths that have '/Funcs/' are excluded.

# Example: bash> find_instance commafy >.hits
####################################################

pushd ~/Documents >/dev/null
egrep -I -R \
--exclude-dir 'RCS' \
--exclude-dir 'Funcs' \
. -e"^-INCLUDE 'Funcs/$1.fun'" 2>/dev/null \
| grep -v 'Functions/functions'
popd >/dev/null
===============================================

== An example invocation ===========================
bash{5}> find_includes dollarfy
./Stuff/BWM/weekday.sbl:-INCLUDE 'Funcs/dollarfy.fun'
./Stuff/Spitbol/Lib/Functions/Tests/dollarfy.sbl:-INCLUDE 'Funcs/dollarfy.fun'
bash{6}>
===============================================



Serious about crackers
 
Posts: 9699 | Location: San Diego | Registered: July 26, 2014Reply With QuoteReport This Post
Member
posted Hide Post
IMHO, probably not, in this example.

I started with Bourne shell and went to ksh, bash, tcl, perl, python, ruby, and even PHP for system scripting. Yep, PHP can be run as a local script without web things. No, it's not the greatest at that. That's another story.

I say probably not because egrep is already pretty optimized for reading and string matching, so it will be pretty fast. At least, until it starts making sense to multi-thread/process to quickly chew through a large number of files. I guess we'd need to code golf it all to find out for sure.


--
I always prefer reality when I can figure out what it is.

JALLEN 10/18/18
https://sigforum.com/eve/forum...610094844#7610094844
 
Posts: 2427 | Location: Roswell, GA | Registered: March 10, 2009Reply With QuoteReport This Post
Member
posted Hide Post
quote:
Originally posted by 4x5:
I'm a software engineer by day, university instructor by night. I recently started teaching a beginning programming course using python, and I have to say, I am VERY impressed with what python can do, and how dead-nuts easy it is to use. In python, I can have a semi-complicated app running in a fraction of the time it would take to do in C#. It's a great language!


Interesting observation. The development team I manage / code (we basically write APIs that do tons of db reads-writes) has twice evaluated Python and rejected it in favor of C#. To be fair, our apps do fall into the complicated range. Maybe we should take a 3rd look at Python?
 
Posts: 7782 | Registered: October 31, 2008Reply With QuoteReport This Post
Nullus Anxietas
Picture of ensigmatic
posted Hide Post
quote:
Originally posted by Pipe Smoker:
Question #2: Suggestions for a scripting language other than perl or python?
Not really. I write all my scripts in sh, bash, or Perl.

I haven't tried Python for one simple reason: I find the idea of scope being determined by leading whitespace to be about as brain-dead an idea as ever I've heard.

By "not tried" what I mean is one time I wrote a simple "Hello, World!" type Python script, just to see, and thought "Just as I thought. Nope."
quote:
Originally posted by Bytes:
The development team I manage / code ... has twice evaluated Python and rejected it in favor of C#.
For clarification: C# is not a scripting language. It's more an alternative to Java, C++, or Objective-C.



"America is at that awkward stage. It's too late to work within the system,,,, but too early to shoot the bastards." -- Claire Wolfe
"If we let things terrify us, life will not be worth living." -- Seneca the Younger, Roman Stoic philosopher
 
Posts: 26032 | Location: S.E. Michigan | Registered: January 06, 2008Reply With QuoteReport This Post
Member
posted Hide Post
Just for giggles, some unoptimized python. Pipe Smoker can speed test it. And, re-format it, since the site will eat all the leading whitespaces.

==================================
#!/usr/bin/env python3

import re
import sys
import os

searchd = os.path.expanduser("~") + "/Documents"

for dir, subdirs, files in os.walk(searchd):
    for file in files:
        if not file.startswith('.'):
            tgt = os.path.join(dir,file)
            for line in open(tgt, 'r'):
                if re.search(sys.argv[1], line):
                    print(tgt + ": " + line)

    if 'RCS' in subdirs:
        subdirs.remove('RCS')

    if 'Funcs' in subdirs:
        subdirs.remove('Funcs')


--
I always prefer reality when I can figure out what it is.

JALLEN 10/18/18
https://sigforum.com/eve/forum...610094844#7610094844
 
Posts: 2427 | Location: Roswell, GA | Registered: March 10, 2009Reply With QuoteReport This Post
Nullus Anxietas
Picture of ensigmatic
posted Hide Post
quote:
Originally posted by SigJacket:
Just for giggles, some unoptimized python. Pipe Smoker can speed test it. And, re-format it, since the site will eat all the leading whitespaces.
Doesn't SF's web forum software support code tags?

Testing...

#!/usr/bin/perl

for($x = 1; $x <= 10; ++$x) {
    print "Hello, World! ($x)\n";
}

It does. Thought so.

ETA: As far as speed-testing the code goes: Wouldn't matter what he wrote it in. The time is all going to be in disk operations.



"America is at that awkward stage. It's too late to work within the system,,,, but too early to shoot the bastards." -- Claire Wolfe
"If we let things terrify us, life will not be worth living." -- Seneca the Younger, Roman Stoic philosopher
 
Posts: 26032 | Location: S.E. Michigan | Registered: January 06, 2008Reply With QuoteReport This Post
Member
posted Hide Post
quote:
Originally posted by ensigmatic:
Doesn't SF's web forum software support code tags?


Re-formatted by post, thanks for this!


--
I always prefer reality when I can figure out what it is.

JALLEN 10/18/18
https://sigforum.com/eve/forum...610094844#7610094844
 
Posts: 2427 | Location: Roswell, GA | Registered: March 10, 2009Reply With QuoteReport This Post
Serenity now!
Picture of 4x5
posted Hide Post
quote:
Originally posted by Bytes:
quote:
Originally posted by 4x5:
I'm a software engineer by day, university instructor by night. I recently started teaching a beginning programming course using python, and I have to say, I am VERY impressed with what python can do, and how dead-nuts easy it is to use. In python, I can have a semi-complicated app running in a fraction of the time it would take to do in C#. It's a great language!


Interesting observation. The development team I manage / code (we basically write APIs that do tons of db reads-writes) has twice evaluated Python and rejected it in favor of C#. To be fair, our apps do fall into the complicated range. Maybe we should take a 3rd look at Python?

For just playing around, I think python does a great job of insulating the programmer from needing to understand too much about the date structures etc. It's a great first language to learn. It's also great for whipping up a quick program to test an idea etc. But for enterprise-level applications, I don't think python would be my first or second choice.



Ladies and gentlemen, take my advice - pull down your pants and slide on the ice.
ʘ ͜ʖ ʘ
 
Posts: 4950 | Location: Highland, UT | Registered: September 14, 2006Reply With QuoteReport This Post
Baroque Bloke
Picture of Pipe Smoker
posted Hide Post
quote:
Originally posted by SigJacket:
Just for giggles, some unoptimized python. Pipe Smoker can speed test it.
<snip>

Thanks much SigJacket. I’ll try that and report the result. But it might be a while because my new MacBook, running Big Sur, doesn’t have python. (Tim Cook is one lazy bastard.)

I’ll swear, SIGforum is a better resource for questions such as this one than Stack Overflow!



Serious about crackers
 
Posts: 9699 | Location: San Diego | Registered: July 26, 2014Reply With QuoteReport This Post
Member
posted Hide Post
quote:
Originally posted by Pipe Smoker:
quote:
Originally posted by SigJacket:
Just for giggles, some unoptimized python. Pipe Smoker can speed test it.
<snip>

Thanks much SigJacket. I’ll try that and report the result. But it might be a while because my new MacBook, running Big Sur, doesn’t have python. (Tim Cook is one lazy bastard.)

I’ll swear, SIGforum is a better resource for questions such as this one than Stack Overflow!


I get my python3 (and other things, like Bash5) from Homebrew.


--
I always prefer reality when I can figure out what it is.

JALLEN 10/18/18
https://sigforum.com/eve/forum...610094844#7610094844
 
Posts: 2427 | Location: Roswell, GA | Registered: March 10, 2009Reply With QuoteReport This Post
member
Picture of henryaz
posted Hide Post
quote:
Originally posted by SigJacket:
I get my python3 (and other things, like Bash5) from Homebrew.

I use Homebrew for things that have a lot of dependencies, like unbound and rsyslog. But if python is all you need, the Python project has a 64bit universal binary installer for macOS (Intel and/or Mac silicon), latest version, of course.



When in doubt, mumble
 
Posts: 10887 | Location: South Congress AZ | Registered: May 27, 2006Reply With QuoteReport This Post
Baroque Bloke
Picture of Pipe Smoker
posted Hide Post
About half way through this thread I had become nearly certain that I ought to learn python. But now I’ve toggled back, thinking that I’ll stick with bash for my scripting language. Possibly renewing my former acquaintance with perl. Here’s what toggled me back…

First, ensigmatic’s post: “I write all my scripts in sh, bash, or Perl. …… I haven't tried Python for one simple reason: I find the idea of scope being determined by leading whitespace to be about as brain-dead an idea as ever I've heard. …”

So ensigmatic had also considered python but continues to use “sh, bash, or Perl” for scripting. He’s already trod the path I was treading, and I respect his judgment and experience. And “scope being determined by leading whitespace” seems bizarre to me too.

Second, SigJacket did a wonderful thing for me: he wrote a python script that was a transcription of my bash script example. That provided a direct python vs. bash comparison. Perfect! I thank you so much SigJacket!

Then, looking at the python and bash versions of that script, I’m thinking that the bash looks significantly better: not only more concise, but also more direct.

In my OP of this thread I rather maligned bash. Sorry for that bash. I apologize.



Serious about crackers
 
Posts: 9699 | Location: San Diego | Registered: July 26, 2014Reply With QuoteReport This Post
  Powered by Social Strata  
 

SIGforum.com    Main Page  Hop To Forum Categories  The Lounge    Need advice for a scripting language

© SIGforum 2024