Which language do you use for "throw away" programs? By "throw away" I don't mean perl one liners, but code that is useful for a current project but may not be added to it.
Generally any scripting language. Ruby is my personal favorite for desktop scripts and PHP for web scripts, but those are the two I'm most familiar with.
If it might be included, whatever language the project is in. In that case, I treat it like part of the project, and check it in and everything. I just make sure that it's commented clearly that it might not be part of the final release and it's just a development tool.
C++, I know it's not the best language for it. But I've been doing C++ for over 10 years and have a lot of utility stuff already written. So I'm usually much faster than in any other language I know.
That said, my second choice is Python.
Python is currently my choice du jour.
Unless I need lots of regex, then it's Perl.
It seems I'm against the flow here but I like VB/ASP for ease of use, ease in transferring to VB.NET if it's a keeper, and as a Web based technology it's easy to provide access to others for demonstrations or permanent access.
All that said, I occasionally use new (to me) languages for non-critical applications so my attempts at learning Python mean it's also an option now.
If it needs a GUI, I prefer VB.NET (the express edition of course). It's quick and dirty (just like all my throw away projects)
Other than that, mostly php.
If the project gets bigger, I eventually port it in Java.
PowerShell or Python. PowerShell being my first choice, since I can call into the .NET framework and use assemblies I've already written (I know IronPython could do that, but PowerShell is more convenient for the moment).
Also, since the PowerShell scripting engine can be embedded in my programs, I can take embed the PS runtime in my app and try various combinations. If things work, I can convert to C# or leave it as PowerShell.
Bash scripting if it's easy enough. Otherwise, generally Ruby.
I used to use Perl, but started forcing myself to use Python - the main reason for that is that I tend to write better code when using Python, simply because there are so many shortcuts available in Perl.
In my experience "throw away" programs can often become more permanent, so I'd think twice before starting to hack away at something that supposedly will be thrown away.
As you write yourself, "may not be added", but it might stick, and if you don't do it properly you might end up with an unmaintainable mess - force yourself to do it right the first time and you'll be happier.
I find Python makes writing throw-away programs that are still readable and maintainable rather easy. Plus, with batteries included, a bit of script can go a long way!
Without a doubt... Boo. Very much like Python but targets .NET. And if you do end up keeping the "throw away" code, then it's really easy to convert to C# or VB.NET if needed (auto in #develop IDE).
It rather depends which language is most suitable for the problem domain.
Even for throwaway programs.
Most recently, sed and xmlstarlet.
Python and C# are favourites for different reasons, and for those reasons I currently am looking at BOO - the best of both worlds!
I'm with izb -- python for most things, but perl if I need regex or more complex string manipulation.
Actually it's still plain old Visual Basic 6.0, because usually my "throw away tools" have to work with strings a lot and I know how to handle these in VB6 ;)
Okay, start to throw rocks... NOW! (JEHOVA, JEHOVA)
I like python for my throwaway type programs and if I'm feeling a little adventurous and need to integrate it with .net IronPython
Matlab, since most of what I do is data-intensive. The built in math functions make testing algorithms easy.
It's kind of funny... but for throwaway apps I immediately turn to VB6.
I'm a fan of VB.NET for more modern development (as I mention in another post... and yes, I am a "real programmer". I choose VB.NET.), but VB.NET did lose some of it's Rapid Application Development gusto when it switched over from VB6. VB6 still lets you push out a quick app in moments.
Groovy from the command line, usually. To verify method behavior in Java libraries.
The interactive Python shell is vital for occasions like this. No need to bother even creating a text file, just type it and run it! You get the whole the Python standard library to play with, which really helps reduce the amount of code you have to write for almost any task.
If its a web app then Grails allows you to create a functional app that can perform CRUD operations with 5 commands and 1 edit of code:
grails create-app BookStore
cd BookStore
grails create-domain-class Book
Then edit the generated Book.groovy, you could add:
class Book {
String title
}
and then enter:
grails generate-all Book
grails run-app
and there you go one working web-app.
I willl generally use whatever language / platform the main body of the project is implemented in. There are a couple of reasons for this:
- It is possible that the throwaway code may be usefull for demonstrating necessities in the final implementation
- Given that this is the language that I am currently working in it is likely to be my sharpest knife
- If it is the language of the project then my colleagues are more likely to understand it.
C++.
Usually that code tends to be useful, so it's nice to keep around in a state that it can be used (by my project) in.
MSN
My problem is I have too many that I turn to. It really depends on the specific task that I am doing. I do a lot of this kind of stuff and I really don't throw it away. It may be useful the next time I have to do something quick. For quick useful tasks I try to avoid compilers unless I need the speed.
Here is my current order and why:
- Batch file - If it's simple and JPSoft's Take Command can do it I use a Take Command batch file.
- PowerShell - Very powerful, but I'm still learning (I hope to make it my solution for most throw aways).
- VBScript - Easy, fast, and easy access to a lot of com stuff - also can be used on IIS to create web pages (ie. ASP).
- Python - If I'm working on XML this is what I go to.
- Perl - Text parsing as long as it's straight forward. I don't like creating write only scripts. If it's complicated I will switch to something like PowerBasic.
- PowerBasic - If I need fast small executables with zero runtime.
- VB 6 (if I already have code that is close to what I want to do).
- C++ (rarely, but again if I already have code that does what I want or I find code online that does what I want).
I have yet to use C# or VB .NET for throw away stuff. In the future that will change as I accumulate more code.
My throw-away are typically to format data or move files around.
For this a good flexable batch file will run on any Win-xxxx based machine.
For a quick reformat GAWK and SSED work great. They can also be zipped with a batch file to pass the quick fix on to others.
I had held off on powershell because it just wasn't on every desktop that I need to touch. And nothing hurts like knowing a solution and not having access to the tools. From all I hear PowerShell has too much .. Power .. to ignore for too long.
- Josh
Python -- for text manipulation, things more complex than regexps, etc. Bash -- for file manipulations, automating various tasks, etc.
Bash for shell scripts. the way you can just start typing it straight into a terminal for testing is priceless.
And you really can't beat PHP for simple web stuff. Most web servers support it.
It depends on where I am and what I need to do
- Work: batch files and perl
- Home: tcsh and perl
Ruby. Pure object oriented, I don't have to worry about casting issues, and the classes that it provides allows to do proof of concepts real quick.
Lately, for simple scripts or throw away code, I've been digging on PHP from the command line. For me you can't beat a C-like syntax and the plethora of PHP functions you get out of the box is a winner.
If not PHP it would have to be C/C++.
Flash: I've been mostly doing interactive game-or-toy-like projects. Flash comes in very handy for me to do quick simulations or game prototypes.
Python: The interactive prompt is awesome.. where you can write programs and test/interact at the same time, on the fly
Haven't ever touched Ruby. Just my gut feeling that I will love it more when it comes to projects more complex and complicated then a command prompt can handle.
When scanning text files (and need quick-n-dirty regexps), perl. Otherwise, lisp.
Excel for one-time use reports (unless the report would require VBA)
Python (with the interactive shell) for other throw-away (or semi throw-away) needs
Usually Lua, unless there's a large need for some complicated library function that isn't included. Typically the string matching, input/output, and data structures in Lua suffice for anything I need to do.
80x86 assembly language.
Naah, just kidding: I use Python. It's the only language in which I can always read my code a year later. On that metric, I'd rate sh
second. I never managed to read my own Perl code, even if it was from yesterday. Genetic flaw, I'm sure.
Throw-away scripts are never as throw-away as you might like. If you don't want to have to re-write them from scratch next time, pick a language for its readability. If you find Perl easier to read than Python — MUTANT! — stick with Perl for your quick scripts.
Corollary: keep learning new languages.
Perl scripts that don't fit onto one-liners. Seriously.
A one-liner (in any language) is cool, but sometimes it's just a bit much to type something in and get a syntax error. So the test code goes into its own file in ~/dev where I add a few comments and explain to my future self to object of this mess. Sure, I that know right now, but I won't remember in a few weeks time.
It really depends on what I'm doing and what platform I'm on.
On OS X
- bash
- REBOL
- Ruby
- F-Script
- Nu
On Windows
- PowerShell
- REBOL
- Ruby
AWK is my scripting hammer of choice for the types of throw away code that I typically need to do. It falls well in to the 80-90% spot of the things I need to do. There are certainly times when it doesn't quite work, like when I need to do some system stuff. AWK has a 'system' call, but it's not quite granular enough for me.
For example, if I had a list of files and I wanted to know which files weren't, say, writable, AWK can't do that. But I can use it to quickly hammer out a shell script that CAN do that (and simply echo the results to another file). It can get a bit Goldbergian, but it works.
In theory I should switch over to Perl or Python or something. But it's kind of the baby duck syndrome. I've been using it for 20 years, and I LOVE the free "line reader loop", free line/field splitting, and the free regex matching.
It's a classic example of the language affecting your thinking, or perhaps using the language that works the way you think. AWK and I are so ingrained, I don't know who influenced who. I just remember have some weird problem at a client site and thinking AWK could solve it, so I dredged through the manual page to make it work.
AWK is small, its approachable, focused, yet powerful and that makes it a handy hammer in any Unix system. I've written everything from powerful code generators and data analysis tools to lowly simple conversion tasks.
PowerShell is designed to provide a very wide range of formalism. Bruce Payette once noted that the lifespan of 99% of programs begins at the prompt and ends at the carriage return. We certainly support that very well.
We also support very simple BASH-style scripting where you use $args.
From there, you can optionally name your parameters, give them types, give them validation constraints, provide initializers, set up multiple parametersets, etc.
If it turns out to be code you want to put into a product, you can add HELP, you can localize the strings, etc.
All the while, you have access to a great scripting environment with man-style help documentation, high-level task-oriented abstractions, type adaptors that make it easy to work with XML, ADO, ADSI, WMI, etc and the ability to natively access the entirety of the .NET framework.
Experiment! Enjoy! Engage!
Jeffrey Snover [MSFT] Windows Management Partner Architect
Python is my first choice, simply because I can whip out a decent piece of code in a short time, that still is readable and possible to read the next time I need it, which is usually in a couple months time.
My disks are littered with small Python scripts written for a one-off, which might be needed again later.
In the order of decreasing likelihood:
- C++ (I have a special "sandbox" workspace where I play with things)
- Perl (If I am in a hurry to do something involving string processing)
- Windows Scripting language (It just amuses me).
- Python (If I also want to learn a trick or two)
For me, Perl. I can never understand what I've done in it after two weeks anyway :-)