 |
|
| Linux Forum Index » Linux - Slackware Forum » Move from KDE4.2 to xfce or fluxbox - why not?... |
|
Page 3 of 3 Goto page Previous 1, 2, 3 |
|
| Author |
Message |
| Loki Harfagr... |
Posted: Tue Oct 13, 2009 10:52 am |
|
|
|
Guest
|
Tue, 13 Oct 2009 16:15:27 +0000, Sylvain Robitaille did cat :
Quote: On Sat, 10 Oct 2009 04:53:56 +1100, Grant wrote:
... 'echo -n' is frowned upon, ...
What??? Since when?
Since I learned printf!
I see ...
and AAMOF using printf is usually quite clearer than to use echo
for people already exposed to [v[s]]printf in some other lingos
Quote: But here we're about Slackware and slack's default shell is bash.
Um .... yeah, ok, your point ...
Isn't this stuff ever going to be standardised over the various shell?
Sure, as soon as no one decides they can build a better wheel ...
(something about playing hockey in Hell also comes to mind, I must admit
...)
well yes, I don't play hockey and Hel was one of my wives but I
guess that Dijkstra had a real idea about why not to multiply wheels
"
About the use of language: it is impossible to sharpen a pencil with a
blunt axe. It is equally vain to try to do it with ten blunt axes instead.
"
Now, I almost started IT on APL and hence according to what Dijkstra
said on APL my programming mood were at least garbled from the start ) |
|
|
| Back to top |
|
|
|
| Aaron W. Hsu... |
Posted: Wed Oct 14, 2009 9:52 am |
|
|
|
Guest
|
On Wed, 14 Oct 2009 09:47:36 -0400, notbob <notbob at (no spam) nothome.com> wrote:
Quote: Lisp is somewhat
comprehensible, in a bizarre twisted sorta way.
When you're ready for the light: Scheme.
Aaron W. Hsu
--
Of all tyrannies, a tyranny sincerely exercised for the good of its
victims may be the most oppressive. -- C. S. Lewis |
|
|
| Back to top |
|
|
|
| Loki Harfagr... |
Posted: Thu Oct 15, 2009 11:34 am |
|
|
|
Guest
|
Thu, 15 Oct 2009 14:28:59 +0000, Sylvain Robitaille did cat :
Quote: On Thu, 15 Oct 2009 19:40:50 +1100, Grant wrote:
What? 'cos I didn't write a module? A module doesn't make the code
more readable.
No, but proper variable names might have gone a long way towards making
the example you posted more readable.
Just because Perl allows you to be lazy doesn't mean you should be, and
just because you can post a barely readable Perl snippet doesn't mean
that Perl forces that style on the programmer.
well, that's right, a counterproof has never made a proof, but
really the Perl code posted by Grant is a part of the 5p100
best, in readability and reuseability, Perl code I've ever seen.
I reckon that these 5p100 are far below the 1p100 best read*
Perl code I've met (and I use a lot of them) but in contrast
most bash and awk code (besides golf/obfuscation games have
a better overall readability and consistence.
Now, there are also some factors positive for the use of
Perl, like presence of a huge base of network modules,
or like the fact that a product you use (e.g. Mimedefang)
uses a good set of good libs and modules and UI properly
written in Perl.
Still, I'm waiting with a smile and impatient fear the day when
Perl6 will out and spread a new veil of language looting over the
naive world of dirty code writers ,D) |
|
|
| Back to top |
|
|
|
| Keith Keller... |
Posted: Thu Oct 15, 2009 11:40 am |
|
|
|
Guest
|
On 2009-10-15, Grant <g_r_a_n_t_ at (no spam) bugsplatter.id.au> wrote:
Quote: On Wed, 14 Oct 2009 23:14:56 -0700, Keith Keller <kkeller-usenet at (no spam) wombat.san-francisco.ca.us> wrote:
...
If this subroutine is doing what I think (trying to map an IP address to
a country code?), you'd probably be better off using a module. Thus
Sylvain's point is still valid--just because you can write unreadable
Perl doesn't mean you have to. :)
What? 'cos I didn't write a module?
No, because you didn't use an existing module. There is (for example)
http://search.cpan.org/~nwetters/IP-Country-2.27/lib/IP/Country.pm
which claims to do "fast lookup of country codes from IP addresses".
(There may be other modules that do the same thing; I didn't look.)
Quote: A module doesn't make the code more readable.
Using a module makes *your* code more readable, even if the module
itself is not. :)
--keith
--
kkeller-usenet at (no spam) wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information |
|
|
| Back to top |
|
|
|
| Lew Pitcher... |
Posted: Thu Oct 15, 2009 4:10 pm |
|
|
|
Guest
|
On October 15, 2009 18:02, in alt.os.linux.slackware, Grant
(g_r_a_n_t_ at (no spam) bugsplatter.id.au) wrote:
[snip]
***************************************************************************
Quote: PROCEDURE DIVISION.
*
100-MAIN.
PERFORM 200-START-SYSTEM.
DISPLAY ' ' LINE 1 COLUMN 1 ERASE SCREEN
PERFORM 300-DISPLAY-WORLD.
PERFORM UNTIL ALL-DONE
MOVE 'X' TO KEY-PRESS
ACCEPT KEY-PRESS
BOLD PROTECTED AUTOTERMINATE DEFAULT IS CURRENT VALUE
IF FUNCTION UPPER-CASE ( KEY-PRESS ) = 'Q'
SET ALL-DONE TO TRUE
ELSE
PERFORM 400-KICK-WORLD
PERFORM 300-DISPLAY-WORLD
END-IF
END-PERFORM
STOP RUN.
*
My eyes!! The goggles do nothing!!!
[snip]
--
Lew Pitcher
Master Codewright & JOAT-in-training | Ex COBOL and MVS Assembly Programmer
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------ |
|
|
| Back to top |
|
|
|
| Grant... |
Posted: Fri Oct 16, 2009 3:57 pm |
|
|
|
Guest
|
On Fri, 16 Oct 2009 20:10:31 +0000 (UTC), Jerry Peters <jerry at (no spam) example.invalid> wrote:
Quote: Mike Jones <Not at (no spam) arizona.bay> wrote:
More and more I'm getting the idea that I need to re-train my brain
instead of leaping about trying all kinds of things and making life more
complex for no good reason. Chances are, I'll end up back at bash
scripting for the level of stuff I typically do.
I think its probably time to swot up on GAWK to by the looks of things.
Cheers!
One of the advantages of using bash is that if you also use it as your
shell, you can easily try out commands at the prompt. This makes
testing unfamiliar constructs nice and easy.
Yes, but is that not true for any shell? Not as if one would try to
run a bash script under zsh? 'spose you could, seems weird to me :)
Quote: Gawk is fairly easy to learn if you already know C.
Sometimes, sure awk's procedural constructs (normal if-then-else
programming with looping) are like C, but then there's the automatic
variables and pattern - action constructs that are not like C.
So there's a certain amount of unlearning too. I found it difficult
to switch to the awk pattern-action way of thinking for a complex
program. In a large awk program I wrote some years ago:
function chart_hits_per_port( hits, i, j, k, kk, max, o, pf, xp)
{
if (!total) return
# find top n hits for barchart, change back to port order
for (i = sort_hits_port_len; i > sort_hits_port_len - chartlen; i--) {
if (!i) break
split(sort_hits_port[i], k, ":")
# promote ICMPs to list top by giving tcp/udp lead-zeroes
if (k[2] !~ /ICMP/) {
split(k[2], kk, "/")
k[2] = sprintf("%07d/%s", kk[1], kk[2])
}
xp[i] = sprintf("%11s:%6d", k[2], k[1])
}
delete sort_hits_port # chart_hits_per_port
....
Yes, sorta looks like C. But programs like this become more like a
prototype to get the logic going?
Back to simple stuff, example of mixing gawk and shell to produce a
result:
grant at (no spam) deltree:~$ ccfind 1234567890
73.150.2.210 US:United States
grant at (no spam) deltree:~$ cat $(which ccfind)
#!/bin/bash
#
# ccfind 2006-03-05, last edit 2008-08-15
#
# returns '<query> cc:country name' for IP address input queries,
# using the ip2cn-server daemon.
#
# Copyright (C) 2006-2008 Grant Coady <http://bugsplatter.id.au> GPLv2
#
# 2008-08-13
# convert to ip2cn-server operation, no more access locking!
#
# check got query
[ -z "$1" ] && echo "
ccfind -- lookup country code and name for IP address
usage $0 aa.bb.cc.dd
" && exit
# get server listen port
port=$(gawk '/^inetport/ {print $2}' /etc/ip2cn-server.conf)
# make query, may be dotquad or numeric (decimal) IP address
echo "$ at (no spam) " | gawk -v port=$port '
BEGIN { service = "/inet/tcp/0/localhost/" port }
$1 == "0" { $1 = "0." }
{ print |& service; service |& getline; print }' 2>/dev/null
# end
When using awk's pattern action constructs, it doesn't much look
like C. Also, that one liner above retrieving port number from
a .conf file is example of awk winning hands down over sed + cut
for clarity of purpose.
Grant.
--
http://bugsplatter.id.au |
|
|
| Back to top |
|
|
|
| Jerry Peters... |
Posted: Sat Oct 17, 2009 10:36 am |
|
|
|
Guest
|
Grant <g_r_a_n_t_ at (no spam) bugsplatter.id.au> wrote:
Quote: On Fri, 16 Oct 2009 20:10:31 +0000 (UTC), Jerry Peters <jerry at (no spam) example.invalid> wrote:
Mike Jones <Not at (no spam) arizona.bay> wrote:
More and more I'm getting the idea that I need to re-train my brain
instead of leaping about trying all kinds of things and making life more
complex for no good reason. Chances are, I'll end up back at bash
scripting for the level of stuff I typically do.
I think its probably time to swot up on GAWK to by the looks of things.
Cheers!
One of the advantages of using bash is that if you also use it as your
shell, you can easily try out commands at the prompt. This makes
testing unfamiliar constructs nice and easy.
Yes, but is that not true for any shell? Not as if one would try to
run a bash script under zsh? 'spose you could, seems weird to me
Perl as a shell? Or REXX or maybe BASIC? I used to work on IBM
mainframes and one of the *very* annoying things using TSO was that
both CLIST and REXX were not available at the command prompt. You had
to put the CLIST or REXX exec into a file before you could run it.
This made testing a new construct much more tedious than it is using
Bash; e set up a few variables with appropriate values and try the
code right at the prompt. If (when) it doesn't quite work, experiment
until it does.
Quote: Gawk is fairly easy to learn if you already know C.
Sometimes, sure awk's procedural constructs (normal if-then-else
programming with looping) are like C, but then there's the automatic
variables and pattern - action constructs that are not like C.
Of course, but the syntax looks like C as opposed to say Perl or PL/1.
Quote:
So there's a certain amount of unlearning too. I found it difficult
to switch to the awk pattern-action way of thinking for a complex
program. In a large awk program I wrote some years ago:
Yeah, the paradigm takes getting used to, but a lot of the report
writer languages I've used are similiar so the concept wasn't entirely
foreign.
Quote:
function chart_hits_per_port( hits, i, j, k, kk, max, o, pf, xp)
{
if (!total) return
# find top n hits for barchart, change back to port order
for (i = sort_hits_port_len; i > sort_hits_port_len - chartlen; i--) {
if (!i) break
split(sort_hits_port[i], k, ":")
# promote ICMPs to list top by giving tcp/udp lead-zeroes
if (k[2] !~ /ICMP/) {
split(k[2], kk, "/")
k[2] = sprintf("%07d/%s", kk[1], kk[2])
}
xp[i] = sprintf("%11s:%6d", k[2], k[1])
}
delete sort_hits_port # chart_hits_per_port
...
Yes, sorta looks like C. But programs like this become more like a
prototype to get the logic going?
You mean like prototype it in GAWK, then actually write it in
something else? Why?
Quote:
Back to simple stuff, example of mixing gawk and shell to produce a
result:
grant at (no spam) deltree:~$ ccfind 1234567890
73.150.2.210 US:United States
grant at (no spam) deltree:~$ cat $(which ccfind)
#!/bin/bash
#
# ccfind 2006-03-05, last edit 2008-08-15
#
# returns '<query> cc:country name' for IP address input queries,
# using the ip2cn-server daemon.
#
# Copyright (C) 2006-2008 Grant Coady <http://bugsplatter.id.au> GPLv2
#
# 2008-08-13
# convert to ip2cn-server operation, no more access locking!
#
# check got query
[ -z "$1" ] && echo "
ccfind -- lookup country code and name for IP address
usage $0 aa.bb.cc.dd
" && exit
# get server listen port
port=$(gawk '/^inetport/ {print $2}' /etc/ip2cn-server.conf)
# make query, may be dotquad or numeric (decimal) IP address
echo "$ at (no spam) " | gawk -v port=$port '
BEGIN { service = "/inet/tcp/0/localhost/" port }
$1 == "0" { $1 = "0." }
{ print |& service; service |& getline; print }' 2>/dev/null
# end
When using awk's pattern action constructs, it doesn't much look
like C. Also, that one liner above retrieving port number from
a .conf file is example of awk winning hands down over sed + cut
for clarity of purpose.
Grant.
Just about *anything* wins over sed IMO.
I wasn't thinking of AWK 1 liners used in shell scripts, more like
actual programs coded in AWK instead of another language.
Jerry |
|
|
| Back to top |
|
|
|
| Eef Hartman... |
Posted: Sun Oct 18, 2009 5:55 am |
|
|
|
Guest
|
Grant <g_r_a_n_t_ at (no spam) bugsplatter.id.au> wrote:
Quote: On Fri, 16 Oct 2009 20:10:31 +0000 (UTC), Jerry Peters <jerry at (no spam) example.invalid> wrote:
Mike Jones <Not at (no spam) arizona.bay> wrote:
One of the advantages of using bash is that if you also use it as your
shell, you can easily try out commands at the prompt. This makes
testing unfamiliar constructs nice and easy.
Yes, but is that not true for any shell? Not as if one would try to
run a bash script under zsh? 'spose you could, seems weird to me :)
Gawk is fairly easy to learn if you already know C.
Bash is actually Algol-based (if / fi, case / esac, etc.).
C-shell was based on C (as the name already suggests).
--
*******************************************************************
** Eef Hartman, Delft University of Technology, dept. SSC/ICT **
** e-mail: E.J.M.Hartman at (no spam) tudelft.nl - phone: +31-15-278 82525 **
******************************************************************* |
|
|
| Back to top |
|
|
|
| Loki Harfagr... |
Posted: Sun Oct 18, 2009 6:46 am |
|
|
|
Guest
|
Sun, 18 Oct 2009 22:26:07 +1100, Grant did cat :
Quote: On Sun, 18 Oct 2009 11:14:31 GMT, Mike Jones <Not at (no spam) Arizona.Bay> wrote:
...
Next up, how to fsck a brain. %|
Start with three fingers Vodka, repeat until . . .
Beware, you can't do that on a journalized brain! |
|
|
| Back to top |
|
|
|
| Mike Jones... |
Posted: Sun Oct 18, 2009 3:33 pm |
|
|
|
Guest
|
Responding to Loki Harfagr:
Quote: Sun, 18 Oct 2009 22:26:07 +1100, Grant did cat :
On Sun, 18 Oct 2009 11:14:31 GMT, Mike Jones <Not at (no spam) Arizona.Bay> wrote:
...
Next up, how to fsck a brain. %|
Start with three fingers Vodka, repeat until . . .
Beware, you can't do that on a journalized brain!
And waking up with a fat head isn't an option.
--
*===( http://www.400monkeys.com/God/
*===( http://principiadiscordia.com/
*===( http://www.slackware.com/ |
|
|
| Back to top |
|
|
|
|
|
All times are GMT - 5 Hours
The time now is Tue Dec 15, 2009 12:38 am
|
|