[HN Gopher] A first person shooter in 571 lines of GNU Awk (2016)
       ___________________________________________________________________
        
       A first person shooter in 571 lines of GNU Awk (2016)
        
       Author : nequo
       Score  : 227 points
       Date   : 2023-01-19 16:55 UTC (6 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | oweiler wrote:
       | I am shocked how readable the code is. Was expecting some Perl-
       | like spaghetti.
        
         | userbinator wrote:
         | You could say that the code isn't really awkward to read.
        
           | amalgamated_inc wrote:
           | That's what she sed
        
         | ufo wrote:
         | I was hoping for some clever abuse of AWK's patterns & regexes
         | but clean code will also do :)
        
       | dekhn wrote:
       | In my UNIX learning history I skipped straight from sed to perl
       | and didn't use awk. By the time I had switched to python, awk
       | sounded awfully "old" to me.
       | 
       | I went back recently and read more on it and now I understand: it
       | was an excellent interpreted programming language that gave
       | semiskilled programmers some things C didn't, like associative
       | arrays, all nicely packaged within the UNIX frame of mind. In an
       | alternative universe, perhaps awk, instead of perl and then
       | python, would become the scripting language of choice.
        
         | [deleted]
        
       | srgpqt wrote:
       | Huh. Did not know Awk could be so similar to Javascript. I
       | certainly haven't seen it written in this way before, as usually
       | I only see it used for simple one-liners.
        
         | czx4f4bd wrote:
         | Awk is a fun, surprisingly powerful language. Even plain mawk
         | can do a lot, but gawk has debugger support, profiling,
         | namespaces, and even network support. (I wouldn't necessarily
         | go out of my way to use most of those features, but it's
         | possible!)
         | 
         | It's honestly worth giving the mawk and gawk manual a skim just
         | to see what all they can do. I want to read through _The AWK
         | Programming Language_ as well.
         | 
         | https://invisible-island.net/mawk/manpage/mawk.html
         | 
         | https://www.gnu.org/software/gawk/manual/gawk.html
        
         | benhoyt wrote:
         | Yeah, they're both languages which are quite unlike C in
         | operation, but both (by design) use C-like syntax to be more
         | familiar to existing developers. I think AWK has survived
         | incredibly well for a language that's 46 years old.
        
         | pmarreck wrote:
         | Awk is super interesting if you peel away a little. One nice
         | thing about it is that the amount of code it takes to do
         | something seems to scale quite linearly with the complexity of
         | the thing you need to do. Which is exactly why you often see it
         | in one-liners, but it's so much more. Recommend a deeper look
         | at it.
        
         | tannhaeuser wrote:
         | JavaScript syntax clearly is derived from awk's: the function
         | keyword, regexp literals, for (x in a), optional semicolons,
         | (associative) arrays, ...
         | 
         | Brendan Eich said as much: "JS's function keyword did come from
         | AWK" [1].
         | 
         | [1]: https://brendaneich.com/2010/07/a-brief-history-of-
         | javascrip...
        
         | jhbadger wrote:
         | There is so much about Awk that just seems more modern than
         | Perl, which largely replaced Awk in common usage in the mid
         | 1990s. Maybe the similarity to Javascript (which as others have
         | mentioned isn't coincidental) will encourage younger people to
         | take a look at it.
        
       | carapace wrote:
       | This was linked from "The State of the Awk (2020)" on the front
       | page earlier today: https://news.ycombinator.com/item?id=34438560
       | 
       | See also "AWK As A Major Systems Programming Language --
       | Revisited" also linked from that article:
       | http://www.skeeve.com/awk-sys-prog.html
        
       | j0hnyl wrote:
       | I came across this not too long ago. I recently picked up awk and
       | went looking for unique / unlikely programs written in the
       | language. This is completely mind blowing.
        
       | jandrese wrote:
       | I don't know if it was the RNG messing with me or something else,
       | but almost all of the monsters ended up congregating in the
       | elevator room when I played. I was basically just standing in the
       | approach hallway blasting them away one after another.
        
       | harveywi wrote:
       | They missed an opportunity to call this "Levenshtein 3D"
        
         | pmarreck wrote:
         | I, at least, appreciated this joke =)
        
         | amalgamated_inc wrote:
         | Literally dead
        
       | revskill wrote:
       | Curious to know if there's language that differentiate between
       | procedure (function with side-effect) and pure function at the
       | syntax level.
        
         | adrian_b wrote:
         | Among the gcc extensions to C and C++ there are 2 attributes
         | for functions without side effects:
         | __attribute__ ((pure))         __attribute__ ((const))
         | 
         | The 'pure' attribute imposes similar but looser restrictions on
         | a function's definition than the 'const' attribute: 'pure'
         | allows the function to read any non-volatile memory, even if it
         | changes in between successive invocations of the function.
        
         | retzkek wrote:
         | Fortran has subroutines and functions. Functions can take
         | multiple arguments and return a single value (however arguments
         | can also be modified). Subroutines can take multiple arguments,
         | which can be inputs, outputs, or both (arguments can be
         | declared inputs or outputs, but it's not required) and don't
         | return a value. And then there's common blocks for sharing
         | variables between subroutines...
        
         | kqr wrote:
         | Ada does this -- sort of. In the base language procedures can't
         | return anything, and functions must return something. However,
         | either of the two can execute side effects.
         | 
         | The SPARK subset of Ada enforces purity of functions at compile
         | time.
         | 
         | SPARK also allows partial purity, i.e. you can declare that a
         | procedure has side effects, but only in the sense that it uses
         | the wall clock as an input, or only in the sense that it writes
         | to a global variable. You can specify in some detail exactly
         | which side effects are allowed to happen in a procedure.
        
         | efdee wrote:
         | BASIC has SUB (for procedures) vs FUNCTION (for functions).
        
         | doodpants wrote:
         | I used Borland Turbo Pascal back in the '80s and '90s, and as I
         | recall it had separate keywords and syntax for defining
         | procedures vs. functions.
        
           | tgv wrote:
           | That was about returning a result or not. The void type made
           | that redundant (in Algol-68).
        
         | etra0 wrote:
         | Nim does this, it has 'proc' and 'func'. They define a `func`
         | as a procedure with no side effects using the macro
         | `{.noSideEffect.}` [1].
         | 
         | [1] https://nim-lang.org/docs/manual.html#procedures-func
        
       | glomgril wrote:
       | Hell of a side project. As deranged as it is awesome.
        
         | mikenew wrote:
         | Looking at the code it's not nearly as deranged as I would have
         | expected. It's actually pretty easy to follow.
        
       | helf wrote:
       | This is disgusting and I love it
        
       | haolez wrote:
       | This dev must be one of the few in the world that doesn't need
       | Google or man pages when awk is needed :)
        
         | klyrs wrote:
         | The weird thing about awk is that it can be written to look
         | like an ordinary c-inspired scripting language. But it also
         | supports the terse one-liners that we see so often; and the
         | general perception is that it's a language for wizards. The
         | ordinary scripting language is hiding in plain sight.
        
       | jandrese wrote:
       | What a delightfully insane project. AWK is under-appreciated
       | IMHO. Read the short manual and you'll discover a world of
       | functionality in a highly orthogonal interface. Pattern
       | Match->Manipulate. An incredibly useful workflow for many tasks.
        
         | avgcorrection wrote:
         | An elegant tool for forgetting inbetween all my organic needs
         | for it.
        
         | no_wizard wrote:
         | I wish there was like a "libawk" or something like it for
         | programmatic usage. Its really a neat piece of work that is
         | limited on being only a shell program.
         | 
         | At least, as far as I am aware, there is no programmatic
         | interface
        
           | pphysch wrote:
           | What would be a use case for this?
        
             | PhilipRoman wrote:
             | This is a somewhat different idea but I'd like to be able
             | to feed structured data (in memory objects) to an (user
             | defined) awk-like script without the need to
             | serialize/parse everything. This could be used for packet
             | filtering, conditional breakpoints, file searching, syscall
             | filtering and intercepting, etc. Basically wherever you
             | need a user defined filter more powerful than regex.
             | 
             | The embedder can decide what variables and functions to
             | provide for each invocation of the script. You could get
             | something like Wireshark filters out of the box:
             | ip && port==1234 {print size, time}
             | 
             | Graphviz includes a tool "gvpr" which essentially
             | implements this idea for processing graphs but of course,
             | they end up reimplementing a large part of awk.
        
               | chaboud wrote:
               | At this point I'be caved and just coerce through json via
               | python and jam things through jq for most of my data
               | inspection and sleuthing.
        
             | no_wizard wrote:
             | Text processing & extraction
        
               | pphysch wrote:
               | Like a middle ground between regex and embedded Lua?
        
           | yumaikas wrote:
           | Where would you use this? Most languages have good enough
           | string processing to imitate a lot of what AWK does
        
           | wrp wrote:
           | Gawk added facilities for writing extensions, but I don't see
           | how to use it as a library. Funny I never thought of it,
           | considering how much I like awk, but using awk instead of Lua
           | as an embedded extension language sounds appealing.
        
           | benhoyt wrote:
           | I don't know of a "libawk" C library, but my GoAWK
           | interpreter can also be used as a library (Go) library. See
           | reference docs:
           | https://pkg.go.dev/github.com/benhoyt/goawk/interp
           | 
           | A project that's using it that way is Benthos, a "stream
           | processor" written in Go. Awk is one of the "processors", the
           | components that filter and transform data:
           | https://www.benthos.dev/docs/components/processors/awk
        
       | [deleted]
        
       | dang wrote:
       | Related:
       | 
       |  _Show HN: 3D shooter in your terminal using raycasting in Awk_ -
       | https://news.ycombinator.com/item?id=10896901 - Jan 2016 (55
       | comments)
        
       | causi wrote:
       | If you're interested in feats of low-size games, I offer you
       | kkrieger, a 3D FPS that fits in 96KB.
       | 
       | https://www.youtube.com/watch?v=8fZBUsn5RYg
        
         | beezlebroxxxxxx wrote:
         | This is wild. One wonders what would happen if the (perhaps
         | misguided) ideals that shaped that project returned to being in
         | vogue.
        
           | sitkack wrote:
           | Previous discussions for a post about how they achieved that
           | feat.
           | 
           | https://fgiesen.wordpress.com/2012/04/08/metaprogramming-
           | for...
           | 
           | Nov 12, 2020 https://news.ycombinator.com/item?id=25043199
           | 
           | Aug 8, 2019 https://news.ycombinator.com/item?id=20635640
           | 
           | May 13, 2014 https://news.ycombinator.com/item?id=7739599
        
           | badsectoracula wrote:
           | Procedural generation for 3D content is something quite
           | common nowadays - see Substance Designer as an example.
           | 
           | AFAIK the people behind kkrieger tried to push their tool for
           | commercial use at some point but it didn't seem to catch on -
           | but that was years ago.
        
           | lmm wrote:
           | Huge but somewhat dull games. No Man's Sky is probably the
           | big name that went that way recently. Or, in its own way,
           | Dwarf Fortress.
        
         | jesprenj wrote:
         | AFAIK this was achieved by heavily using DirectX API and
         | features it contains. When running, it uses around 300 MiB of
         | RAM.
        
           | andai wrote:
           | The textures and models are procedurally generated at load
           | time!
        
         | McNutty wrote:
         | In the linked video, one of the kkrieger devs (kb) comments and
         | addresses some FAQs
        
         | 404mm wrote:
         | Nice. My little CLI utility that filters and lists my servers
         | in EC2 is 11MB (GO).
        
       ___________________________________________________________________
       (page generated 2023-01-19 23:00 UTC)