this post was submitted on 24 Feb 2024
13 points (76.0% liked)

Programming

17270 readers
39 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
 

This is a script called m5.awk that I randomly found after reading a paper about it on the ACM website. The paper's worth reading too but the script is just a piece of work. Commented to the brim, clean, and most importantly, useful as hell. it could be a replacement for m4. It allows you to embed AWK in text files, and besides that, it allows you to use several preprocessng features that it offers via macros. Give it a try.

top 11 comments
sorted by: hot top controversial new old
[–] [email protected] 13 points 1 year ago (2 children)

This is a strong example for the distinction between abundant comments and good documentation. Comments should describe why and how, not what. Comments on every single line stating what the line is doing is rarely a good sign. Despite all the comments, it's not super clear what it actually does from a user perspective and why someone would want to use it. I assume it's meant to be a templating system for text documents.

[–] [email protected] -3 points 1 year ago

I forgot to mention, tools like Bison and Autoconf use m4. Andrew Appel calls languages that need preprocessing 'weak'. The specs for D also call C 'weak' for needing to be preprocessed. Preprocessing is almost an abandoned practice, at least in the world of programming, because Scheme-like 'hygenic macros' have taken their place. Some languages like Rust and Zig are attempting to reinvent the wheel by re-inventing macros, but Scheme had it right in the 70s. Truly, C and Pascal's preprocessor were out the door in the 70s, let alone, now.

Here's another preprocessor that is 'neat: GPP.

I have made my own preprocessor, it's very nasty and has a lot of bugs because I was an idiot when I made it: https://github.com/Chubek/Ekipp

I have half a mind to remake Ekipp. I don't know what purpose would it serve. But it's just neat, I think preprocessors are neat, as useless as they are.

[–] [email protected] -4 points 1 year ago

It does not really need to explain what it 'is' because

1- a paper has been released on ACM explaining it, you can download it for free from here: https://dl.acm.org/doi/pdf/10.1145/353474.353484

2- It's name is m5, most people in the UNIX world know what m4 is. If you have Linux, bring up info m4.

Imagine this, when you use C, there is a preprocessor that does all the #include and #defines, m4 is like that and m5 is like that too. Preprocessing used to be big, but now it's not. If you wanna see an example of preprocessing, look at this preprocessor I made for C: https://gist.github.com/Chubek/b2846855e5bb71a67c7e3effc6beefd6

[–] [email protected] 8 points 1 year ago* (last edited 1 year ago) (1 children)

I am too dumb for this. Can somebody give an example of how this could be used in a real world scenario?

[–] [email protected] 8 points 1 year ago

If only this post title had received descriptive text too