Category: Uncategorized

  • bash version 4 and associative arrays

    The new builtin array variable BASH_ALIASES is a nice example for an associative array.
    If you do an ”echo ${BASH_ALIASES[@]}” you see all the values, if you do a “set | fgrep BASH_ALIASES” you see, to what the indexes map.

    Update:

    In December, when I got aware of the new feature, I thought, there is no way to get the list of indexes.
    But there is:  ${!name[@]} and ${!name[*]} return the list of array keys. This gets explained in the section Parameter Expansion. I am sorry, if my former statements caused confusion.

  • my 1st steps in Java: extending a JasperReport sample program using Apache Commons CLI

    iReports and JasperReports (and also JasperETL and much more) are open source software, that you can find on JasperForge.org.

    I intended to extend jasperreports-3.6.2/demo/samples/text/TextApp.java, so that it would take “-Dname=value” style options. There was a need to make TextApp.java a little more flexible, and that was quite easily to achieve making use of getProperty calls.

    A friend had given me the hint recently to have a look at “System.getProperty()“, but
    it turned out to only provide the caller with properties like "os.name", according to http://java.sun.com/docs/books/tutorial/essential/environment/sysprop.html. So that wasn’t quite the route to follow.

    I started my day googling for “getopt java”, found that nice package “Apache Commons CLI“, made use of it within that JasperForge utility, and started scripting a batch run around that utility’s targets named “fill…” resp. “text…” in bash, resp. their new sisters, that I derived from them today. Next step is to rewrite that shell script as Windows batch script file resp. as python script to be used in a Windows environment. This work is almost “production ready”, but I am facing quite some necessary paperwork, so that the software developed can get made serious use of.

    Looks like the Jasper guys had not expected their software to be used like that. The “.jrxml” gets designed using iReport on a Windows box or whatever; after that it is being made use of on any kind of server executing Java classes with access to a database. (I wonder, whether that approach would also work with JasperETL.)

    I am quite satisfied with my 1st steps in Java in that JasperReport environment.

    I really had no idea and also no perspective of getting thrown into Java development during a commercial project, and even in the context of JasperReport. I do like this.

    Update / 2010-03-05:
    The atomar production steps described within TextApp.java‘s build.xml are rather nice and instructive, but they make use of those routines within TextApp.java, where target file names (incl. directory path) get strictly derived from source file names. I added resp. derived productions steps, that make use of thoses methods of the API, that allow you to name the destiny’s name explictily. And I also added chains of productions steps into the java source file, so that the calling shell resp. “whatever” script wouldn’t have to deal with calling the chained steps one by one itself. So far there are chains starting at .jrxml and at .jasper, and chains that end at .txt and also at .pdf. The idea is to place intermediate files on local disks within temp. directories instead of close to the source resp. final target file (maybe) somewhere on a network file system.

  • python and class methods

    Yes, they are supported, but you have to use an extra magic function call:

    classmethod = classmethod(classmethod)

  • software documentation

    From the book Expert Python Programming, “Documenting Your Project“, “Use a Simple Style“:

    You are not writing fiction, so keep the style as simple as possible.

    And with a few more words:

    (Another author) made an analysis […] to try to understand, why his books sold so well. He made a list of all best sellers in the marketing area and compared the average number of words per sentence in each one of them. He realized, that his books had the lowest numbers of words per sentence (thirteen words). This simple fact […] proved that readers prefer short and simple sentences, rather than long and stylish ones.

  • using associative arrays in your code

    How many lines of code does it take for your new piece of code, before you introduce an associative array?

    How many lines of code does it take for your new piece of code, before you introduce a class?

    Yes, I know, Bourne shell doesn’t come with the concept of associative arrays, of course it also doesn’t know classes or object orientation. Right, a simple 20 or 30 lines shell script for copying and renaming files may not have the need for associative arrays or classes. But if your script gets longer, pls rethink, whether Bourne shell is the right choice for your task, or whether you make really good use of ruby, perl, or python!

    Your next steps may be writing unit testing and using continuous integration. It’s not your customer, who should request it, it should be your serious professional style, your way to deliver proper services. If you are not familiar with the terms, look them up — I provided you with proper links to interesting and informative articles.

  • how to abbreviate the word Character and how German programmers pronounce it

    We know, that in a few “modern” programming languages the word “character” as an IT term gets abbreaviated as “char“. Do you have any idea, of how many coders pronounce it? They pronounce it like the “char-” as in “Charlie“. Why would actually anybody pronounce the abbrevation so much different to the unabbreviated word?

  • how to use UNIX tee to send output to more than one pipe?

    I have a necessity for that usage, I googled for it, found an answer here on UNIX.com, but I thought, there might be something slicker. I got myself an account there in order to tell the initiator of that thread, what I am going to find out, but sadly enough, he got banned since. That doesn’t happen too rarely.

    I like UNIX man pages, and I thought, I should give “$ man 1 tee” a try. That pointed me to “$ info coreutils ‘tee invocation‘”, and that instructed me to use “process substitution“, a feature of modern shells. The notation is different, but it’s still piping: “>( PROCESS_READING_FROM_A_PIPE )“. And you can use it more than once on the process, that you want to read output from.

    Now, that is seriously slick enough for me. Read the example there, it’s really nice!

    Added a note on en.wikipedia.org mentioning this insight.

    It is rather tempting to think, that using process substitution you don’t even need tee itself anymore at all, but just try yourself, it doesn’t work!