Faculty of Engineering and Mathematical Sciences 
Not logged in (login)

help4407


This forum is provided to promote discussion amongst students enrolled in Open Source Tools and Scripting (CITS4407).
 
Options:
RSS cloud
Jump to:

Bash vs Other Programming Languages (eg Python or C)

4 of 390 articles shown, currently no other people reading this forum.
photo
From: Kerrie B.
Date: Sun 7th Jun 2020, 11:20am
Actions: 
        Login-to-reply

 

Now obviously I realise that because this is a scripting unit, we are required to use 
bash to create solutions for the assignments, however in "real life" would it not be 
easier to create a Python or C program to do the task and then just call it from 
bash? 

For example, I think I could create a solution to Assignment 2, Question 3 
significantly quicker & easier in Python than I did in bash. Now I realise I am much 
more proficient at Python than bash, hence I am wondering whether it is just my lack 
of experience in bash which makes it very cumbersome, or whether Python would be a 
better option? 

Cheers

Kerrie

Bash vs Other Programming Languages (eg Python or C)

photo
From: Lee dB.
Date: Sun 7th Jun 2020, 4:00pm
Actions: 
        Login-to-reply

 

"Kerrie Beech" <19*1*3*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> Now obviously I realise that because this is a scripting unit, we are required to use 
> bash to create solutions for the assignments, however in "real life" would it not be 
> easier to create a Python or C program to do the task and then just call it from 
> bash? 
> 
> For example, I think I could create a solution to Assignment 2, Question 3 
> significantly quicker & easier in Python than I did in bash. Now I realise I am much 
> more proficient at Python than bash, hence I am wondering whether it is just my lack 
> of experience in bash which makes it very cumbersome, or whether Python would be a 
> better option? 
> 
> Cheers
> 
> Kerrie

This is something I've been reflecting on myself through the course of
the unit and I think it's a good question. I'm quite fond of Python as
a programming language for a number of reasons. On the other hand, Bash
and shells are something I've previously had exposure to, but I've never
really taken the time to learn them in detail beyond whatever I needed
to know to achieve a particular outcome at the time. For that reason,
I was keen to learn Bash specifically in more detail.

In may ways though, I think that Bash and Python have something
substantial in common - their power comes largely from the collection
of libraries and software that is available in each of  those
environments. Both Bash and Python are interpreted scripting languages
that are dynamic in nature. They also both leverage other projects and
ecosystems for a large portion of their capabilities. In that sense,
both Python and Shell programming are about bringing together disparate
components that have been designed with different philosophies and
objectives to build something new. Contrast that to something like Java
or C#, where the standard library has been developed largely by a single
coordinated entity e.g. Sun. Oracle or Microsoft.

In my opinion, each has pros and cons. Python is much more
platform agnostic than Bash, and Bash (as an example) is much more
anachronistic. Python adopts more modern data structures and paradigms,
whereas Bash feels more like an interactive shell that has grown to
accommodate some programming. Either way, both are still very relevant in
their own ways - Python hasn't (yet) become a mainstream replacement for
a shell, and Bash (probably never will) become a mainstream programming
language.

That being said, Bash and other shells are still the most direct way to
interact with the internals of an operating system. It is a lightweight
glue that can bring together a variety of high-performance executables -
potentially running in parallel - with a common interface regardless of
implementation language. Contrast that with Python where libraries need to
have Python-specific bindings, more than likely share an address space,
and can be difficult to parallelise because of things like the Global
Interpreter Lock.

Would I want to attempt something like Assignment 2, Question 3 in a shell
again? Probably not. I agree it could be implemented more effectively in a
modern language like Python. But having completed the assignments, I can
absolutely see the advantage of shell scripting specifically for certain
use cases, especially where performance and efficiency are required.

Anyway, just my two cents. Would be very keen to hear other's thoughts on the topic!

Bash vs Other Programming Languages (eg Python or C)

photo
From: David M.
Date: Sun 7th Jun 2020, 7:05pm
Actions: 
        Login-to-reply

 

The assignments require you to demonstrate what you CAN do with bash
not what you SHOULD do with bash. 

You would never use bash to write a significant program. 

Bash and other shells are primarily to help a user interact with the 
operating system. This includes automating tasks; and most usefully, 
shell scripts act as the "glue" between applications that perform
specialised tasks.

E.g. in Assignment 2, task 3, the most time consuming task, by far, was reading
the data files into memory.  And since the application seems to be intended
originally to run in a Web page, response time is critical and therefore it would be
a very poor design decision to read the files into memory every time you want to
compute a route. I.e. you would want to store the data in a database.  Accessing
The database and performing computations would be much more conveniently
done using a full-featured programming language. (I note you could use a SQL
command-line tool in your shell script if you are mad enough!) Also do not forget
that modern programming languages have many nice features to help you,
e.g. proper functions amongst others, as well as modules or libraries.

For serious Unix scripting, you should consider Perl (it is not dead - merely
unfashionable), otherwise Python or Ruby on Rails for Web stuff, or Javascript
and Node.js.

Bash vs Other Programming Languages (eg Python or C)

photo
From: Christopher M.
Date: Tue 9th Jun 2020, 4:50pm
Actions: 
        Login-to-reply

 

A great question Kerrie;  and thanks to Lee and David for their viewpoints - all correct, because 
there's no single one-size-fits-all solution or language for the majority of computing tasks.


As David stated, it's not reasonable to compare what we've completed in assignments (for the purpose 
of demonstrating that you've learnt something), and developing a new application in your favourite 
language.  And if you're equally fluent in a handful of programming languages, compiled or 
interpreted,  then you'll need to make your decision based on the best fit for the application domain, 
how much leverage you can get from existing tools and functions/modules, and whether there's any 
constraints such as speed, resource usage, readability, maintainability, and cost.

There's many occasions, not just my experience, where bash and friends are perfect for building a 
prototype of an application, because many of the necessary components already exist as other, external 
programs that can be invoked 'for free', and all we need to worry about it getting the input+output 
plumbing and formats correct.  Such prototypes can be easily demonstrated.  Then, if the prototype 
looks promising, and if speed is a future concern when the program will be connected to hundreds of 
clients per-second then, yes, devote the necessary resources and time to build a solution in a 
traditional programming language.

But everything exists on a spectrum; a working bash script may be considered too slow, so replace it 
with a developed Python program which, in turn, may be considered too slow, so replace that with a 
compiled C/C++ program.

There's been many occasions when I've started building a solution in a shell, with plans to replace it 
with a program one day,  only to realise that it took minutes to develop, it's only 20 well-documented 
lines long, takes less than a second to run, and only runs once a day or once a month anyway.  In such 
cases, there's no benefit at all in rewriting it.

Also, I think as an artefact of using languages/tools that haven't changed much at all for forty 
years, I find myself far less obsessed by ensuring that the same version exists on all the platforms I 
use, Linux, macOS, Raspberry Pi, for me.  The scripting tools are very mature, and their core 
'identical' in bash, zsh, and ksh, whereas Python, and others, are still in transition (or recent 
upheaval).

_______
Interesting topic Kerrie, thanks.

It'd be great to hear from some other students too - particularly those who, in February, said that 
they'd never programmed anything before.
This Page


Program written by: [email protected]
Feedback welcome
Last modified: 11:27am Sep 21 2020