Home » Ruby » How do you use scripting language (PHP, Python, etc) to improve your productivity?

How do you use scripting language (PHP, Python, etc) to improve your productivity?

Posted by: admin December 31, 2017 Leave a comment

Questions:

I’m a Delphi developer on the Windows platform, recently read the PHP tutorial at W3CSchools, it looks interesting.

We all know scripting languages are very good at web site development, but I also want to utilize it to improve my productivity or get some tedious tasks done quickly, maybe some quick-and-dirty string/file processing?

What do you usually do with scripting languages apart from software development?
And we need a responsive, decent IDE/editor in order to gain productivity when writing scripts for this purpose?

Answers:

I’ll tell you how I’ve improved my productivity with Python on Windows. I just try to write everything in Python – every application I need, unless I know it won’t scale and I’ll need more efficient tools (in which case I personally use C++, but you could also use C#/Delphi).

It turns out that for most (> 95%) of the tools and utilities are need, Python (coupled with PyQt for the GUI) is good enough, and it’s a much more productive language for me than C++. The key is stop thinking of Python as a “scripting language”. It is no less a programming language than C++/Java/C#/Delphi/what say you. It has it strengths, and it has its limitations. As long as you’re aware of them and know how to pick the appropriate tool for the job, you’ll do just fine.

You don’t need any special IDE. I use Scite for all my Python coding (on Windows and Linux, by the way), and it works great.

Questions:
Answers:
  1. You can DEFINITELY help yourself by automating a lot of tasks with scripting languages.

    Please note: some of those “scripting” languages – like Perl – are actually very powerful general purpose software development languages which just happen to be labeled “scripting” because their initial niche and/or parentage was scripting (and because it is easy to do simple scripts with them).

    Personally I use Perl for both quick scripting automation (2% usage), web development (8% usage) and enterprise financial software development (remaining 90%).

  2. As for examples of what you can do – the answer is “pretty much anything” and largely depends on what your typical work that needs automating is. I use Perl for file system related stuff (file organization/cleanup/renaming) to file content manipulation (Perl’s origin and one of strongest suites still being text processing) and assorted reporting (“R” in Perl stands for “Reporting”), and for assorted data crunching that is just too difficulty to do quickly in Excel.

    Please note that Perl has an extremely wide array of libraries (called modules) available via CPAN that can be used to do pretty much anything except toasting bread or time travel; as well as numerous frameworks for serious software development.

    To mirror the Python answer, Perl can also be used for GUI stuff on Windows – I won’t elaborate here since SO has very comprehensive discussions on the topic should you decide to go with Perl.

  3. As a very specific example illustrating the above, the last 2 projects I did for myself were indexing systems that indexed file names, meta-data and contents and provided a way to search through the index. The first one was local code search (poor man’s version of Google Code Search appliance), the second one was a file collection management system for my mp3s (I double dog dare any existing software for the purpose to allow me random regular expression search by tag keywords). Both used SQLite back-end and Perl for indexing and front-end. Second specific example was a 2-liner counting how many up-votes I had for a specific tag on StackOverflow 🙂

  4. You will benefit greatly from a good IDE or just programming editor for ANY programming, scripting included. On Windows you can use Notepad++ or UltraEdit or many more – SO should have a list someplace. Any editor with “intellisense” (intelligent workd completion) gets an edge.

Questions:
Answers:

Scripting languages can be very powerful. Here’s how I believe Lua improves my productivity:

  • The central data is the associative array (mutable hash table). Lua’s implementation is extraordinarily efficient and serves well as hash, table, set, and list.

  • The string processing sits in an excellent sweet spot: almost as powerful as regular expressions, and a lot more readable. The pattern escape character % is different from the string escape char \. Lua’s “pattern with capture” is simpler than POSIX regexps and much simpler than Perl regexps, and it meets 90% of my string scanning needs. A superb example of engineering design.

These two features cover the major data. On top of this,

  • The table is the only mutable type, making programs easier to reason about.

  • Lua has first-class, nested functions, so all the power of the functional paradigm is available if you need it—but if you don’t use it, you don’t pay.

  • Lua has a built-in iteration construct, native to the language, which is suitable for iterating over collections, filesystems, you name it. Much better than having some “iterator object” with “iterator methods”. Iteration is sufficiently important that I benefit greatly from having a language construct devoted to it (the generic for loop).

  • The language is simple enough that after modest study, I understand all of it.

  • There is a lightning-fast interactive implementation.

  • At need, I can import any existing C library into Lua.

  • The standard Lua libraries meet most of my needs while remaining small enough to be comprehensible. If I need a special purpose library (XML, HTTP, parsing), it is generally already available and easy enough to understand.

  • Again at need, I can readily extend with my own data types.

I find that I am using Lua for all the tasks I used to get done with sh, awk, sed, perl, and that crowd. I also find that 90% of the time I can write a simple, useful Lua program much more quickly than a simple, useful C program. (The other 10% is when I’m mostly making system calls.)

Although I’ve lost count of the number of languages I know well (over 10,000 lines of code written), these days almost all of my needs are met by just 3:

  • Lua for almost all lightweight programs, including the quick-and-dirty string/file processing that you mention

  • C for teaching (because I must teach C)

  • Haskell for prototyping (and sometimes implementing) sophisticated or large systems, especially compilers

I’ve also used a mix of Lua and C for some fairly substantial applications, like nbibtex and noweb 3.

Questions:
Answers:

The short answer would be, you can do many many things with scripting languages – but you can still call it programming or software development.

But, answering your questions, what i find the most helpful in my work, to increase my productivity, is lots of shell/perl/python scripts.

I think the most common use of scripts are various kinds of reports (in a broad sense),
say having a logfile and wanting to retrieve certain information (or some sort of statistics), script can help you to achieve that in very short time.

Some hint keywords for you: shell scripting, regular expressions, output formatting.

Thanks

Questions:
Answers:

So you probably got the picture already, you’ll perform certain tasks lot quicker using scripting language (and regarding the word scripting: I just don’t consider it derogatory anymore, quite the contrary). Hell, I have some friends (accidentally Delphi-only programmers) still using Delphi to perform some one-time tasks, searching in text files etc, spending hours writing Delphi classes and forms, compiling over and over again, instead of couple of minutes writing Python/Ruby/Perl one-liners.

But I think there’s even more important thing to it (given the right choice): you will learn new programming concepts. You will grow as a programmer. You will outgrow that old “you got the hammer, so everything looks like a nail” point of view. You will learn how to breathe again.

BTW, when I say “given the right choice”, I strongly advice choosing a properly devised language with powerful functional programming concepts. So I’d really skip PHP and go for either Python or Ruby.

Questions:
Answers:

So, I have frequently been using Python to prototype solutions to various programming tasks (it’s good to get the algorithm right before implementing with all the bells and whistles in some other programming language), and I have been using BASH shell scripting to automate a variety of tasks (e.g. running a program over multiple differents sets of input, saving the results, piping to grep and other utilities, etc.).

When it comes to tedium, really I would strongly recommend BASH. You can get it on Windows by installing Cygwin. For example, I frequently find myself doing things like the following for my various courses:

for i in {1..10} ; do
    ./process_data input-$i.txt | tee result-$i.transcript
done

You don’t need a good editor… any text editor will do just fine. That said, if you are looking for a good Python editor, Eclipse with PyDev is pretty good. Personally, I just use Xcode as a general purpose code editor for everything… even though it doesn’t really bring anything to the table for Python or BASH shell scripts… of course, you don’t have Xcode on Windows. However, you can use Notepad++, Notepad, or Wordpad.

Questions:
Answers:

As a 50/50 windows/linux user at work, python is especially useful, since nearly everything I write is cross-platform, and also because windows doesn’t really have a very useful shell language. With pyqt, I can create a pretty impressive GUI in just a few hours. I’m fairly certain than in the next few years, python will take over the world.

Questions:
Answers:

i’m TextMate user and actively develop extensions (“bundles”) for it for my own use in php, ruby and javascript.

Questions:
Answers:

I use scripting languages to do a lot of pre/post processing of data. Small or large.

Nearly all scripting languages have superb/fast file, text, graphic, etc. handling. And very very easy without masses of boiler plate code and the compilation step.

And as someone mentioned, you’ll be flexing your muscles and learning a new world of possibilities.

I jump from one scripting language to another, sometimes mix them up, just to get what I want done faster. Makes me fearless knowing that you can do most anything you can think. If you can’t then there’s always stackoverflow and the more languages (the language-agnostic tag) you can accept for a solution the faster (and better usually) you’ll get one.

Questions:
Answers:

I use the standard libraries of each scripting language to get things done quickly using a well documented API. For example, here are the tools I use in the most popular scripting languages:

  • PHP

    • XSLT – XML report generation
    • imagemagick – image optimization
    • curl – integration testing
    • intl – internationalization
  • Python

    • turtle – nostalgia
    • plistlib – OSX configuration
    • sqlite – rapid database prototyping
    • sched – rapid task scheduling
    • difflib – diffing
    • shutil – file archiving
  • Ruby

    • Rake – automating backups and logs
    • expect – automating authentication prompts
    • abbrev – autocomplete
    • RSS – creating feeds
    • fileutils – comparing files
    • gdbm – serializing program state
    • win32ole – MSXML/IE automation
    • did_you_mean – Avoiding typos
  • Perl

    • Env – fixing path issues
    • Memoize – testing algorithms
    • TAP – organizing tests
    • Params::Check – validating APIs

References