I'm not 100% convinced by your basic premise, that the lack of an
extension mechanism is the main / a big reason why Awk isn't used
for the kinds of system programming tasks that Perl, Python, etc.,
are. It's absolutely a factor--without such a mechanism, there's
just no way to do a lot of important computations. But how does
that trade off against just having built-in mechanisms for the core
system programming facilities (as Perl does) or a handful of core
libraries like sys, os, regex, etc., for Python?
I'm also not convinced that Awk is the right language for writing
things that need extensions. It was originally designed for
1-liners, and a lot of its constructs don't scale up to bigger
programs. The notation for function locals is appalling (all my
fault too, which makes it worse). There's little chance to recover
from random spelling mistakes and typos; the use of mere adjacency
for concatenation looks ever more like a bad idea.
Awk is fine for its original purpose, but I find myself writing
Python for anything that's going to be bigger than say 10-20 lines
unless the lines are basically just longer pattern-action
sequences. (That notation is a win, of course, which you point
out.)
The du example is awfully big, though it does show off some of the
language features. Could you get the same mileage with something
quite a bit shorter?
In short, it's too early to really tell. This is the beginning of
an experiment. I hope it will be a fun journey for me, the other
gawk maintainers, and the larger community of awk users.
AWK As A Major Systems Programming Language
In retrospect, it seems clear (at least to us!) that there are two
major reasons that all of the previously mentioned languages have
enjoyed significant popularity. The first is their extensibility. The
second is namespace management.
I have worked for several years in Python. For string manipulation
and processing records, you still have to write all the manual stuff:
open the file, read lines in a loop, split them, etc. Awk does all
this stuff for me.
[snip]I have worked for several years in Python. For string manipulation
and processing records, you still have to write all the manual stuff:
open the file, read lines in a loop, split them, etc. Awk does all
this stuff for me.
On the flip side, you can peep it like this: Python's got a solid
set of statement types you can use for everything, making the code
hella readable. Meanwhile, awk's got its bag of tricks for special
cases like file and string processing. Just compare [1] with [2].
[1]
He described what awk did well, as well as what it didn't, and presented
a list of things that awk would need to acquire in order to take the
position of a reasonable alternative to C for systems programming tasks
on Unix systems.
Stefan Ram <ram@zedat.fu-berlin.de> wrote:
On the flip side, you can peep it like this: Python's got a solid set[snip]
of statement types you can use for everything, making the code hella
readable. Meanwhile, awk's got its bag of tricks for special cases
like file and string processing. Just compare [1] with [2].
[1]
Weird, as someone who doesn't use much of Python or AWK, I look at
your examples as clearly demonstrating that the AWK version is much
easier to read. I wonder if the Python version is more complicated
than it needs to be actually.
Yes, you could do a direct translation from the Awk and end up with
something that looked quite similar, apart from the differences in
syntax.
Trying to make that Python script more user-friendly for folks
who dig awk, then rolling out a sleeker version . . .
ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
Trying to make that Python script more user-friendly for folks
who dig awk, then rolling out a sleeker version . . .
The setup with a class and a bunch of named functions had some perks,
though: The class and function names are like a cheat sheet, spilling
the beans on what the coder was up to. They keep things chill by
breaking up the work, each one zeroing in on just one part of the gig.
Plus, they give you a solid jumping-off point for unit tests.
Richard Kettlewell <invalid@invalid.invalid> wrote or quoted:
Yes, you could do a direct translation from the Awk and end up with
something that looked quite similar, apart from the differences in
syntax.
Trying to make that Python script more user-friendly for folks
who dig awk, then rolling out a sleeker version . . .
#!/usr/bin/env python3
import sys
import csv
# Initialize variables
total_price = 0
min_year = 0
max_year = 0
author_count = {}
year_count = {}
# Print the header of the report
print("Book Analysis Report")
print("====================")
# Read CSV data from standard input
reader = csv.reader(sys.stdin)
next(reader) # Skip the header row
# Process each row in the CSV
for row in reader:
title, author, year, price = row
year = int(year)
price = float(price)
# Accumulate total price
total_price += price
# Determine min and max year
if min_year == 0 or year < min_year:
min_year = year
if year > max_year:
max_year = year
# Count books per author
if author in author_count:
author_count[author] += 1
else:
author_count[author] = 1
# Count books per year
if year in year_count:
year_count[year] += 1
else:
year_count[year] = 1
# Calculate total number of books
total_books = sum(author_count.values())
# Print the report
print("\nTotal number of books:", total_books)
print("Average book price: $%.2f" % (total_price / total_books))
print("Year range:", min_year, "to", max_year)
print("\nBooks per author:")
for author, count in author_count.items():
print(author + ":", count)
print("\nBooks per year:")
for year, count in year_count.items():
print(str(year) + ":", count)
No need to make it such a big production, though . . .
import csv, sys
from collections import Counter
with open(sys.argv[1]) as f:
data = list(csv.reader(f))[1:]
prices = [float(row[3]) for row in data]
years = [int(row[2]) for row in data]
authors = [row[1] for row in data]
print("Book Analysis Report\n====================")
print(f"\nTotal number of books: {len(data)}")
print(f"Average book price: ${sum(prices) / len(prices):.2f}")
print(f"Year range: {min(years)} to {max(years)}")
print("\nBooks per author:")
for author, count in Counter(authors).items():
print(f"{author}: {count}")
print("\nBooks per year:")
for year, count in Counter(years).items():
print(f"{year}: {count}")
ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
Trying to make that Python script more user-friendly for folks
who dig awk, then rolling out a sleeker version . . .
The setup with a class and a bunch of named functions had some perks,
though: The class and function names are like a cheat sheet, spilling
the beans on what the coder was up to. They keep things chill by
breaking up the work, each one zeroing in on just one part of the gig.
Plus, they give you a solid jumping-off point for unit tests.
|The Zen of Python, by Tim Peters
|[...]
|Flat is better than nested.
[...]
Stefan Ram:
|The Zen of Python, by Tim Peters |[...]
|Flat is better than nested. [...]
Then why does Python lack the ultimate code flattener, the `goto'
operator, and mandates structural indentation?
On Sun, 18 Aug 2024 00:28:21 -0000 (UTC), Ben Collver wrote:
He described what awk did well, as well as what it didn't, and presented
a list of things that awk would need to acquire in order to take the
position of a reasonable alternative to C for systems programming tasks
on Unix systems.
It was soon obsoleted by Perl, which did everything Awk did, just as concisely, and more besides.
Funny---I gave up on Perl as soon as I discovered the existence of AWK.
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Sun, 18 Aug 2024 00:28:21 -0000 (UTC), Ben Collver wrote:
He described what awk did well, as well as what it didn't, and
presented a list of things that awk would need to acquire in order to
take the position of a reasonable alternative to C for systems
programming tasks on Unix systems.
It was soon obsoleted by Perl, which did everything Awk did, just as
concisely, and more besides.
Funny---I gave up on Perl as soon as I discovered the existence of AWK.
On Tue, 27 Aug 2024 19:43:28 -0300, Johanne Fairchild wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Sun, 18 Aug 2024 00:28:21 -0000 (UTC), Ben Collver wrote:
He described what awk did well, as well as what it didn't, and
presented a list of things that awk would need to acquire in order to
take the position of a reasonable alternative to C for systems
programming tasks on Unix systems.
It was soon obsoleted by Perl, which did everything Awk did, just as
concisely, and more besides.
Funny---I gave up on Perl as soon as I discovered the existence of AWK.
Have you given up motor-cars in favour of horse-drawn transport as well?
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Sun, 18 Aug 2024 00:28:21 -0000 (UTC), Ben Collver wrote:
He described what awk did well, as well as what it didn't, and presented >>> a list of things that awk would need to acquire in order to take the
position of a reasonable alternative to C for systems programming tasks
on Unix systems.
It was soon obsoleted by Perl, which did everything Awk did, just as
concisely, and more besides.
Funny---I gave up on Perl as soon as I discovered the existence of AWK.
Sometimes less is more. It's aesthetics for sure, but for
me personally, I do not like massive languages that try to
do, and be, everything. For fun I thought about to have a
look at Lua, or possibly, go.
On Tue, 27 Aug 2024, Johanne Fairchild wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Sun, 18 Aug 2024 00:28:21 -0000 (UTC), Ben Collver wrote:
He described what awk did well, as well as what it didn't, and presented >>>> a list of things that awk would need to acquire in order to take the
position of a reasonable alternative to C for systems programming tasks >>>> on Unix systems.
It was soon obsoleted by Perl, which did everything Awk did, just as
concisely, and more besides.
Funny---I gave up on Perl as soon as I discovered the existence of AWK.
Sometimes less is more. It's aesthetics for sure, but for me
personally, I do not like massive languages that try to do, and be, everything. For fun I thought about to have a look at Lua, or
possibly, go.
D <nospam@example.net> writes:
On Tue, 27 Aug 2024, Johanne Fairchild wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Sun, 18 Aug 2024 00:28:21 -0000 (UTC), Ben Collver wrote:
He described what awk did well, as well as what it didn't, and presented >>>>> a list of things that awk would need to acquire in order to take the >>>>> position of a reasonable alternative to C for systems programming tasks >>>>> on Unix systems.
It was soon obsoleted by Perl, which did everything Awk did, just as
concisely, and more besides.
Funny---I gave up on Perl as soon as I discovered the existence of AWK.
Actually it was after I read ``The AWK Programming Language''.
Sometimes less is more. It's aesthetics for sure, but for me
personally, I do not like massive languages that try to do, and be,
everything. For fun I thought about to have a look at Lua, or
possibly, go.
Lua is a nice language, but it's really small.
Funny---I gave up on Perl as soon as I discovered the existence of AWK.
Actually it was after I read ``The AWK Programming Language''.
Sometimes less is more. It's aesthetics for sure, but for me
personally, I do not like massive languages that try to do, and be,
everything. For fun I thought about to have a look at Lua, or
possibly, go.
Lua is a nice language, but it's really small.
Ah! So maybe Lua would be my next hobby language to learn. =)
D <nospam@example.net> writes:
[...]
Actually it was after I read ``The AWK Programming Language''.Funny---I gave up on Perl as soon as I discovered the existence of AWK. >>>
Sometimes less is more. It's aesthetics for sure, but for me
personally, I do not like massive languages that try to do, and be,
everything. For fun I thought about to have a look at Lua, or
possibly, go.
Lua is a nice language, but it's really small.
Ah! So maybe Lua would be my next hobby language to learn. =)
I don't know why people enjoy such small things so much. Sure, it feels
good to master something, but it's also good to have tools that can do a
lot for us. I used to be very minimalist, but following my heart
instead of my brain I found Common Lisp to be the nicest of them all.
But, sure, if I'm going to embed a language in my executable, Lua is a candidate, though I'd probably go for a small Lisp.
On Sat, 31 Aug 2024, Johanne Fairchild wrote:
D <nospam@example.net> writes:
[...]
Actually it was after I read ``The AWK Programming Language''.Funny---I gave up on Perl as soon as I discovered the existence of AWK. >>>>
Sometimes less is more. It's aesthetics for sure, but for me
personally, I do not like massive languages that try to do, and be,
everything. For fun I thought about to have a look at Lua, or
possibly, go.
Lua is a nice language, but it's really small.
Ah! So maybe Lua would be my next hobby language to learn. =)
I don't know why people enjoy such small things so much. Sure, it feels
good to master something, but it's also good to have tools that can do a
lot for us. I used to be very minimalist, but following my heart
instead of my brain I found Common Lisp to be the nicest of them all.
But, sure, if I'm going to embed a language in my executable, Lua is a
candidate, though I'd probably go for a small Lisp.
In my case, it is because I am not working as a programmer, so I have
not requirements to be productive or to be able to generate any income
of programming.
That means, I can just have a go at what I find interesting and
beautiful. It also means that if I get bored, I can just stop, and
have a look at any other languange that catches my interest. =)
I had no idea [Lisp] existed and I felt it was
really strange that inteligent people would care so much about such an
old thing.
In my case, it is because I am not working as a programmer, so I have
not requirements to be productive or to be able to generate any income
of programming.
I am not programming for profit any longer. Thank God. I program for
beauty now. This change has been the hardest thing I had to do and it's
been so worth it.
On Sun, 1 Sep 2024, Johanne Fairchild wrote:
In my case, it is because I am not working as a programmer, so I have
not requirements to be productive or to be able to generate any income
of programming.
I am not programming for profit any longer. Thank God. I program for
beauty now. This change has been the hardest thing I had to do and it's
been so worth it.
Why? How was it to work as a programmer and what was it that you
didn't like about it?
When I graduated from university, I wanted to become a programmer, but
at that time, only 10+ years of experience was wanted on the job
market, so life decided that I should work in infrastructure/system administration instead.
When I graduated from university, I wanted to become a programmer, but
at that time, only 10+ years of experience was wanted on the job
market, so life decided that I should work in infrastructure/system
administration instead.
I always thought of system administration as a programming job. In
fact, a fun one. Initially I wanted to be a UNIX system administrator.
But my professional life began in a web world when most jobs I could get
were all web related. Deep web projects always involve UNIX
programming, but I was never really hired for deep projects. As a
result, I kept doing web programming to pay bills. So I had to study
and invent projects in order to study the other sides of computer
science so I would not spend my life with technology and culture I did
not even appreciate. That actually paid off. For the first time in my
life, I can say I really like my job.
On Mon, 2 Sep 2024, Johanne Fairchild wrote:
When I graduated from university, I wanted to become a programmer, but
at that time, only 10+ years of experience was wanted on the job
market, so life decided that I should work in infrastructure/system
administration instead.
I always thought of system administration as a programming job. In
fact, a fun one. Initially I wanted to be a UNIX system administrator.
Yes, having worked as one, I can see that. For me, the pleasure was
always in automation, and the quick feedback loops. I would work on a
piece of the infra-stack, automate as much as possible, and you can do
that in small cycles of days and weeks, instead of the endless bug
hunting the developers at one of my jobs did, in some kind of million+
line CAD software. I always got the feeling talking with them, that
their job would never end, and you would only see small,
micro-incremental improvements stretching over years.
Mean while, I'd happily automate my systems, deployments, reports,
statistics etc. so yes, some kind of programming always was there during
my time as a linux/unix system administrator.
You offer a shell account to a ``tweenager'' and they decline---thanks,
but no, thanks. ``I have my own system.'' They see no fun in sharing
in a UNIX system.
Yes, having worked as one, I can see that. For me, the pleasure was
always in automation, and the quick feedback loops. I would work on a
piece of the infra-stack, automate as much as possible, and you can do
that in small cycles of days and weeks, instead of the endless bug
hunting the developers at one of my jobs did, in some kind of million+
line CAD software. I always got the feeling talking with them, that
their job would never end, and you would only see small,
micro-incremental improvements stretching over years.
Mean while, I'd happily automate my systems, deployments, reports,
statistics etc. so yes, some kind of programming always was there during
my time as a linux/unix system administrator.
I recognize all of the above. But I think there's an even stronger
point for system administration back then. When I got introduced to
UNIX systems, it was a time where there were UNIX users and people would still share the system. So UNIX administrators did programming that
everyone around the system noticed. There were mailing lists, NNTP
servers and IRC servers so that people living the same area could talk
to on a daily basis. Getting online and seeing there were people online
too was a joy.
The web evolved and computers became cheap, so everyone got their own
and that seems to have isolated everyone. Instead of talking to your neighbor, you'd then interact with a lot of people across the world.
System administrators got buried. We only notice their presence now
when things go completely wrong. Today, the new generation of
programmers have not even heard of W. Richard Stevens. I have no idea
how they understand the systems they use.
You offer a shell account to a ``tweenager'' and they decline---thanks,
but no, thanks. ``I have my own system.'' They see no fun in sharing
in a UNIX system.
You offer a shell account to a ``tweenager'' and they decline---thanks,
but no, thanks. ``I have my own system.'' They see no fun in sharing
in a UNIX system.
On Fri, 30 Aug 2024, Johanne Fairchild wrote:
D <nospam@example.net> writes:
On Tue, 27 Aug 2024, Johanne Fairchild wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Sun, 18 Aug 2024 00:28:21 -0000 (UTC), Ben Collver wrote:
He described what awk did well, as well as what it didn't, and presented >>>>>> a list of things that awk would need to acquire in order to take the >>>>>> position of a reasonable alternative to C for systems programming tasks >>>>>> on Unix systems.
It was soon obsoleted by Perl, which did everything Awk did, just as >>>>> concisely, and more besides.
Funny---I gave up on Perl as soon as I discovered the existence of AWK.
Actually it was after I read ``The AWK Programming Language''.
Sometimes less is more. It's aesthetics for sure, but for me
personally, I do not like massive languages that try to do, and be,
everything. For fun I thought about to have a look at Lua, or
possibly, go.
Lua is a nice language, but it's really small.
Ah! So maybe Lua would be my next hobby language to learn. =)
On the other hand, aseprite lua has actually worked consistently unlike krita's python
Johanne Fairchild <jfairchild@tudado.org> wrote or quoted:
You offer a shell account to a ``tweenager'' and they decline---thanks,
but no, thanks. ``I have my own system.'' They see no fun in sharing
in a UNIX system.
On some shell accounts here, "social commands" (like "finger",
"who", etc.) have been disabled. It might have something to
do with the "Datenschutz" ("privacy") laws.
The admins also do not seem to use "motd" anymore, instead
system information seems to be published on some web page.
I had one free shell account about 20 years on a system where
you could log in and play nethack. I think the highscore list
was shared.
D <nospam@example.net> wrote at 09:56 this Saturday (GMT):
On Fri, 30 Aug 2024, Johanne Fairchild wrote:
D <nospam@example.net> writes:
On Tue, 27 Aug 2024, Johanne Fairchild wrote:Actually it was after I read ``The AWK Programming Language''.
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
On Sun, 18 Aug 2024 00:28:21 -0000 (UTC), Ben Collver wrote:
He described what awk did well, as well as what it didn't, and presented
a list of things that awk would need to acquire in order to take the >>>>>>> position of a reasonable alternative to C for systems programming tasks >>>>>>> on Unix systems.
It was soon obsoleted by Perl, which did everything Awk did, just as >>>>>> concisely, and more besides.
Funny---I gave up on Perl as soon as I discovered the existence of AWK. >>>
Sometimes less is more. It's aesthetics for sure, but for me
personally, I do not like massive languages that try to do, and be,
everything. For fun I thought about to have a look at Lua, or
possibly, go.
Lua is a nice language, but it's really small.
Ah! So maybe Lua would be my next hobby language to learn. =)
I learned some lua to make aseprite scripts, it is pretty neat but it is
a bit frustrating to learn (like how specifically instance functions
MUST be called with :, while static functions are called with .)
On the other hand, aseprite lua has actually worked consistently unlike krita's python
On Mon, 2 Sep 2024 23:50:04 -0000 (UTC), candycanearter07 wrote:
On the other hand, aseprite lua has actually worked consistently unlike
krita's python
Isn’t it neat how all the major open-source content-creation apps offer a Python API?
Easily the most extensive of them all has to be Blender: more extensive
even than the scripting API of any proprietary app.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 388 |
Nodes: | 16 (2 / 14) |
Uptime: | 05:21:04 |
Calls: | 8,220 |
Calls today: | 18 |
Files: | 13,122 |
Messages: | 5,872,261 |
Posted today: | 1 |