Sponsored Content
Top Forums Shell Programming and Scripting On how to select the right tool for a given task Post 302249565 by neked on Tuesday 21st of October 2008 03:24:15 PM
Old 10-21-2008
My personal perspective:

1) I am not very good at memorizing stuff, nor do I think the human brain is optimized for that task. I'm much better at making inferences and deductions instead.
2) I know what parameter substitutions are -- in general. But I can't bring myself to remember the difference between
Code:
${parameter##pattern}
and
${parameter%%pattern}

Everytime I see one of those, I have to open a terminal and make a small test to figure out which is which. And thats only an example, there are many other similar looking constructs that do not give the slightest hint to what they actually do. My memory is weak, and when I can't use my deductive and inferential powers, I end up wasting time figuring out what they do. A classic example, if you only knew minimal bash, how much time do you need to understand what this does:

Code:
path="/home/neked/testfile"
s=${path##*/}

versus:

Code:
path="/home/neked/testfile"
s=$(basename $path)

The second code provides some semantics for you to infer what the code does. The first one relies on your memory. The brief way to sum my point is that parameter substitutions are NOT easily readable.

3) Even if you were a parameter substitution guru, and you used meaningful variable names and comments to make clearer what your parameter substitution tricks do, then future maintainers of the code might not be the same. This bit me a couple of days ago: I had to spend 20 minutes debugging a bash script riddled with those parameter substitution scripts. I estimate I would've spent closer to 5 minutes if the code was written using more obvious external tools (sed, basename, awk). This is about 15 minutes of human time wasted in order to save less than a few milliseconds of CPU time. Especially since the whole script runs only once a night, and does not exceed 0.030 seconds runtime on my modest 7 years old computer.

4) The conclusion for me is that parameter substitution should only be used when and only if the need arises. Anything else is premature optimization at the cost of more developer hours debugging and maintaining the code. If I have a script that takes 4 seconds to execute, which could be optimized into running within less than a second using parameter substitution, that still would not -- on its own -- make a convincing case to use param substitution. For a convincing case to be made, the need to reclaim the additional seconds of CPU time must be established and weighed against the loss in human seconds needed to maintain and develop the code.

Last edited by neked; 10-21-2008 at 04:50 PM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

process vs task

Hi, I am new to this forum and unix too. I have just started learning unix. As I was going through the first chapter, I read that unix is multitasking, multiprogramming, multiprocessing and multiuser OS. My question is: Is there any difference between a TASK and a PROCESS. How are PROCESS... (2 Replies)
Discussion started by: hana
2 Replies

2. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies

3. Shell Programming and Scripting

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies

4. Programming

Help with task daemon

believe it or not but this is my first c program (i've worked with java, C#, php though) I am trying to make a daemon that checks if mplayer is running(it's for a projection room) and if it is not then to run mplayer with a file.. So far it's not working and I don't know why Help and comments... (5 Replies)
Discussion started by: james2432
5 Replies

5. Boot Loaders

Reboot and Select Proper Boot device or insert Boot media in select Boot device and press a key

Hello, I have kubuntu on my laptop and now I decided to switch to Windows 7. I made the bios settings properly (first choice is boot from cd\vd) but I see the error " reboot and select proper Boot device or insert Boot media in select Boot device and press a key " I have tried CD and... (0 Replies)
Discussion started by: rpf
0 Replies

6. Shell Programming and Scripting

last task for my script

hi, infile- create table salary ( occupation_code char(40), earnings decimal(10,2), occ_yearend integer ); outfile- salary:create table salary salary:( occupation_code char(40), salary: earnings decimal(10,2), salary: occ_yearend integer salary:); Thanks. (4 Replies)
Discussion started by: dvah
4 Replies

7. Shell Programming and Scripting

task

Hi all, I'm newbie and stuck here. Thanks for any help. Input(txt file) a b X c d Y e f Z g h W Requested output: a b X Y c d Y X e f Z W g h W Z Please use code tags when posting data and code samples! (10 Replies)
Discussion started by: hernand
10 Replies

8. Shell Programming and Scripting

Task

Hi experts, I have a problem with the below shell task: I need to modify the file creatin a paired row , per each row which matches filter (e.g. number of nonempty columns = 5) Output should look like this: second row is original one from the input, first row(red) is pairing row, it's... (29 Replies)
Discussion started by: hernand
29 Replies

9. Homework & Coursework Questions

[HELP] Easy task

I have a simple task for my school work. I'm new with unix, so i need help. I need to write a scenario. Task is. From created txt file read first 3 words and create a 3 catalogs with those 3 words. 2 of those new catalogs should be transferred to other directory. If someone could help me just... (1 Reply)
Discussion started by: justynykas
1 Replies
Holotz's Castle Editor(6)												 Holotz's Castle Editor(6)

NAME
holotz-castle-editor - editor for holotz-castle game SYNOPSIS
holotz-castle-editor [-f] [-w] [--fps nn] [-mWWxHHxBPP] [-r RR] [-c CC] [-t theme] <story> <nr> DESCRIPTION
A great mystery is hidden beyond the walls of Holotz's Castle. Will you be able to help Ybelle and Ludar escape alive from the castle? Use the editor to design new levels for this game! USAGE
You can use the following keys while working with the editor: - Page Down: Next level in the story (or a new one if it doesn't exist). - Page Up: Previous level in the story. - 'c': Increase the number of columns from the right. - CTRL-'c': Increase the number of columns from the left - SHIFT-'c': Decrease the number of columns from the right. - SHIFT-CTRL-'c': Decrease the number of columns from the left. - 'r': Increase the number of rows from below. - CTRL-'r': Increase the number of rows from above. - SHIFT-'r': Decrease the number of rows from below. - SHIFT-CTRL-r: Decrease the number of rows from Above. - '+': Increase level time. - '-': Decrease level time. - '1': Select 'floor' tool. - '2': Select 'continuous floor' tool. - '3': Select 'stairs' tool. - '4': Select 'bar' tool. - '5': Select 'breakable floor' tool. - '6': Select 'key' tool. - '7': Select 'rope' tool - '8': Select 'starting character's position' tool. - '9': Select 'exit position' tool. - '0': Select 'enemy' tool. - 's': Save. - CTRL-'q': Quit editor. - Arrow keys: Move around in the map. - 'g': Increase gravity strength. - SHIFT-'g': Decrease gravity strength. - 'x': Increase main character's speed in axis. - SHIFT-'x': Decrease main character's speed in X axis. - 'y': Increase main character's speed in Y axis. - SHIFT-'y': Decrease main character's speed in Y axis. - 'j': Increase the number of cells that the player can jump vertically. - SHIFT-'j': Decrease the number of cells that the player can jump vertically. Other features: - When adding an item to the map, if you press CTRL key it is adjusted to a cell. - To adjust a rope's lenght, you select it and, while still pressing mouse button, press ALT key and drag the mouse vertically until get- ting the desired length. - To adjust a rope's oscillation amplitude, you must select it and, keeping mouse button pressed, press SHIFT key. Real time amplitude is not shown, as it is determined taking into account the distance in vertical to the rope when releasing mouse button. OPTIONS
These command line options are available: -f Full Screen. -w Windowed. --fps nn Run the game at nn frames per second (fps). -mWWxHHxBPP Run in video mode set by WW pixels of width, HH pixels of height and BPP bits per pixel (eg. -m640x480x16). -r RR Crete map with RR rows of height. -c CC Crete map with CC columns of width. -t theme Use theme named 'theme'. <story> <nr> Load level nr of the story called 'story'. AUTHOR
This manual page was written for the Debian GNU/Linux system by Miriam Ruiz <little_miry@yahoo.es> (but may be used by others, of course) Miriam Ruiz 28.01.2005 Holotz's Castle Editor(6)
All times are GMT -4. The time now is 03:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy